Sfoglia il codice sorgente

1.增加Bms升级数据传输
2.取消0x85控制状态上报,合并到开关状态里
3.增加Fota数据包总长度判定

CHENJIE-PC\QiXiang_CHENJIE 4 anni fa
parent
commit
f950007e95
4 ha cambiato i file con 60 aggiunte e 90 eliminazioni
  1. 1 1
      inc/Fota.h
  2. 1 22
      inc/TcpTask.h
  3. 35 5
      src/Fota.c
  4. 23 62
      src/TcpTask.c

+ 1 - 1
inc/Fota.h

@@ -22,4 +22,4 @@ typedef struct _Fota_Type
 
 }Fota_Type;
 extern volatile bool Fota_update_flag;
-void Fota_Func(UINT8 *DataPtr,INT32 connectId);
+void Fota_Func(UINT8 *DataPtr,INT32 connectId,UINT8 FotaType);

+ 1 - 22
inc/TcpTask.h

@@ -60,7 +60,7 @@ typedef struct BattInfoType
 	UINT8	battI[2];
 	UINT8	battLinkVol[2];
 	UINT8	battPackVol[2];
-	UINT8   mosState;
+	UINT8   switchState;
 	UINT8	battSOC;
 	UINT8	battSOH;
 	UINT8	batCellBalenceState[4];	//uint32 should change to uint8[]: each bit stand for 1 cell, up to 1024
@@ -139,27 +139,6 @@ typedef struct VersionMsgtoTcpType
 	VerInfoType VerInfo;	
 	UINT8	CRC;
 }VersionMsgtoTcpType;
