Browse Source

版本号:2.1.0.11,网络逻辑更改测试

CHENJIE-PC\QiXiang_CHENJIE 3 years ago
parent
commit
133e96f5eb
8 changed files with 95 additions and 55 deletions
  1. 2 2
      inc/Signal.h
  2. 2 1
      inc/app.h
  3. 24 2
      src/MainTask.c
  4. 2 1
      src/Signal.c
  5. 15 26
      src/TcpTask.c
  6. 48 20
      src/UartTask.c
  7. 1 2
      src/app.c
  8. 1 1
      src/hal_module_adapter.c

+ 2 - 2
inc/Signal.h

@@ -40,8 +40,8 @@ extern	UINT16	battPackVol;
 extern	UINT16	battI;
 extern	UINT16	nbHwVersion;
 
-
-
+extern UINT8 Lockstatus;
+extern UINT8 Error_count;
 
 //declear the UINT32 vars
 extern	UINT32	battWarningState;

+ 2 - 1
inc/app.h

@@ -52,7 +52,7 @@ extern "C" {
 #define	DRVSWVERSION		0x01050000     //驱动层版本号V1.4.0.0  驱动层1.5.0.0,增加了三轴
 //#define	APPSWVERSION		0x01020209     
 //#define	APPSWVERSION		0x02000103
-#define	APPSWVERSION		0x0201000A
+#define	APPSWVERSION		0x0201000B
 //--------------------------------------------------------------------------------
 
 #define APP_CONFIG_FILE_LATEST_VERSION 0
@@ -108,6 +108,7 @@ typedef struct AppDataType
     INT8  BattCurrentNegFlag;
     UINT32 CumulativeCapacity;
     UINT32 AccMileage;
+    UINT16 SysReStart;
 }AppDataBody;
 typedef struct _AppDataHeader
 {

+ 24 - 2
src/MainTask.c

@@ -185,7 +185,26 @@ static void MainTask(void* arg)
             case PROCESS_STATE_WORK:
             {
 
-                
+                if(Error_count>=5)
+                {
+                    AppDataInfo.appDataModify = true;
+                    AppDataInfo.SysReStart = AppDataInfo.SysReStart +1;
+                    if(AppDataInfo.SysReStart>=0xfffe)
+                    {
+                        AppDataInfo.SysReStart = 0;
+                    }
+                    if(AppNVMData.appDataModify)
+                    {
+                        appSaveNVMData();
+                    }
+                    if(AppDataInfo.appDataModify)
+                    {
+                        appSaveDataInfo();
+                    }
+                    appSetCFUN(0);
+                    osDelay(1000);
+                    EC_SystemReset();
+                }
                 osDelay(1000);
                 if(Work_timer_end)
                 {
@@ -281,7 +300,7 @@ static void MainTask(void* arg)
                     printf("which slpstate can go now :%d \n",slpstate);
                 #endif
                 #ifdef DEBUGLOG
-                    Debug_printf("slp-%d,AccM-%d  \n",slpstate,AppDataInfo.AccMileage);
+                    Debug_printf("slp-%d,%d,%d\n",slpstate,AppDataInfo.AccMileage,AppDataInfo.SysReStart);
                 #endif
                 slpManDeepSlpTimerStart(deepslpTimerID, AppNVMData.sleepTime*1000*60);
                 UINT8 sleeptime_count=0;
@@ -300,6 +319,8 @@ static void MainTask(void* arg)
                         #ifdef DEBUGLOG
                             Debug_printf("405\n");
                         #endif
+                        appSetCFUN(0);
+                        osDelay(1000);
                         EC_SystemReset();
                     }
                 }
@@ -797,6 +818,7 @@ static void setDefaultAppDataInfo(void)
     AppDataInfo.BattCurrentNegFlag = 1;
     AppDataInfo.CumulativeCapacity = 0;
     AppDataInfo.AccMileage = 0;
+    AppDataInfo.SysReStart = 0;
     return;
 }
 

+ 2 - 1
src/Signal.c

@@ -70,7 +70,8 @@ UINT16	battI = 0xFFFF;
 UINT16	nbHwVersion = 0xFFFF;
 
 
