|
@@ -25,7 +25,6 @@ const ATCmdFunc Atcmdfunc[] = {
|
|
|
{AT_CSQ, "AT+CSQ\r\n", at_callbackFunc},
|
|
|
{AT_NETOPEN, "AT+NETOPEN\r\n", at_callbackFunc},
|
|
|
{AT_CGIP, "AT+CDNSGIP=", at_callbackFunc},
|
|
|
- //{AT_CONNECT, "AT+CIPOPEN=0,\"TCP\",\"120.26.68.165\",14319\r\n", at_callbackFunc},
|
|
|
{AT_CONNECT, "AT+CIPOPEN=", at_callbackFunc},
|
|
|
{AT_CONNECTCHK, "AT+CIPOPEN?\r\n", at_callbackFunc},
|
|
|
{AT_SEND, "AT+CIPSEND=", at_callbackFunc},
|
|
@@ -35,22 +34,28 @@ const ATCmdFunc Atcmdfunc[] = {
|
|
|
|
|
|
static process_Tcp gProcess_Tcp_Task = PROCESS_TCP_INIT;
|
|
|
#define PROC_TCP_STATE_SWITCH(a) (gProcess_Tcp_Task = a)
|
|
|
-void InitFunc(void);
|
|
|
+sint8 InitFunc(void);
|
|
|
sint8 TcpConnectFunc(sint8 *ConnectId);
|
|
|
-sint8 TcpDataSendFunc(sint8 ConnectId);
|
|
|
+sint8 TcpDataSendFunc(sint8 ConnectId,uint8 DataSendIdxIn);
|
|
|
sint8 TcpRegisterChkFunc(void);
|
|
|
-void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen);
|
|
|
-void GetUtc8Time(UTC8TimeType *UTC8TimeTcp);
|
|
|
+void TcpDataEncode(uint8 DataIdx,uint32 *PtrSendAddr, uint16 *SendLen);
|
|
|
+void GetUtc8Time(UTC8TimeType *UTC8TimeTcpPtr);
|
|
|
+void TimeUpdate(UTC8TimeType *UTC8TimeTcpPtr);
|
|
|
+static void TcpDataSendFeqHandFunc(uint8 *DataIdx);
|
|
|
static void AtcmdTransmit(sint8 CmdIdx, uint8 *SetValuePtr, uint16 SetValueLen, sint8 *retFunc, uint16 timeout);
|
|
|
static void TcpDataInfoRecvHandle(uint8 *DataRecv, uint16 DataRecvLen);
|
|
|
static void GetCSQValue(uint8 *out);
|
|
|
void Fota_Ftp(uint8 *dataPtrIn);
|
|
|
void tcpUdsFunc(uint8 *Ptr, uint8 *AnsPtr);
|
|
|
static void vTimer1000msCallback(TimerHandle_t pxTimer);
|
|
|
-bool SendTimerFlg = false;
|
|
|
-static uint32 TcpSendTimeCounter = 0;
|
|
|
+
|
|
|
+volatile TcpFeq_type TcpDataFeq={
|
|
|
+ {0x01,60*60*2,0},{0x86,60*60,0},{0x91,10,0},
|
|
|
+ {0x82,10,0},{0x90,60,0},{0x92,60,0},{0x8C,10,0}};//默认发送频率
|
|
|
+static UTC8TimeType UTC8TimeTcp;//全局真实时间存储
|
|
|
extern boolean waitForSleepFlag;
|
|
|
boolean Uart_4G_Task_Sleep_FLag = false;
|
|
|
+TimerHandle_t monitorTimer1000ms;
|
|
|
void Uart_4G_Task(void *pvParameters)
|
|
|
{
|
|
|
(void)pvParameters;
|
|
@@ -58,17 +63,6 @@ void Uart_4G_Task(void *pvParameters)
|
|
|
uint8 UartRecvPtr[512];
|
|
|
volatile uint16 tcpErrorCounter = 0;
|
|
|
uint16 pReadLen = 0;
|
|
|
- // 4G开机
|
|
|
- Dio_LevelType _4G_Status = 0; // 0-关机,1-开机
|
|
|
- // Dio_WriteChannel(DioConf_DioChannel_PTA6_GPIO_OUT_MCU_4G_POW_EN, STD_ON);
|
|
|
- // vTaskDelay(pdMS_TO_TICKS(500));
|
|
|
- // Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_ON);
|
|
|
- // vTaskDelay(pdMS_TO_TICKS(50));
|
|
|
- // AtcmdDelayRecvFunc(UART_LPUART1,(char *)("SMS DONE"),30000);
|
|
|
- // Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_OFF);
|
|
|
- // _4G_Status = Dio_ReadChannel(DioConf_DioChannel_PTB1_GPIO_IN_MCU_4G_STATUS);
|
|
|
- // InitFunc(); // 4G模块初始化,注:AT同步不通过,没有进行次数判定及跳转
|
|
|
- TimerHandle_t monitorTimer1000ms;
|
|
|
monitorTimer1000ms = xTimerCreate("monitor1000ms", 1000, pdTRUE, (void *)0, vTimer1000msCallback);
|
|
|
xTimerStart(monitorTimer1000ms, 0);
|
|
|
for (;;)
|
|
@@ -82,23 +76,22 @@ void Uart_4G_Task(void *pvParameters)
|
|
|
{
|
|
|
case PROCESS_TCP_INIT:
|
|
|
{
|
|
|
- Dio_WriteChannel(DioConf_DioChannel_PTA6_GPIO_OUT_MCU_4G_POW_EN, STD_ON);
|
|
|
- vTaskDelay(pdMS_TO_TICKS(500));
|
|
|
-
|
|
|
- Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_ON);
|
|
|
- vTaskDelay(pdMS_TO_TICKS(50));
|
|
|
- Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_OFF);
|
|
|
-
|
|
|
- AtcmdDelayRecvFunc(UART_LPUART1, (char *)("SMS DONE"), 30000);
|
|
|
- _4G_Status = Dio_ReadChannel(DioConf_DioChannel_PTB1_GPIO_IN_MCU_4G_STATUS);
|
|
|
- InitFunc();
|
|
|
- TcpSendTimeCounter = 0;
|
|
|
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
|
|
|
+ sint8 InitFlg = -1;
|
|
|
+ InitFlg = InitFunc();
|
|
|
+ if(InitFlg==0)
|
|
|
+ {
|
|
|
+ PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ TcpSysReboot = 1;
|
|
|
+ PROC_TCP_STATE_SWITCH(PROCESS_TCP_ERROR);
|
|
|
+ }
|
|
|
break;
|
|
|
}
|
|
|
case PROCESS_TCP_IDLE: // 空闲状态
|
|
|
{
|
|
|
- UART_Receive_Data(UART_LPUART1, UartRecvPtr, &pReadLen, 100); // 100ms检测
|
|
|
+ Tcp_Receive_Data (UartRecvPtr, &pReadLen, 100); // 100ms检测
|
|
|
if (SocketId < 0)
|
|
|
{
|
|
|
PROC_TCP_STATE_SWITCH(PROCESS_TCP_REGCHK);
|
|
@@ -108,12 +101,11 @@ void Uart_4G_Task(void *pvParameters)
|
|
|
PROC_TCP_STATE_SWITCH(PROCESS_TCP_RECV);
|
|
|
RecvTimerDelay = TimerCounter;
|
|
|
}
|
|
|
- else if (AppConfigInfo.eolFlg == 1 && TcpWorkState == 0 && SendTimerFlg == true)
|
|
|
+ else if (AppConfigInfo.eolFlg == 1 && TcpWorkState == 0)
|
|
|
{
|
|
|
- SendTimerFlg = false;
|
|
|
PROC_TCP_STATE_SWITCH(PROCESS_TCP_SEND);
|
|
|
}
|
|
|
- if ((TimerCounter - RecvTimerDelay) >= 30000 && TcpWorkState == 1) // 10s内没有命令下发,进行正常发送任务
|
|
|
+ if ((TimerCounter - RecvTimerDelay) >= 30000 && TcpWorkState == 1) // 30s内没有命令下发,进行正常发送任务
|
|
|
{
|
|
|
TcpWorkState = 0;
|
|
|
}
|
|
@@ -141,7 +133,6 @@ void Uart_4G_Task(void *pvParameters)
|
|
|
if (ConnectRet > 0)
|
|
|
{
|
|
|
PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
|
|
|
- TcpSendTimeCounter = 0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -153,16 +144,22 @@ void Uart_4G_Task(void *pvParameters)
|
|
|
case PROCESS_TCP_SEND: // 网络数据发送
|
|
|
{
|
|
|
sint8 SendRet = -1;
|
|
|
- SendRet = TcpDataSendFunc(SocketId);
|
|
|
- if (SendRet == 0)
|
|
|
- {
|
|
|
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
|
|
|
- tcpErrorCounter = 0;
|
|
|
- }
|
|
|
- else
|
|
|
+ uint8 DataSendIdx = 0;
|
|
|
+ //发送判定
|
|
|
+ TcpDataSendFeqHandFunc(&DataSendIdx);
|
|
|
+ if(DataSendIdx!=0)//有数据处理
|
|
|
{
|
|
|
- SocketId = -1;
|
|
|
- PROC_TCP_STATE_SWITCH(PROCESS_TCP_ERROR);
|
|
|
+ SendRet = TcpDataSendFunc(SocketId,DataSendIdx);//发送函数
|
|
|
+ if (SendRet == 0)
|
|
|
+ {
|
|
|
+ PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
|
|
|
+ tcpErrorCounter = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ SocketId = -1;
|
|
|
+ PROC_TCP_STATE_SWITCH(PROCESS_TCP_ERROR);
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
@@ -181,7 +178,6 @@ void Uart_4G_Task(void *pvParameters)
|
|
|
}
|
|
|
case PROCESS_TCP_SLEEP: // 网络休眠状态
|
|
|
{
|
|
|
-
|
|
|
while (waitForSleepFlag == true)
|
|
|
{
|
|
|
Uart_4G_Task_Sleep_FLag = true;
|
|
@@ -194,7 +190,7 @@ void Uart_4G_Task(void *pvParameters)
|
|
|
{
|
|
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
|
|
tcpErrorCounter++;
|
|
|
- if (tcpErrorCounter > 60 && TcpSysReboot == 1) // 无法驻网或者联网
|
|
|
+ if (tcpErrorCounter > 60 || TcpSysReboot == 1) // 无法驻网或者联网
|
|
|
{
|
|
|
Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_ON);
|
|
|
vTaskDelay(pdMS_TO_TICKS(2500));
|
|
@@ -207,7 +203,6 @@ void Uart_4G_Task(void *pvParameters)
|
|
|
{
|
|
|
PROC_TCP_STATE_SWITCH(PROCESS_TCP_IDLE);
|
|
|
}
|
|
|
-
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -217,23 +212,53 @@ static void vTimer1000msCallback(TimerHandle_t pxTimer)
|
|
|
{
|
|
|
uint32 ulTimerID;
|
|
|
ulTimerID = (uint32)pvTimerGetTimerID(pxTimer);
|
|
|
+ sint16 *TcpDataFeqPtr =NULL;
|
|
|
+ TcpDataFeqPtr = (sint16 *)&TcpDataFeq;
|
|
|
if (ulTimerID == 0)
|
|
|
{
|
|
|
- SendTimerFlg = true;
|
|
|
- TcpSendTimeCounter++;
|
|
|
+ if(SocketId>=0)
|
|
|
+ {
|
|
|
+ for(uint8 i=2;i<sizeof(TcpDataFeq)/sizeof(sint16);i=i+3)
|
|
|
+ {
|
|
|
+ *(TcpDataFeqPtr+i) = (*(TcpDataFeqPtr+i)-1)<0 ? 0 : (*(TcpDataFeqPtr+i)-1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ TimeUpdate(&UTC8TimeTcp);
|
|
|
}
|
|
|
}
|
|
|
-sint8 TcpDataSendFunc(sint8 ConnectId)
|
|
|
+static void TcpDataSendFeqHandFunc(uint8* DataIdx)
|
|
|
+{
|
|
|
+ sint16 *TcpDataFeqPtr =NULL;
|
|
|
+ TcpDataFeqPtr = (sint16 *)&TcpDataFeq;
|
|
|
+ for(uint8 i=2;i<sizeof(TcpDataFeq)/sizeof(sint16);i=i+3)
|
|
|
+ {
|
|
|
+ if(*(TcpDataFeqPtr+i)==0)
|
|
|
+ {
|
|
|
+ *DataIdx = *(TcpDataFeqPtr+i-2);
|
|
|
+ *(TcpDataFeqPtr+i) = *(TcpDataFeqPtr+i-1);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ *DataIdx = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return;
|
|
|
+}
|
|
|
+sint8 TcpDataSendFunc(sint8 ConnectId,uint8 DataSendIdxIn)
|
|
|
{
|
|
|
sint8 outValue = -1;
|
|
|
uint32 pSendDataAddr = 0;
|
|
|
uint16 DataSendLen = 0;
|
|
|
- TcpDataEncode(&pSendDataAddr, &DataSendLen); // 数据组包,malloc申请在里面,pSendData指向申请的地址
|
|
|
- if (DataSendLen == 0)
|
|
|
+ TcpDataEncode(DataSendIdxIn,&pSendDataAddr, &DataSendLen); // 数据组包,malloc申请在里面,pSendData指向申请的地址
|
|
|
+ if(DataSendLen==0)//长度为0 不调用发送数据函数
|
|
|
+ {
|
|
|
+ outValue = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
{
|
|
|
- return 0; // 暂时无数据可以发
|
|
|
+ outValue = tcpipConnectionSend(ConnectId, (uint8 *)pSendDataAddr, DataSendLen); // 发送函数
|
|
|
}
|
|
|
- outValue = tcpipConnectionSend(ConnectId, (uint8 *)pSendDataAddr, DataSendLen); // 发送函数
|
|
|
if (pSendDataAddr != 0)
|
|
|
{
|
|
|
vPortFree((uint8 *)(pSendDataAddr));
|
|
@@ -257,8 +282,8 @@ sint8 tcpipConnectionSend(uint8 TcpConnectId, uint8 *SendDataPtr, uint16 SendDat
|
|
|
ret = UART_Query_Data(UART_LPUART1, UART_LPUART1, (uint8 *)AtCmdSend, AtCmdSendTotalLen, UartRecvPtr, &ReadLen, 1000);
|
|
|
if (((ret == 0) && (ReadLen > 0) && ((uint8 *)strstr((char *)UartRecvPtr, (char *)(">")))) || 1) // 此IF条件默认通过
|
|
|
{
|
|
|
- UART_Send_Data(UART_LPUART1, (uint8 *)SendDataPtr, SendDataLen, 1000);
|
|
|
- sint8 ret = AtcmdDelayRecvFunc(UART_LPUART1, (char *)("+CIPSEND"), 2000);
|
|
|
+ UART_Send_Data(UART_LPUART1, (uint8 *)SendDataPtr, SendDataLen, 100);
|
|
|
+ sint8 ret = AtcmdDelayRecvFunc(UART_LPUART1, (char *)("+CIPSEND"), 3000);
|
|
|
if (ret == 0)
|
|
|
{
|
|
|
outValue = 0;
|
|
@@ -453,7 +478,7 @@ sint8 TcpRegisterChkFunc(void)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-void InitFunc(void)
|
|
|
+sint8 InitFunc(void)
|
|
|
{
|
|
|
// 4G模块初始化
|
|
|
uint8 _4G_InitStep = 0;
|
|
@@ -464,6 +489,14 @@ void InitFunc(void)
|
|
|
uint8 UartRecvPtr[50];
|
|
|
uint16 ATerrorCnt = 0;
|
|
|
uint8 *retptr = NULL;
|
|
|
+ Dio_LevelType _4G_Status = 0; // 0-关机,1-开机
|
|
|
+ Dio_WriteChannel(DioConf_DioChannel_PTA6_GPIO_OUT_MCU_4G_POW_EN, STD_ON);
|
|
|
+ vTaskDelay(pdMS_TO_TICKS(500));
|
|
|
+ Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_ON);
|
|
|
+ vTaskDelay(pdMS_TO_TICKS(50));
|
|
|
+ Dio_WriteChannel(DioConf_DioChannel_PTA7_GPIO_OUT_MCU_4G_PWRKEY, STD_OFF);
|
|
|
+ AtcmdDelayRecvFunc(UART_LPUART1, (char *)("SMS DONE"), 10000);
|
|
|
+ _4G_Status = Dio_ReadChannel(DioConf_DioChannel_PTB1_GPIO_IN_MCU_4G_STATUS);
|
|
|
while (1)
|
|
|
{
|
|
|
switch (_4G_InitStep)
|
|
@@ -482,7 +515,7 @@ void InitFunc(void)
|
|
|
ATerrorCnt++;
|
|
|
if (ATerrorCnt > 60 * 5)
|
|
|
{
|
|
|
- SystemSoftwareReset();
|
|
|
+ return -1;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
@@ -586,8 +619,7 @@ void InitFunc(void)
|
|
|
}
|
|
|
default:
|
|
|
{
|
|
|
- return;
|
|
|
- break;
|
|
|
+ return 0;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -751,48 +783,14 @@ sint8 at_callbackFunc(char *PSendStr, char *pReadStr, uint8 CmdIdx, uint16 pRead
|
|
|
}
|
|
|
return OutValue;
|
|
|
}
|
|
|
-void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
|
|
|
+void TcpDataEncode(uint8 DataIdx,uint32 *PtrSendAddr, uint16 *SendLen)
|
|
|
{
|
|
|
- static UTC8TimeType UTC8TimeTcp;
|
|
|
uint8 *SendBuffer = NULL;
|
|
|
- uint8 DataIdx = 0;
|
|
|
- if ((TcpSendTimeCounter) % (60 * 60) == 1)
|
|
|
- {
|
|
|
- DataIdx = VerMsg; // 版本信息发送
|
|
|
- }
|
|
|
- else if (TcpSendTimeCounter % 10 == 2)
|
|
|
- {
|
|
|
- DataIdx = TruckBattMsg; // 电池信息发送
|
|
|
- }
|
|
|
- else if ((TcpSendTimeCounter) % 60 == 3)
|
|
|
- {
|
|
|
- DataIdx = TruckVehiMsg; // 车辆信息发送
|
|
|
- }
|
|
|
- else if ((TcpSendTimeCounter) % 60 == 4)
|
|
|
- {
|
|
|
- DataIdx = TruckAcclMsg; // 累计信息发送
|
|
|
- }
|
|
|
- else if ((TcpSendTimeCounter) % 10 == 5)
|
|
|
- {
|
|
|
- DataIdx = GpsMsg; // 定位信息发送
|
|
|
- }
|
|
|
- else if ((TcpSendTimeCounter) % (60 * 60 * 2) == 6)
|
|
|
- {
|
|
|
- DataIdx = 0x01; // 时间校准
|
|
|
- }
|
|
|
- else if ((TcpSendTimeCounter) % 10 == 7)
|
|
|
+ memcpy(TcpbattSN, AppConfigInfo.deviceSn, 17);
|
|
|
+ if(UTC8TimeTcp.month==0)
|
|
|
{
|
|
|
- DataIdx = DebugMsg; // 调试信息发送,含FFT结果
|
|
|
+ DataIdx = 0x01;
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- *SendLen = 0;
|
|
|
- DataIdx = 0; // 不发送,返回
|
|
|
- return;
|
|
|
- }
|
|
|
- memcpy(TcpbattSN, AppConfigInfo.deviceSn, 17);
|
|
|
- GetUtc8Time(&UTC8TimeTcp); // 时间获取
|
|
|
- vTaskDelay(pdMS_TO_TICKS(100));
|
|
|
switch (DataIdx)
|
|
|
{
|
|
|
case 0x01: // 时间校准
|
|
@@ -802,7 +800,9 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
|
|
|
uint8 ReadLen = 0;
|
|
|
uint8 UartRecvPtr[20];
|
|
|
UART_Query_Data(UART_LPUART1, UART_LPUART1, (uint8 *)ATCmdSend, ATCmdSendLen, UartRecvPtr, &ReadLen, pdMS_TO_TICKS(500));
|
|
|
+ GetUtc8Time(&UTC8TimeTcp); // 时间获取
|
|
|
*SendLen = 0; // 不发送,长度为0
|
|
|
+ xTimerReset(monitorTimer1000ms,0);
|
|
|
return;
|
|
|
}
|
|
|
case 0x82:
|
|
@@ -934,6 +934,8 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
|
|
|
case DebugMsg:
|
|
|
{
|
|
|
char rbuf[512]={0};
|
|
|
+ char tmp[13] = {0};
|
|
|
+ memcpy(tmp,BMS_SN,12);
|
|
|
DebugMsgtoTcpType DebugMsgInfo;
|
|
|
UINT16 DataLen = 0;
|
|
|
UINT16 BufferLen = 0;
|
|
@@ -942,7 +944,7 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
|
|
|
{%.2f,%.2f,%.2f,%.2f,%.2f;\
|
|
|
%.2f,%.2f,%.2f,%.2f,%.2f,}\
|
|
|
{%.2f,%.2f,%.2f,%.2f,%.2f;\
|
|
|
- %.2f,%.2f,%.2f,%.2f,%.2f,}",
|
|
|
+ %.2f,%.2f,%.2f,%.2f,%.2f,},%s",
|
|
|
returnFreq[0][0], returnFreq[0][1], returnFreq[0][2], returnFreq[0][3], returnFreq[0][4],
|
|
|
returnP[0][0], returnP[0][1], returnP[0][2], returnP[0][3], returnP[0][4],
|
|
|
|
|
@@ -950,13 +952,9 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
|
|
|
returnP[1][0], returnP[1][1], returnP[1][2], returnP[1][3], returnP[1][4],
|
|
|
|
|
|
returnFreq[2][0], returnFreq[2][1], returnFreq[2][2], returnFreq[2][3], returnFreq[2][4],
|
|
|
- returnP[2][0], returnP[2][1], returnP[2][2], returnP[2][3], returnP[2][4]);
|
|
|
+ returnP[2][0], returnP[2][1], returnP[2][2], returnP[2][3], returnP[2][4],tmp);
|
|
|
|
|
|
BufferLen = strlen((const char *)rbuf);
|
|
|
-#ifdef SEGGER_RTT_PRINTF
|
|
|
- SEGGER_RTT_printf("[%d]BufferLen=%d\r\n",__LINE__,BufferLen);
|
|
|
- SEGGER_RTT_printf("[%d]rbuf=%s\r\n",__LINE__,rbuf);
|
|
|
-#endif
|
|
|
*SendLen = BufferLen + sizeof(DebugMsgInfo);
|
|
|
SendBuffer = pvPortMalloc(*SendLen);
|
|
|
memcpy(SendBuffer + sizeof(DebugMsgInfo) - 1, rbuf, BufferLen);
|
|
@@ -1056,6 +1054,11 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
|
|
|
}
|
|
|
case 0x91:
|
|
|
{
|
|
|
+ if(BMS_CellRecvCounter<128)
|
|
|
+ {
|
|
|
+ *SendLen = 0; // 不发送,长度为0
|
|
|
+ return;
|
|
|
+ }
|
|
|
GetCSQValue(&CSQValue);
|
|
|
*SendLen = 0x54 + min(BMS_CellTotal, BMS_CELL_MAX_NUM) * 2 + min(BMS_TempTotal, BMS_TEMP_MAX_NUM);
|
|
|
SendBuffer = pvPortMalloc(*SendLen);
|
|
@@ -1198,29 +1201,97 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-void GetUtc8Time(UTC8TimeType *UTC8TimeTcp)
|
|
|
+void TimeUpdate(UTC8TimeType *UTC8TimeTcpPtr)
|
|
|
+{
|
|
|
+ int year = 0, month = 0, day = 0, hour = 0,minute = 0,second = 0;
|
|
|
+ int lastday = 0;
|
|
|
+
|
|
|
+ year = UTC8TimeTcpPtr->year + 2000;
|
|
|
+ month = UTC8TimeTcpPtr->month;
|
|
|
+ day = UTC8TimeTcpPtr->day;
|
|
|
+ hour = UTC8TimeTcpPtr->hour;
|
|
|
+ minute = UTC8TimeTcpPtr->minute;
|
|
|
+ second = UTC8TimeTcpPtr->second;
|
|
|
+ second+=1;
|
|
|
+ if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
|
|
|
+ {
|
|
|
+ lastday = 31;
|
|
|
+ }
|
|
|
+ else if (month == 4 || month == 6 || month == 9 || month == 11)
|
|
|
+ {
|
|
|
+ lastday = 30;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))
|
|
|
+ lastday = 29;
|
|
|
+ else
|
|
|
+ lastday = 28;
|
|
|
+ }
|
|
|
+ if(second >=60)
|
|
|
+ {
|
|
|
+ second -=60;
|
|
|
+ minute +=1;
|
|
|
+ if(minute >=60)
|
|
|
+ {
|
|
|
+ minute -=60;
|
|
|
+ hour +=1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (hour >= 24)
|
|
|
+ {
|
|
|
+ hour -= 24;
|
|
|
+ day += 1;
|
|
|
+ if (day > lastday)
|
|
|
+ {
|
|
|
+ day -= lastday;
|
|
|
+ month += 1;
|
|
|
+ if (month > 12)
|
|
|
+ {
|
|
|
+ month -= 12;
|
|
|
+ year += 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ UTC8TimeTcpPtr->year = year - 2000;
|
|
|
+ UTC8TimeTcpPtr->month = month;
|
|
|
+ UTC8TimeTcpPtr->day = day;
|
|
|
+ UTC8TimeTcpPtr->hour = hour;
|
|
|
+ UTC8TimeTcpPtr->minute = minute;
|
|
|
+ UTC8TimeTcpPtr->second = second;
|
|
|
+}
|
|
|
+void GetUtc8Time(UTC8TimeType *UTC8TimeTcpPtr)
|
|
|
{
|
|
|
char *AtCmdAsk = (char *)("AT+CCLK?\r\n");
|
|
|
uint8 AtCmdLen = mstrlen(AtCmdAsk);
|
|
|
uint16 ReadLen = 0;
|
|
|
uint8 *retptr = NULL;
|
|
|
uint8 UartRecvPtr[128];
|
|
|
- UART_Query_Data(UART_LPUART1, UART_LPUART1, (uint8 *)AtCmdAsk, AtCmdLen, UartRecvPtr, &ReadLen, pdMS_TO_TICKS(100));
|
|
|
- if (ReadLen > 0)
|
|
|
+ uint8 ErrCnt = 0;
|
|
|
+ while(ErrCnt<3)
|
|
|
{
|
|
|
- if ((uint8 *)strstr((char *)UartRecvPtr, (char *)("OK")))
|
|
|
+ UART_Query_Data(UART_LPUART1, UART_LPUART1, (uint8 *)AtCmdAsk, AtCmdLen, UartRecvPtr, &ReadLen, pdMS_TO_TICKS(100));
|
|
|
+ if (ReadLen ==39 )
|
|
|
{
|
|
|
- retptr = (uint8 *)strstr((char *)UartRecvPtr, (char *)("+CCLK:"));
|
|
|
- if (retptr)
|
|
|
+ if ((uint8 *)strstr((char *)UartRecvPtr, (char *)("OK")))
|
|
|
{
|
|
|
- UTC8TimeTcp->year = CharToHex(*(retptr + 8)) * 10 + CharToHex(*(retptr + 9));
|
|
|
- UTC8TimeTcp->month = CharToHex(*(retptr + 11)) * 10 + CharToHex(*(retptr + 12));
|
|
|
- UTC8TimeTcp->day = CharToHex(*(retptr + 14)) * 10 + CharToHex(*(retptr + 15));
|
|
|
- UTC8TimeTcp->hour = CharToHex(*(retptr + 17)) * 10 + CharToHex(*(retptr + 18));
|
|
|
- UTC8TimeTcp->minute = CharToHex(*(retptr + 20)) * 10 + CharToHex(*(retptr + 21));
|
|
|
- UTC8TimeTcp->second = CharToHex(*(retptr + 23)) * 10 + CharToHex(*(retptr + 24));
|
|
|
+ retptr = (uint8 *)strstr((char *)UartRecvPtr, (char *)("+CCLK:"));
|
|
|
+ if (retptr)
|
|
|
+ {
|
|
|
+ UTC8TimeTcpPtr->year = CharToHex(*(retptr + 8)) * 10 + CharToHex(*(retptr + 9));
|
|
|
+ UTC8TimeTcpPtr->month = CharToHex(*(retptr + 11)) * 10 + CharToHex(*(retptr + 12));
|
|
|
+ UTC8TimeTcpPtr->day = CharToHex(*(retptr + 14)) * 10 + CharToHex(*(retptr + 15));
|
|
|
+ UTC8TimeTcpPtr->hour = CharToHex(*(retptr + 17)) * 10 + CharToHex(*(retptr + 18));
|
|
|
+ UTC8TimeTcpPtr->minute = CharToHex(*(retptr + 20)) * 10 + CharToHex(*(retptr + 21));
|
|
|
+ UTC8TimeTcpPtr->second = CharToHex(*(retptr + 23)) * 10 + CharToHex(*(retptr + 24));
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ErrCnt++;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
static void GetCSQValue(uint8 *out)
|
|
@@ -1230,13 +1301,12 @@ static void GetCSQValue(uint8 *out)
|
|
|
uint16 ReadLen = 0;
|
|
|
uint8 *retptr = NULL;
|
|
|
uint8 UartRecvPtr[30];
|
|
|
+ static uint8 CSQValue = 0;
|
|
|
UART_Query_Data(UART_LPUART1, UART_LPUART1, (uint8 *)AtCmdAsk, AtCmdLen, UartRecvPtr, &ReadLen, pdMS_TO_TICKS(100));
|
|
|
- *out = 99;
|
|
|
if (ReadLen > 0)
|
|
|
{
|
|
|
if ((uint8 *)strstr((char *)UartRecvPtr, (char *)("OK")))
|
|
|
{
|
|
|
- *out = 0;
|
|
|
retptr = (uint8 *)strstr((char *)UartRecvPtr, (char *)("+CSQ:"));
|
|
|
char CsqStr[5];
|
|
|
for (uint8 i = 0; i < 5; i++)
|
|
@@ -1247,9 +1317,10 @@ static void GetCSQValue(uint8 *out)
|
|
|
}
|
|
|
memcpy((CsqStr + i), (retptr + i + 6), 1);
|
|
|
}
|
|
|
- *out = atoi(CsqStr);
|
|
|
+ CSQValue = atoi(CsqStr);
|
|
|
}
|
|
|
}
|
|
|
+ *out = CSQValue;
|
|
|
return;
|
|
|
}
|
|
|
static void TcpDataInfoRecvHandle(uint8 *DataRecv, uint16 DataRecvLen)
|