|
@@ -45,6 +45,7 @@ static void AtcmdTransmit(sint8 CmdIdx, uint8 *SetValuePtr, uint16 SetValueLen,
|
|
|
static void TcpDataInfoRecvHandle(uint8 *DataRecv, uint16 DataRecvLen);
|
|
|
static void GetCSQValue(uint8 *out);
|
|
|
void Fota_Ftp(void);
|
|
|
+void tcpUdsFunc(Ptr,TcpCmdAnswer);
|
|
|
void Uart_4G_Task(void *pvParameters)
|
|
|
{
|
|
|
(void)pvParameters;
|
|
@@ -55,7 +56,7 @@ void Uart_4G_Task(void *pvParameters)
|
|
|
_4G_Status = Dio_ReadChannel(DioConf_DioChannel_PTB1_GPIO_IN_MCU_4G_STATUS);
|
|
|
// LED测试
|
|
|
Dio_WriteChannel(DioConf_DioChannel_PTE0_GPIO_OUT_MCU_LED1, STD_OFF);
|
|
|
- vTaskDelay(pdMS_TO_TICKS(1000));
|
|
|
+ vTaskDelay(pdMS_TO_TICKS(5000));
|
|
|
uint16 pReadLen = 0;
|
|
|
InitFunc(); // 4G模块初始化,注:AT同步不通过,没有进行次数判定及跳转
|
|
|
uint32 SendTimerCounter = 0;
|
|
@@ -67,7 +68,7 @@ void Uart_4G_Task(void *pvParameters)
|
|
|
{
|
|
|
case PROCESS_TCP_IDLE: //空闲状态
|
|
|
{
|
|
|
- UART_Receive_Data(UART_LPUART1, &UartRecvPtr, &pReadLen, 10);//100ms检测
|
|
|
+ UART_Receive_Data(UART_LPUART1, &UartRecvPtr, &pReadLen, 100);//100ms检测
|
|
|
if (SocketId < 0)
|
|
|
{
|
|
|
PROC_TCP_STATE_SWITCH(PROCESS_TCP_REGCHK);
|
|
@@ -299,6 +300,12 @@ sint8 TcpConnectFunc(sint8 *ConnectId)
|
|
|
char AtCmdSend[40] = {0};
|
|
|
uint8 AtCmdSendTotalLen = 0;
|
|
|
*ConnectId = 0;
|
|
|
+ /*IP测试更改*/
|
|
|
+// char *ATCmdSend = (char *)("\"120.26.68.165\"");
|
|
|
+// memset(WebSiteIp,0x00,sizeof(WebSiteIp));
|
|
|
+// memcpy(WebSiteIp ,ATCmdSend,strlen(ATCmdSend));
|
|
|
+// WebSitePort = 14401;
|
|
|
+ /**/
|
|
|
sprintf(AtCmdSend, "%d,\"TCP\",%s,%d\r\n", *ConnectId, WebSiteIp, WebSitePort); //此处需要优化
|
|
|
AtCmdSendTotalLen = mstrlen(AtCmdSend);
|
|
|
AtcmdTransmit(AT_CONNECT, AtCmdSend, AtCmdSendTotalLen, &ATRet,10000);
|
|
@@ -718,11 +725,11 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
|
|
|
{
|
|
|
DataIdx = VerMsg; //版本信息发送
|
|
|
}
|
|
|
- else if (TcpSendTimeCounter % 60 == 0)
|
|
|
+ else if (TcpSendTimeCounter % 10 == 0)
|
|
|
{
|
|
|
DataIdx = BattMsg; //电池信息发送
|
|
|
}
|
|
|
- else if ((TcpSendTimeCounter+1) % 60 == 0)
|
|
|
+ else if ((TcpSendTimeCounter+1) % 10 == 0)
|
|
|
{
|
|
|
DataIdx = 0x83; //储能开关信息发送
|
|
|
}
|
|
@@ -730,7 +737,7 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
|
|
|
{
|
|
|
DataIdx = GpsMsg; //定位信息发送
|
|
|
}
|
|
|
- else if ((TcpSendTimeCounter+3) % 10 == 0)
|
|
|
+ else if ((TcpSendTimeCounter+3) % 240 == 0)
|
|
|
{
|
|
|
DataIdx = 0x93; //储能电量信息发送
|
|
|
}
|
|
@@ -1114,7 +1121,7 @@ static void TcpDataInfoRecvHandle(uint8 *DataRecv, uint16 DataRecvLen)
|
|
|
{
|
|
|
uint8 Tcp_Cmd;
|
|
|
uint8 *Ptr = NULL, *retptr = NULL;
|
|
|
- uint8 TcpCmdAnswer[31];
|
|
|
+ uint8 TcpCmdAnswer[50]={0};
|
|
|
uint16 TcpDataLen = 0;
|
|
|
uint16 NumCalTemp = 1;
|
|
|
retptr = (uint8 *)strstr((char *)DataRecv, (char *)("\r\n##"));
|
|
@@ -1139,6 +1146,10 @@ static void TcpDataInfoRecvHandle(uint8 *DataRecv, uint16 DataRecvLen)
|
|
|
{
|
|
|
TcpWorkState = 0x01;//需要暂停发送,进行命令应答的标志
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
switch (Tcp_Cmd)
|
|
|
{
|
|
|
case TCP_QUERY_SYM:
|
|
@@ -1195,6 +1206,8 @@ static void TcpDataInfoRecvHandle(uint8 *DataRecv, uint16 DataRecvLen)
|
|
|
TcpCmdAnswer[0] = TCP_START_SYM1;
|
|
|
TcpCmdAnswer[1] = TCP_START_SYM1;
|
|
|
TcpCmdAnswer[2] = TCP_UDSCMD_SYM;
|
|
|
+ tcpUdsFunc(Ptr,TcpCmdAnswer);
|
|
|
+// tcpipConnectionSend(SocketId, TcpCmdAnswer, 30);
|
|
|
break;
|
|
|
}
|
|
|
default:
|
|
@@ -1205,6 +1218,91 @@ static void TcpDataInfoRecvHandle(uint8 *DataRecv, uint16 DataRecvLen)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+void tcpUdsFunc(uint8 *Ptr,uint8 *AnsPtr)
|
|
|
+{
|
|
|
+ uint8 contrlType = 0;
|
|
|
+ uint16 udsDataLen = 0;
|
|
|
+ uint16 DIDBuffer = 0;
|
|
|
+ uint8 udsType_SID = 0;
|
|
|
+ uint8 DataBuffer[10];
|
|
|
+ uint8 *DataBufferPtr = NULL;
|
|
|
+ contrlType = *(Ptr + 30);
|
|
|
+ udsDataLen = *(Ptr + 31);
|
|
|
+ udsType_SID = *(Ptr + 32);
|
|
|
+ DIDBuffer = *(Ptr + 33)<<8|*(Ptr + 34);
|
|
|
+ memcpy(DataBuffer,Ptr + 35,udsDataLen);
|
|
|
+ switch(contrlType)
|
|
|
+ {
|
|
|
+ case 0x00:
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 0x01:
|
|
|
+ {
|
|
|
+ switch(udsType_SID)
|
|
|
+ {
|
|
|
+ case 0x2E:
|
|
|
+ {
|
|
|
+ switch(DIDBuffer)
|
|
|
+ {
|
|
|
+ case 0x01:
|
|
|
+ {
|
|
|
+ battSeparateEnable = 1;
|
|
|
+ if(DataBuffer[0]==0x01)
|
|
|
+ {
|
|
|
+ battSeparateCtlState = 1;
|
|
|
+ }
|
|
|
+ else if(DataBuffer[0]==0x00)
|
|
|
+ {
|
|
|
+ battSeparateCtlState = 0;
|
|
|
+ }
|
|
|
+ *(AnsPtr+3) = 0x0f;
|
|
|
+ memcpy((AnsPtr+4), (Ptr + 4), BATT_SN_LEN);
|
|
|
+ *(AnsPtr+21) = TCP_ENCPT_DISABLE;
|
|
|
+ *(AnsPtr+22) = 0x00;
|
|
|
+ *(AnsPtr+23) = 0x06;
|
|
|
+ memcpy((AnsPtr+24), (Ptr + 24), 6);
|
|
|
+ *(AnsPtr+30) = contrlType;
|
|
|
+ *(AnsPtr+31) = udsDataLen;
|
|
|
+ *(AnsPtr+32) = udsType_SID;
|
|
|
+ *(AnsPtr+33) = DIDBuffer>>8;
|
|
|
+ *(AnsPtr+34) = DIDBuffer;
|
|
|
+ *(AnsPtr+36) = DataBuffer[0];
|
|
|
+ *(AnsPtr+37) = bcc_chk(AnsPtr, 37);
|
|
|
+ return;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 0x22:
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ *(AnsPtr+3) = 0x0f;
|
|
|
+ memcpy((AnsPtr+4), (Ptr + 4), BATT_SN_LEN);
|
|
|
+ *(AnsPtr+21) = TCP_ENCPT_DISABLE;
|
|
|
+ *(AnsPtr+22) = 0x00;
|
|
|
+ *(AnsPtr+23) = 0x06;
|
|
|
+ memcpy((AnsPtr+24), (Ptr + 24), 6);
|
|
|
+ *(AnsPtr+30) = contrlType;
|
|
|
+ *(AnsPtr+31) = udsDataLen;
|
|
|
+ *(AnsPtr+32) = 0x7F;
|
|
|
+ *(AnsPtr+33) = DIDBuffer>>8;
|
|
|
+ *(AnsPtr+34) = DIDBuffer;
|
|
|
+ *(AnsPtr+36) = 0x31;
|
|
|
+ *(AnsPtr+37) = bcc_chk(AnsPtr, 37);
|
|
|
+}
|
|
|
sint8 tcpipConnectionSend(uint8 TcpConnectId, uint8 *SendDataPtr, uint16 SendDataLen)
|
|
|
{
|
|
|
sint8 outValue = -1;
|
|
@@ -1217,12 +1315,12 @@ sint8 tcpipConnectionSend(uint8 TcpConnectId, uint8 *SendDataPtr, uint16 SendDat
|
|
|
uint8 ret = 0;
|
|
|
sprintf(AtCmdSend, "AT+CIPSEND=%d,%d\r\n", TcpConnectId, SendDataLen);
|
|
|
AtCmdSendTotalLen = mstrlen(AtCmdSend);
|
|
|
- while(outValue!=0&&sendErrConuter<10)
|
|
|
+ while(outValue!=0&&sendErrConuter<3)
|
|
|
{
|
|
|
- ret = UART_Query_Data(UART_LPUART1, UART_LPUART1, (uint8 *)AtCmdSend, AtCmdSendTotalLen, &UartRecvPtr1, &ReadLen, 2000);
|
|
|
+ ret = UART_Query_Data(UART_LPUART1, UART_LPUART1, (uint8 *)AtCmdSend, AtCmdSendTotalLen, &UartRecvPtr1, &ReadLen, 5000);
|
|
|
if (ret==0&&ReadLen>0&&(uint8 *)strstr((char *)UartRecvPtr1, (char *)(">"))||0)//一个字节收不到的问题,IDE中断间隔过大不行
|
|
|
{
|
|
|
- UART_Query_Data(UART_LPUART1, UART_LPUART1, (uint8 *)SendDataPtr, SendDataLen, &UartRecvPtr, &ReadLen, 2000);
|
|
|
+ UART_Query_Data(UART_LPUART1, UART_LPUART1, (uint8 *)SendDataPtr, SendDataLen, &UartRecvPtr, &ReadLen, 5000);
|
|
|
if (ReadLen>0&&(uint8 *)strstr((char *)UartRecvPtr, (char *)("\r\nOK\r\n\r\n+CIPSEND")))
|
|
|
{
|
|
|
outValue = 0;
|