-
+UINT8 Lockstatus = 0;
+UINT8 Error_count=0;
 
 //declear the UINT32 vars
 UINT32	battWarningState = 0xFFFFFFFF;

+ 15 - 26
src/TcpTask.c

@@ -70,11 +70,9 @@ UINT8 bcc_chk(UINT8* data, UINT8 length);
 //线程任务区
 static void TcpTask(void* arg)
 {
-    INT32 connectionId = -1;
     appSetEDRXSettingSync(0,5,1800000);
     appSetPSMSettingSync(1,3*60*60,10);
     appSetCFUN(1);
-    UINT8 Error_count=0;
     psEventQueueHandle = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(eventCallbackMessage_t*));
     PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_IDLE);
     if (psEventQueueHandle == NULL)
@@ -89,6 +87,7 @@ static void TcpTask(void* arg)
     {
         Error_Mutex = osMutexNew(NULL);
     }
+    osDelay(5000);//等待驻网延时5s
     while (true)
     {
         osDelay(100);
@@ -115,7 +114,7 @@ static void TcpTask(void* arg)
             switch(queueItem->messageId)
             {
                 case QMSG_ID_NW_IP_READY:
-                    if(connectionId < 0)
+                    if(socContext.id < 0)
                     {
                         struct addrinfo hints;
                         struct addrinfo *servinfo = NULL;
@@ -133,15 +132,14 @@ static void TcpTask(void* arg)
                             for(int i=0;i<16;i++)
                                 printf("%c",*(Tcp_ip_des+i));
                         #endif
-                        connectionId = tcpipConnectionCreate(TCPIP_CONNECTION_PROTOCOL_TCP, PNULL, 0, Tcp_ip_des, QX_TCP_PORT, socketAppConnectionCallBack);
+                        socContext.id  = tcpipConnectionCreate(TCPIP_CONNECTION_PROTOCOL_TCP, PNULL, 0, Tcp_ip_des, QX_TCP_PORT, socketAppConnectionCallBack);
                         if (NULL != servinfo) {
                             freeaddrinfo(servinfo);
                         }
 
                     }
-                    if(connectionId >= 0)
+                    if(socContext.id  >= 0)
                     {
-                        socContext.id = connectionId;
                         socContext.status = APP_SOCKET_CONNECTION_CONNECTED;
                         #ifdef USING_PRINTF
                             printf("create connection %u success", socContext.id);
@@ -158,15 +156,12 @@ static void TcpTask(void* arg)
                     }
                     break;
                 case QMSG_ID_NW_IP_NOREACHABLE:
-                    if(Error_count>=10)
                     {
-                        Error_count = 0;
-                        #ifdef DEBUGLOG
-                            Debug_printf("404\n");
-                        #endif
+                        Error_count++;
                         appSetCFUN(0);
-                        osDelay(1000);
-                        EC_SystemReset();
+                        osDelay(5000);
+                        appSetCFUN(1);
+                        osDelay(5000);
                     }
                     break;
                 case QMSG_ID_SOCK_SENDPKG:
@@ -176,7 +171,6 @@ static void TcpTask(void* arg)
                     }
                     else
                     {
-                        Error_count++;
                         sendQueueMsg(QMSG_ID_NW_IP_READY, 0);
                         #ifdef USING_PRINTF
                             printf("connection %u or status invalid", socContext.id, socContext.status);
@@ -428,6 +422,7 @@ static void TcpDataInfoAssembleSend()
             else
             {
                 TcpSendLen = 0xFD & TcpSendLen;
+                sendQueueMsg(QMSG_ID_NW_IP_SUSPEND, 0);
             }
         }
     }
@@ -479,6 +474,7 @@ static void TcpDataInfoAssembleSend()
             else
             {
                 TcpSendLen = 0xFB & TcpSendLen;
+                sendQueueMsg(QMSG_ID_NW_IP_SUSPEND, 0);
             }
         }
         #ifdef USING_PRINTF1