-typedef struct _StatesInfoType
-{
-	UINT8	sendTimeUTC[6];
-	UINT8	msgMark;
-	UINT8	msgCollectionTimeUTC[6];
-	UINT8 	ResetStates;
-	UINT8	BattLockStates;
-	UINT8	HeatSwitchStates;
-	UINT8	BuzzerStatus;
-}StatesInfoType;
-typedef struct _StatesMsgtoTcpType
-{
-	UINT8 	startSymbol[2];
-	UINT8	cmdSymbol;
-	UINT8	ansSymbol;
-	UINT8	SN[BATT_SN_LEN];
-	UINT8	encryptMethod;
-	UINT8	dataLength[2];	
-	StatesInfoType StatesInfo;	
-	UINT8	CRC;
-}StatesMsgtoTcpType;
 /*---------------------------------------------------------------------------*/
 typedef enum
 {

+ 35 - 5
src/Fota.c

@@ -18,13 +18,19 @@ static Fota_Type Fota_S;
 static UINT8 bcc_chk_fota(UINT8* data, UINT8 length);
 static UINT8 Fota_crc_chk(UINT8* data,UINT8 length);
 volatile bool Fota_update_flag = FALSE; //可以升级标志
-void Fota_Func(UINT8 *DataPtr,INT32 connectId)
+void Fota_Func(UINT8 *DataPtr,INT32 connectId,UINT8 FotaType)
 {
     UINT8 Fota_Answer[43];
     UINT8 Fota_Cmd;
     INT8 ret;
-    //Fota_S.Fota_Flash_Addres = FLASH_FOTA_REGION_START;
-    Fota_S.Fota_Flash_Addres = FLASH_BMS_FOTA_START_ADDR;
+    if(FotaType==0x01)
+    {
+        Fota_S.Fota_Flash_Addres = FLASH_FOTA_REGION_START;
+    }
+    else if(FotaType == 0x88)
+    {
+        Fota_S.Fota_Flash_Addres = FLASH_BMS_FOTA_START_ADDR;
+    }
     if(*(DataPtr+30)==0x01)
     {
         Fota_Cmd = *(DataPtr+31);
@@ -37,7 +43,28 @@ void Fota_Func(UINT8 *DataPtr,INT32 connectId)
             {
                 Fota_S.Fota_All_Data_Len = *(DataPtr+33)<<24|*(DataPtr+34)<<16|*(DataPtr+35)<<8|*(DataPtr+36);
                 Fota_S.Fota_Current_Addres = *(DataPtr+37)<<24|*(DataPtr+38)<<16|*(DataPtr+39)<<8|*(DataPtr+40);
-                Fota_Answer[3] = 0x01;
+                if(FotaType==0x01)
+                {
+                    if(Fota_S.Fota_All_Data_Len>=(FLASH_BMS_FOTA_START_ADDR - FLASH_FOTA_REGION_START))
+                    {
+                        Fota_Answer[3] = 0x02;
+                    }
+                    else
+                    {
+                        Fota_Answer[3] = 0x01;
+                    }
+                }
+                if(FotaType==0x88)
+                {
+                    if(Fota_S.Fota_All_Data_Len>=(FLASH_BMS_FOTA_END_ADDR - FLASH_BMS_FOTA_START_ADDR))
+                    {
+                        Fota_Answer[3] = 0x02;
+                    }
+                    else
+                    {
+                        Fota_Answer[3] = 0x01;
+                    }
+                }
                 memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
                 Fota_Answer[21] = TCP_ENCPT_DISABLE;
                 Fota_Answer[22] = 0x00;
@@ -45,7 +72,10 @@ void Fota_Func(UINT8 *DataPtr,INT32 connectId)
                 memcpy(&Fota_Answer[24],(DataPtr+24),18);
                 Fota_Answer[42] =  bcc_chk_fota(Fota_Answer,42);
                 tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
-                BSP_QSPI_Erase_Safe(Fota_S.Fota_Flash_Addres,Fota_S.Fota_All_Data_Len + 4 - (Fota_S.Fota_All_Data_Len%4)); //512k-32k = 480k -> 0x75300  0x78000
+                if(Fota_Answer[3] == 0x01)
+                {
+                    BSP_QSPI_Erase_Safe(Fota_S.Fota_Flash_Addres,Fota_S.Fota_All_Data_Len + 4 - (Fota_S.Fota_All_Data_Len%4)); //512k-32k = 480k -> 0x75300  0x78000
+                }
                 break;
             }
             case 0x02:

+ 23 - 62
src/TcpTask.c

@@ -57,7 +57,6 @@ static QueueHandle_t TcpRecvHandle = NULL;
 //Tcp线程堆栈申请区
 
 //函数声明区
-static void TcpWorkStatus(void *arg);
 static void sendQueueMsg(UINT32 msgId, UINT32 xTickstoWait);
 static INT32 socketRegisterPSUrcCallback(urcID_t eventID, void *param, UINT32 paramLen);
 static void socketAppConnectionCallBack(UINT8 connectionEventType, void *bodyEvent);
@@ -281,7 +280,14 @@ static void TcpDataInfoAssembleSend()
 	    BattToTcpInfo.battInfo.battPackVol[0] = BattU >> 8;
 	    BattToTcpInfo.battInfo.battPackVol[1] = BattU & 0xFF;
         temp = ((UartReadMsg.data[(0x09+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1])>>1)&0x03;
-        BattToTcpInfo.battInfo.mosState = ((temp&0x01)<<01)|(temp>>0x01);
+        if(AppNVMData.isBattLocked==TRUE)
+        {
+            BattToTcpInfo.battInfo.switchState = ((temp&0x01)<<1)|((temp&0x02)>>1)|0x01<<2;
+        }
+        else
+        {
+            BattToTcpInfo.battInfo.switchState = ((temp&0x01)<<1)|((temp&0x02)>>1)|0x00<<2;
+        }
         BattToTcpInfo.battInfo.battSOC = UartReadMsg.data[(0x0B+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1];
         BattToTcpInfo.battInfo.battSOH = UartReadMsg.data[(0x0C+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1];
         memcpy(BattToTcpInfo.battInfo.batCellBalenceState,&UartReadMsg.data[(0x06+BATT_CELL_VOL_NUM+TEMP_NUM)*2],4);
@@ -413,7 +419,6 @@ static void TcpDataInfoRecvHandle()
     osMessageQueueGet(TcpRecvHandle,&TcpRecvData,0,0);
     osDelay(100);
     Uart_Write_Data_Type UartWriteCmd;
-    StatesMsgtoTcpType StatesMsg;
     OsaUtcTimeTValue TimeStracture;
     UINT8 DataLen;
     UINT8 Tcp_Cmd;
@@ -443,7 +448,11 @@ static void TcpDataInfoRecvHandle()
                 TcpCmdAnswer[2] = TCP_CONCMD_SYM;
                 if(*(Ptr+30)==0x01)//远程升级命令
                 {
-                    Fota_Func(Ptr,socContext.id);
+                    Fota_Func(Ptr,socContext.id,0x01);
+                }
+                else if(*(Ptr+30)==0x88)//BMS远程升级数据传输命令
+                {
+                    Fota_Func(Ptr,socContext.id,0x88);
                 }
                 else if(*(Ptr+30)==0x80)//远程锁定命令
                 {
@@ -459,14 +468,6 @@ static void TcpDataInfoRecvHandle()
                         {
                             osMessageQueuePut(UartWriteCmdHandle,&UartWriteCmd,0,1000);
                         }
-                        TcpCmdAnswer[3] = 0x01;
-                        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);
                     }
                     else                //0x02代表解锁
                     {
@@ -476,57 +477,18 @@ static void TcpDataInfoRecvHandle()
                         UartWriteCmd.Data[0] = 0x00;
                         UartWriteCmd.Data[1] = 0x03;
                         osMessageQueuePut(UartWriteCmdHandle,&UartWriteCmd,0,1000);
-                        TcpCmdAnswer[3] = 0x01;
-                        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);
-                    }
-                    osDelay(1000);
-                    appGetSystemTimeUtcSync(&TimeStracture);
-                    DataLen= (UINT16)sizeof(StatesMsg.StatesInfo);
-                    StatesMsg.startSymbol[0] = TCP_START_SYM1;
-                    StatesMsg.startSymbol[1] = TCP_START_SYM2;
-                    StatesMsg.cmdSymbol = TCP_CMD_SYM;
-                    StatesMsg.ansSymbol = TCP_ANS_SYM;
-                    memcpy(StatesMsg.SN, AppNVMData.battSN,BATT_SN_LEN);
-                    StatesMsg.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
-                    StatesMsg.dataLength[0] = (DataLen>>8) & 0xFF;
-                    StatesMsg.dataLength[1] = DataLen & 0xFF;
-                    StatesMsg.StatesInfo.sendTimeUTC[0] = ((((TimeStracture.UTCtimer1) >> 16) & 0xFFFF) - 0x07D0) & 0xFF; 	//year
-                    StatesMsg.StatesInfo.sendTimeUTC[1] = ((TimeStracture.UTCtimer1) >> 8 ) & 0xFF;							//month
-                    StatesMsg.StatesInfo.sendTimeUTC[2] = (TimeStracture.UTCtimer1) & 0xFF;									//day
-                    StatesMsg.StatesInfo.sendTimeUTC[3] = ((TimeStracture.UTCtimer2) >> 24 ) & 0xFF; 						    //hour
-                    StatesMsg.StatesInfo.sendTimeUTC[4] = ((TimeStracture.UTCtimer2) >> 16 ) & 0xFF;						    //mins
-                    StatesMsg.StatesInfo.sendTimeUTC[5] = ((TimeStracture.UTCtimer2) >> 8 ) & 0xFF;							//sec
-                    StatesMsg.StatesInfo.msgMark = STATESMSG;
-                    StatesMsg.StatesInfo.msgCollectionTimeUTC[0] = ((((TimeStracture.UTCtimer1) >> 16) & 0xFFFF) - 0x07D0) & 0xFF; 	//year
-                    StatesMsg.StatesInfo.msgCollectionTimeUTC[1] = ((TimeStracture.UTCtimer1) >> 8 ) & 0xFF;							//month
-                    StatesMsg.StatesInfo.msgCollectionTimeUTC[2] = (TimeStracture.UTCtimer1) & 0xFF;									//day
-                    StatesMsg.StatesInfo.msgCollectionTimeUTC[3] = ((TimeStracture.UTCtimer2) >> 24 ) & 0xFF; 						    //hour
-                    StatesMsg.StatesInfo.msgCollectionTimeUTC[4] = ((TimeStracture.UTCtimer2) >> 16 ) & 0xFF;						    //mins
-                    StatesMsg.StatesInfo.msgCollectionTimeUTC[5] = ((TimeStracture.UTCtimer2) >> 8 ) & 0xFF;
-                    StatesMsg.StatesInfo.ResetStates = 0;
-                    if((UartReadMsg.data[(0x1B+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+2)*2+1]==0x00)&&(AppNVMData.isBattLocked == TRUE))
-                    {
-                        StatesMsg.StatesInfo.BattLockStates = 1;
-                    }
-                    else if((UartReadMsg.data[(0x1B+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+2)*2+1]!=0x00)&&(AppNVMData.isBattLocked == FALSE))
-                    {
-                        StatesMsg.StatesInfo.BattLockStates = 0;
-                    }
-                    else if((UartReadMsg.data[(0x1B+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+2)*2+1]!=0x00)&&(AppNVMData.isBattLocked == TRUE))
-                    {
-                        StatesMsg.StatesInfo.BattLockStates = 2;
                     }
-                    StatesMsg.StatesInfo.HeatSwitchStates = UartReadMsg.data[(0x1C+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+2)*2+1];
-                    StatesMsg.StatesInfo.BuzzerStatus = 0;
-                    StatesMsg.CRC = bcc_chk((UINT8 *)&StatesMsg, sizeof(StatesMsgtoTcpType)-1 );
-                    tcpipConnectionSend(socContext.id, (UINT8 *)&StatesMsg, sizeof(StatesMsgtoTcpType), 0, 0, 0);
+                    TcpCmdAnswer[3] = 0x01;
+                    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);
                     osMutexRelease(UartMutex);
+                    tcpipConnectionSend(socContext.id,TcpCmdAnswer,31,0,0,0);
+                    TcpService=0x00;
+                    
                 }
                 else
                 {
@@ -545,7 +507,6 @@ static void TcpDataInfoRecvHandle()
                 break;
             }
         }
-
     free(TcpRecvData); 
     }
 }