|
@@ -10,192 +10,16 @@
|
|
|
#include "numeric.h"
|
|
|
#include "hal_module_adapter.h"
|
|
|
|
|
|
-
|
|
|
-void battSOCDisplay()
|
|
|
+UINT8 bcc_chk(UINT8* data, UINT8 length)
|
|
|
{
|
|
|
-
|
|
|
- static UINT8 lightTimer = 0;
|
|
|
- UINT8 socLowLEDFlashPeriod = 10;//10*100 = 1000ms
|
|
|
- UINT8 chargeLEDFlashPeriod = 6;//6*100 = 600ms
|
|
|
- float dutyRatio = 0.4;
|
|
|
-
|
|
|
- if(UartRecvFlag == true)
|
|
|
- {
|
|
|
- lightTimer++;
|
|
|
-
|
|
|
- if(battWorkState == 0||battWorkState == 1) //静置或放电状态
|
|
|
- {
|
|
|
- if(battSOC<=10)
|
|
|
- {
|
|
|
- if(lightTimer<(UINT8)(socLowLEDFlashPeriod*dutyRatio))
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
- }
|
|
|
- else if(lightTimer>=(UINT8)(socLowLEDFlashPeriod*dutyRatio) && lightTimer<socLowLEDFlashPeriod)
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
- lightTimer = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- else if(battSOC>10&&battSOC<=25)
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
- lightTimer = 0;
|
|
|
- }
|
|
|
- else if(battSOC>25&&battSOC<=50)
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
- lightTimer = 0;
|
|
|
- }
|
|
|
- else if(battSOC>50&&battSOC<=75)
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
- lightTimer = 0;
|
|
|
- }
|
|
|
- else if(battSOC>75&&battSOC<=100)
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_ON);
|
|
|
- lightTimer = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- else if(battWorkState == 2)
|
|
|
- {
|
|
|
- if(battSOC<=25)
|
|
|
- {
|
|
|
- if(lightTimer<(UINT8)(chargeLEDFlashPeriod*dutyRatio))
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
- }
|
|
|
- else if(lightTimer>=(UINT8)(chargeLEDFlashPeriod*dutyRatio) && lightTimer<chargeLEDFlashPeriod)
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
- lightTimer = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- else if(battSOC>25&&battSOC<=50)
|
|
|
- {
|
|
|
- if(lightTimer<(UINT8)(chargeLEDFlashPeriod*dutyRatio))
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
- }
|
|
|
- else if(lightTimer>=(UINT8)(chargeLEDFlashPeriod*dutyRatio) && lightTimer<chargeLEDFlashPeriod)
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
- lightTimer = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- else if(battSOC>50&&battSOC<=75)
|
|
|
- {
|
|
|
- if(lightTimer<(UINT8)(chargeLEDFlashPeriod*dutyRatio))
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
- }
|
|
|
- else if(lightTimer>=(UINT8)(chargeLEDFlashPeriod*dutyRatio) && lightTimer<chargeLEDFlashPeriod)
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
- lightTimer = 0;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- else if(battSOC>75&&battSOC<=97)
|
|
|
- {
|
|
|
- if(lightTimer<(UINT8)(chargeLEDFlashPeriod*dutyRatio))
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_ON);
|
|
|
- }
|
|
|
- else if(lightTimer>=(UINT8)(chargeLEDFlashPeriod*dutyRatio) && lightTimer<chargeLEDFlashPeriod)
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
- lightTimer = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- else if(battSOC>97&&battSOC<=100)
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_2,LED_TURN_ON);
|
|
|
- NetSocDisplay(LED_SOC_3,LED_TURN_ON);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ UINT8 bcc_chk_return = 0x00;
|
|
|
+ UINT8 count = 0;
|
|
|
+ while (count<length)
|
|
|
+ {
|
|
|
+ bcc_chk_return^=data[count];
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ return bcc_chk_return;
|
|
|
}
|
|
|
/***********************************************************************************************************************
|
|
|
* LED控制函数
|
|
@@ -272,14 +96,16 @@ void LEDDisplay(void)
|
|
|
FaultDisplay(LED_TURN_OFF);
|
|
|
LightTimer = 0;
|
|
|
}
|
|
|
- #ifdef USING_PRINTF
|
|
|
- printf("[%d]",__LINE__);
|
|
|
- #endif
|
|
|
return;
|
|
|
}
|
|
|
else if(UartRecvFlag==1) //电池接收到UART信息,且正确运行
|
|
|
{
|
|
|
- if(battWarningState != 0)
|
|
|
+ if(battWorkState == 0x02) //充电模式下,如果只有“SOC低故障”,那么就不显示故障灯 zhengchao20210713 add
|
|
|
+ {
|
|
|
+ if((((battWarningState >> 10) & 0x01) == 0x01) && ((battWarningState & 0xFFFFFBFF) == 0x00))
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(battWarningState != 0) //电池存在故障
|
|
|
{
|
|
|
if(ErrorLightTimer<(UINT8)(LEDFlashPeriod*DutyRatio))
|
|
|
{
|
|
@@ -331,10 +157,7 @@ void LEDDisplay(void)
|
|
|
NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
|
|
|
NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
LightTimer = 0;
|
|
|
- }
|
|
|
- #ifdef USING_PRINTF
|
|
|
- printf("[%d]",__LINE__);
|
|
|
- #endif
|
|
|
+ }
|
|
|
}
|
|
|
else if(battSOC>10&&battSOC<=25)
|
|
|
{
|
|
@@ -394,10 +217,7 @@ void LEDDisplay(void)
|
|
|
NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
|
|
|
NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
|
|
|
LightTimer = 0;
|
|
|
- }
|
|
|
- #ifdef USING_PRINTF
|
|
|
- printf("[%d]",__LINE__);
|
|
|
- #endif
|
|
|
+ }
|
|
|
}
|
|
|
else if(battSOC>25&&battSOC<=50)
|
|
|
{
|
|
@@ -845,9 +665,6 @@ void SaveAppData(void)
|
|
|
}
|
|
|
AppDataHr.fileBodySize = sizeof(AppDataInfo);
|
|
|
AppDataHr.checkSum = OsaCalcCrcValue((UINT8 *)&AppDataInfo, sizeof(AppDataInfo));
|
|
|
- #ifdef USING_PRINTF
|
|
|
- printf(" AppDataHr.fileBodySize:%x\n",AppDataHr.fileBodySize);
|
|
|
- #endif
|
|
|
writeCount = OsaFwrite(&AppDataHr, sizeof(AppDataHr), 1, fp);
|
|
|
if (writeCount != 1)
|
|
|
{
|
|
@@ -1177,4 +994,278 @@ UINT16 encryptionAlgorithm (UINT16 plainText)
|
|
|
* 输入:网络接收的数据,网络链接ID
|
|
|
* 输出:0x00表示数据未准备完成,0x01表示数据模块OTA数据准备完成,0x88表示BMS的OTA数据准备完成
|
|
|
* 处理:将接收的数据进行校验,搬运至升级区域,并进行应答
|
|
|
-***********************************************************************************************************************/
|
|
|
+***********************************************************************************************************************/
|
|
|
+void Fota_Func(UINT8 *DataPtr,INT32 connectId)
|
|
|
+{
|
|
|
+ Fota_Type Fota_S;
|
|
|
+ UINT8 Fota_Answer[43];
|
|
|
+ UINT8 Fota_Cmd;
|
|
|
+ INT8 ret;
|
|
|
+ UINT8* Data_Read_Buffer=PNULL;
|
|
|
+ UINT8 Data_Read_Crc;
|
|
|
+ if(*(DataPtr+30)==0x01)
|
|
|
+ {
|
|
|
+ Fota_S.Fota_Flash_Addres = FLASH_FOTA_REGION_START;
|
|
|
+ Fota_Cmd = *(DataPtr+31);
|
|
|
+ Fota_Answer[0] = TCP_START_SYM1;
|
|
|
+ Fota_Answer[1] = TCP_START_SYM2;
|
|
|
+ Fota_Answer[2] = TCP_CONCMD_SYM;
|
|
|
+ switch (Fota_Cmd)
|
|
|
+ {
|
|
|
+ case 0x01:
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ 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;
|
|
|
+ BSP_QSPI_Erase_Safe(Fota_S.Fota_Flash_Addres,(FLASH_BMS_FOTA_START_ADDR - FLASH_FOTA_REGION_START)); //512k-32k = 480k -> 0x75300 0x78000
|
|
|
+ }
|
|
|
+ memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
|
|
|
+ Fota_Answer[21] = TCP_ENCPT_DISABLE;
|
|
|
+ Fota_Answer[22] = 0x00;
|
|
|
+ Fota_Answer[23] = 0x12;
|
|
|
+ memcpy(&Fota_Answer[24],(DataPtr+24),18);
|
|
|
+ Fota_Answer[42] = bcc_chk_fota(Fota_Answer,42);
|
|
|
+ tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 0x02:
|
|
|
+ {
|
|
|
+ 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_S.Fota_Recv_Data_Len = *(DataPtr+41);
|
|
|
+ memset(Fota_S.Fota_Recv_Data,0x00,100);
|
|
|
+ memcpy(Fota_S.Fota_Recv_Data,(DataPtr+42),*(DataPtr+41));
|
|
|
+ Fota_S.Fota_CRC = Fota_crc_chk(Fota_S.Fota_Recv_Data,Fota_S.Fota_Recv_Data_Len);
|
|
|
+ Data_Read_Buffer = malloc(Fota_S.Fota_Recv_Data_Len+1);
|
|
|
+ if(Fota_S.Fota_CRC == *(DataPtr+Fota_S.Fota_Recv_Data_Len+42)||Data_Read_Buffer!=PNULL)
|
|
|
+ {
|
|
|
+ if(Fota_S.Fota_Recv_Data_Len%4!=0)
|
|
|
+ {
|
|
|
+ Fota_S.Fota_Recv_Data_Len = Fota_S.Fota_Recv_Data_Len + 4-(Fota_S.Fota_Recv_Data_Len%4);
|
|
|
+ }
|
|
|
+ BSP_QSPI_Write_Safe(Fota_S.Fota_Recv_Data,Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
|
|
|
+ memset(Data_Read_Buffer,0x00,Fota_S.Fota_Recv_Data_Len);
|
|
|
+ BSP_QSPI_Read_Safe(Data_Read_Buffer,Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
|
|
|
+ Data_Read_Crc = Fota_crc_chk(Data_Read_Buffer,Fota_S.Fota_Recv_Data_Len);
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("Data_Read_Buffer:\n");
|
|
|
+ for(int i=0;i<Fota_S.Fota_Recv_Data_Len;i++)
|
|
|
+ {
|
|
|
+ printf("%x ",*(Data_Read_Buffer+i));
|
|
|
+ }
|
|
|
+ printf("\n");
|
|
|
+ #endif
|
|
|
+ if(Data_Read_Crc==Fota_S.Fota_CRC )
|
|
|
+ {
|
|
|
+ Fota_Answer[3] = 0x01;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Fota_Answer[3] = 0x02;
|
|
|
+ BSP_QSPI_Erase_Safe(Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else//数据校验失败
|
|
|
+ {
|
|
|
+ Fota_Answer[3] = 0x02;
|
|
|
+ }
|
|
|
+ if(Data_Read_Buffer!=PNULL)
|
|
|
+ free(Data_Read_Buffer);
|
|
|
+ Data_Read_Buffer =PNULL;
|
|
|
+ memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
|
|
|
+ Fota_Answer[21] = TCP_ENCPT_DISABLE;
|
|
|
+ Fota_Answer[22] = 0x00;
|
|
|
+ Fota_Answer[23] = 0x12;
|
|
|
+ memcpy(&Fota_Answer[24],(DataPtr+24),18);
|
|
|
+ Fota_Answer[42] = bcc_chk_fota(Fota_Answer,42);
|
|
|
+ tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 0x03:
|
|
|
+ {
|
|
|
+ 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;
|
|
|
+ memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
|
|
|
+ Fota_Answer[21] = TCP_ENCPT_DISABLE;
|
|
|
+ Fota_Answer[22] = 0x00;
|
|
|
+ Fota_Answer[23] = 0x12;
|
|
|
+ memcpy(&Fota_Answer[24],(DataPtr+24),18);
|
|
|
+ Fota_Answer[42] = bcc_chk_fota(Fota_Answer,42);
|
|
|
+ tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
|
|
|
+ if(Fota_S.Fota_All_Data_Len==Fota_S.Fota_Current_Addres)
|
|
|
+ {
|
|
|
+ NB_Fota_update_flag = TRUE;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ NB_Fota_update_flag = FALSE;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ {
|
|
|
+ Fota_Answer[3] = 0x02;
|
|
|
+ memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
|
|
|
+ Fota_Answer[21] = TCP_ENCPT_DISABLE;
|
|
|
+ Fota_Answer[22] = 0x00;
|
|
|
+ Fota_Answer[23] = 0x12;
|
|
|
+ memcpy(&Fota_Answer[24],(DataPtr+24),18);
|
|
|
+ Fota_Answer[42] = bcc_chk_fota(Fota_Answer,42);
|
|
|
+ tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(*(DataPtr+30)==0x88)//BMS升级文件存放
|
|
|
+ {
|
|
|
+ Fota_S.Fota_Flash_Addres = FLASH_BMS_FOTA_START_ADDR;
|
|
|
+ Fota_Cmd = *(DataPtr+31);
|
|
|
+ Fota_Answer[0] = TCP_START_SYM1;
|
|
|
+ Fota_Answer[1] = TCP_START_SYM2;
|
|
|
+ Fota_Answer[2] = TCP_CONCMD_SYM;
|
|
|
+ switch (Fota_Cmd)
|
|
|
+ {
|
|
|
+ case 0x01:
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ 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;
|
|
|
+ Fota_Answer[23] = 0x12;
|
|
|
+ memcpy(&Fota_Answer[24],(DataPtr+24),18);
|
|
|
+ Fota_Answer[42] = bcc_chk_fota(Fota_Answer,42);
|
|
|
+ tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
|
|
|
+ if(Fota_Answer[3] == 0x01)
|
|
|
+ {
|
|
|
+ BSP_QSPI_Erase_Safe(Fota_S.Fota_Flash_Addres,(FLASH_BMS_FOTA_END_ADDR - FLASH_BMS_FOTA_START_ADDR)); //512k-32k = 480k -> 0x75300 0x78000
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 0x02:
|
|
|
+ {
|
|
|
+ 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_S.Fota_Recv_Data_Len = *(DataPtr+41);
|
|
|
+ memset(Fota_S.Fota_Recv_Data,0x00,100);
|
|
|
+ memcpy(Fota_S.Fota_Recv_Data,(DataPtr+42),*(DataPtr+41));
|
|
|
+ Fota_S.Fota_CRC = Fota_crc_chk(Fota_S.Fota_Recv_Data,Fota_S.Fota_Recv_Data_Len);
|
|
|
+ Data_Read_Buffer = malloc(Fota_S.Fota_Recv_Data_Len);
|
|
|
+ if(Fota_S.Fota_CRC == *(DataPtr+Fota_S.Fota_Recv_Data_Len+42)||Data_Read_Buffer!=PNULL)
|
|
|
+ {
|
|
|
+ if(Fota_S.Fota_Recv_Data_Len%4!=0)
|
|
|
+ {
|
|
|
+ Fota_S.Fota_Recv_Data_Len = Fota_S.Fota_Recv_Data_Len + 4-(Fota_S.Fota_Recv_Data_Len%4);
|
|
|
+ }
|
|
|
+ BSP_QSPI_Write_Safe(Fota_S.Fota_Recv_Data,Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
|
|
|
+
|
|
|
+ BSP_QSPI_Read_Safe(Data_Read_Buffer,Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
|
|
|
+ Data_Read_Crc = Fota_crc_chk(Data_Read_Buffer,Fota_S.Fota_Recv_Data_Len);
|
|
|
+ #ifdef USING_PRINTF1
|
|
|
+ printf("\n\n\n");
|
|
|
+ UINT8 temp[1];
|
|
|
+ for(int i=0;i<Fota_S.Fota_Recv_Data_Len;i++)
|
|
|
+ {
|
|
|
+ printf("%x ",*(Data_Read_Buffer+i));
|
|
|
+ }
|
|
|
+ printf("\n\n\n");
|
|
|
+ #endif
|
|
|
+ if(Data_Read_Crc==Fota_S.Fota_CRC )
|
|
|
+ {
|
|
|
+ Fota_Answer[3] = 0x01;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Fota_Answer[3] = 0x02;
|
|
|
+ BSP_QSPI_Erase_Safe(Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else//数据校验失败
|
|
|
+ {
|
|
|
+ Fota_Answer[3] = 0x02;
|
|
|
+ }
|
|
|
+ if(Data_Read_Buffer!=PNULL)
|
|
|
+ free(Data_Read_Buffer);
|
|
|
+ Data_Read_Buffer =PNULL;
|
|
|
+ memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
|
|
|
+ Fota_Answer[21] = TCP_ENCPT_DISABLE;
|
|
|
+ Fota_Answer[22] = 0x00;
|
|
|
+ Fota_Answer[23] = 0x12;
|
|
|
+ memcpy(&Fota_Answer[24],(DataPtr+24),18);
|
|
|
+ Fota_Answer[42] = bcc_chk_fota(Fota_Answer,42);
|
|
|
+ tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 0x03:
|
|
|
+ {
|
|
|
+ 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;
|
|
|
+ memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
|
|
|
+ Fota_Answer[21] = TCP_ENCPT_DISABLE;
|
|
|
+ Fota_Answer[22] = 0x00;
|
|
|
+ Fota_Answer[23] = 0x12;
|
|
|
+ memcpy(&Fota_Answer[24],(DataPtr+24),18);
|
|
|
+ Fota_Answer[42] = bcc_chk_fota(Fota_Answer,42);
|
|
|
+ tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
|
|
|
+ if(Fota_S.Fota_All_Data_Len==Fota_S.Fota_Current_Addres)
|
|
|
+ {
|
|
|
+ BMS_Fota_update_flag = TRUE;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ BMS_Fota_update_flag = FALSE;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ {
|
|
|
+ Fota_Answer[3] = 0x02;
|
|
|
+ memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
|
|
|
+ Fota_Answer[21] = TCP_ENCPT_DISABLE;
|
|
|
+ Fota_Answer[22] = 0x00;
|
|
|
+ Fota_Answer[23] = 0x12;
|
|
|
+ memcpy(&Fota_Answer[24],(DataPtr+24),18);
|
|
|
+ Fota_Answer[42] = bcc_chk_fota(Fota_Answer,42);
|
|
|
+ tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+static UINT8 bcc_chk_fota(UINT8* data, UINT8 length)
|
|
|
+{
|
|
|
+ UINT8 bcc_chk_return = 0x00;
|
|
|
+ UINT8 count = 0;
|
|
|
+ while (count<length)
|
|
|
+ {
|
|
|
+ bcc_chk_return^=data[count];
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ return bcc_chk_return;
|
|
|
+}
|
|
|
+static UINT8 Fota_crc_chk(UINT8* data,UINT8 length)
|
|
|
+{
|
|
|
+ UINT8 reg_crc=0x00;
|
|
|
+ while(length--)
|
|
|
+ {
|
|
|
+ reg_crc ^= *data++;
|
|
|
+ }
|
|
|
+ return reg_crc;
|
|
|
+}
|