@@ -564,6 +560,7 @@ static void TcpDataInfoAssembleSend()
             else
             {
                 TcpSendLen = 0xFE & TcpSendLen;
+                sendQueueMsg(QMSG_ID_NW_IP_SUSPEND, 0);
             }
         }
         else
@@ -581,12 +578,12 @@ static void TcpDataInfoAssembleSend()
         if(BufferLen>200)
         {
             Debug_Del_Logfile();
-            return;
+            #ifdef DEBUGLOG
+                Debug_printf("Sys:%d\n",AppDataInfo.SysReStart);
+            #endif
+            BufferLen = Debug_GetSize();
         }
         UINT8 rbuf[BufferLen];
-        #ifdef USING_PRINTF
-            printf("BufferLen:%d!\n",BufferLen);
-        #endif
         Debug_Read_Logfile(rbuf,BufferLen);
         SendBuffer = malloc(BufferLen+sizeof(DebugMsgInfo));
         memcpy(SendBuffer+sizeof(DebugMsgInfo)-1, rbuf,BufferLen);
@@ -732,14 +729,6 @@ static void TcpDataInfoRecvHandle()
                 }
                 default:
                 {
-                    TcpCmdAnswer[3] = 0x0f;
-                    memcpy(&TcpCmdAnswer[4],(Ptr+4),BATT_SN_LEN);
-                    TcpCmdAnswer[21] = TCP_ENCPT_DISABLE;
-                    TcpCmdAnswer[22] = 0x00;
-                    TcpCmdAnswer[23] = 0x06;
-                    memcpy(&TcpCmdAnswer[24],(Ptr+24),6);
-                    TcpCmdAnswer[30] = bcc_chk(TcpCmdAnswer,30);
-                    tcpipConnectionSend(socContext.id,TcpCmdAnswer,31,0,0,0);
                     break;
                 }
             }

+ 48 - 20
src/UartTask.c

@@ -44,7 +44,7 @@ BOOL UartBattInfoRecvFlag  = false;
 QueueHandle_t UartWriteCmdHandle = NULL;
 UINT8 BattChrgEndFlag;
 
-UINT8 Lockstatus;
+
 
 //
 
@@ -307,28 +307,40 @@ static BOOL uartBattInfoDecode(UINT8* dataPtr)
     
     Batt_current = (dataPtr[(0x02+BATT_CELL_VOL_NUM)*2]<<8)|(dataPtr[(0x02+BATT_CELL_VOL_NUM)*2+1]);
     //原始数据:充电为负,放电为正
-	if(battWorkState==0x02&&Batt_current>0x8000)
+	if(battWorkState == 0x02) //充电过程
 	{
-		AppDataInfo.BattCurrentNegFlag = 1;
+		if(Batt_current >0x8000)// 数据为负
+		{			
+			//求补码,结果为负
+			Batt_current = (UINT16)((UINT16)(~(Batt_current))+1);
+        	Batt_current = Batt_current/10;
+			AppDataInfo.BattCurrentNegFlag = -1;
+		}
+		else
+		{
+			//源码,结果为负
+			Batt_current = Batt_current/10;
+			AppDataInfo.BattCurrentNegFlag = -1;
+		}
 	}
-	if(battWorkState==0x02&&Batt_current<0x8000)
+	else //放电过程
 	{
-		AppDataInfo.BattCurrentNegFlag = -1;
+		if(Batt_current >0x8000)// 数据为负
+		{
+			//求补码,结果为正
+			Batt_current = (UINT16)((UINT16)(~(Batt_current))+1);
+        	Batt_current = Batt_current/10;
+			AppDataInfo.BattCurrentNegFlag = 1;
+		}
+		else
+		{
+			//源码,结果为正
+			Batt_current = Batt_current/10;
+			AppDataInfo.BattCurrentNegFlag = 1;
+		}
 	}
-    if (Batt_current>0x8000) //为负,充电数据
-    {
-        Batt_current = (UINT16)((UINT16)(~(Batt_current))+1);
-        Batt_current = Batt_current/10;
-        Batt_current = -Batt_current*AppDataInfo.BattCurrentNegFlag + 0x2710;//平台数据:充电为负
-        //Batt_current = Batt_current;
-    }
-    else  //为正,数据
-    {
-        Batt_current = Batt_current/10;
-        Batt_current = Batt_current*AppDataInfo.BattCurrentNegFlag + 0x2710;//平台数据:充电为负
-        //Batt_current = Batt_current;
-    }
-    battI = Batt_current;
+
+	battI = Batt_current*AppDataInfo.BattCurrentNegFlag + 0x2710;
     //bit0 ~ bit31 represent cell0 ~ cell31
     battBalanceoInfo  = dataPtr[(0x06+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1] | (dataPtr[(0x06+BATT_CELL_VOL_NUM+TEMP_NUM)*2] <<8) + (dataPtr[(0x07+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]<<16) | (dataPtr[(0x07+BATT_CELL_VOL_NUM+TEMP_NUM)*2] <<24);
 
@@ -436,7 +448,7 @@ UINT8 Uart_WriteCmd_func(Uart_Write_Data_Type UartWriteData)
     UINT8 Uart_Recv_Buffer[8];
     switch (UartWriteData.WriteCmd)
     {
-        case 0x01:
+        case 0x01://是否锁定
         {   
             RegAddress = 0x1B + BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM;
             Uart_Write_Msg.Bms_Address = BMS_ADDRESS_CODE;
@@ -452,6 +464,22 @@ UINT8 Uart_WriteCmd_func(Uart_Write_Data_Type UartWriteData)
             Uart_Write_Msg.CRC_H = CRC_chk_buffer>>8;
             break;
         }
+		case 0x02://是否加热
+		{
+			RegAddress = 0x1C + BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM;
+            Uart_Write_Msg.Bms_Address = BMS_ADDRESS_CODE;
+            Uart_Write_Msg.Bms_Funcode = UART_WRITE_CODE;
+            Uart_Write_Msg.Reg_Begin_H = RegAddress>>8;
+            Uart_Write_Msg.Reg_Begin_L = RegAddress;
+            Uart_Write_Msg.Reg_Num_H = 0x00;
+            Uart_Write_Msg.Reg_Num_L = 0x01;
+            Uart_Write_Msg.Data_Count = 0x02;//要写入的字节数
+            memcpy(Uart_Write_Msg.Data,UartWriteData.Data,2);
+            CRC_chk_buffer = crc_chk((UINT8 *)&Uart_Write_Msg,sizeof(Uart_Write_Msg)-2);
+            Uart_Write_Msg.CRC_L = CRC_chk_buffer;
+            Uart_Write_Msg.CRC_H = CRC_chk_buffer>>8;
+            break;
+		}
         default:
         {
             UartWriteData.WriteCmd = 0x00;

+ 1 - 2
src/app.c

@@ -34,12 +34,11 @@ void appInit(void *arg)
     	printf("%s[%d]\r\n",__FUNCTION__, __LINE__);
     #endif
     MainTaskInit(arg);
-    osDelay(1000);
     AdcTaskInit();
     UartTaskInit(arg);
-    TcpTaskInit(arg);
     GpsTaskInit();
 	CANTaskInit(arg);
+    TcpTaskInit(arg);
 }
 //主函数入口
 void main_entry(void) 

+ 1 - 1
src/hal_module_adapter.c

@@ -297,7 +297,7 @@ void Debug_printf(const UINT8 *format, ...)
 	memset(buf,0,128+1);
 	UTC8TimeType UTC8TimeStruct;
 	UTCToBeijing((UTC8TimeType *)&UTC8TimeStruct,year,month,day,hour,minute,sec);
-	sprintf((char *)buf,"%02d-%02d %02d:%02d:%02d ",UTC8TimeStruct.month,UTC8TimeStruct.day,UTC8TimeStruct.hour,UTC8TimeStruct.minute,UTC8TimeStruct.second);
+	sprintf((char *)buf,"%02d:%02d:%02d-",UTC8TimeStruct.hour,UTC8TimeStruct.minute,UTC8TimeStruct.second);
 	va_start(args, format);
 	vsnprintf(buf+strlen(buf), 128-strlen(buf), format, args);
 	va_end(args);