|
@@ -7,3 +7,101 @@
|
|
|
*
|
|
|
****************************************************************************/
|
|
|
#include "Fota.h"
|
|
|
+#include "ec_tcpip_api.h"
|
|
|
+#include "ps_lib_api.h"
|
|
|
+#include "MainTask.h"
|
|
|
+#include "TcpTask.h"
|
|
|
+#include "os_exception.h"
|
|
|
+extern AppNVMDataType AppNVMData;
|
|
|
+static Fota_Type Fota_S;
|
|
|
+static UINT8 bcc_chk_fota(UINT8* data, UINT8 length);
|
|
|
+static UINT8 Fota_crc_chk(UINT8* data,UINT8 length);
|
|
|
+void Fota_Func(UINT8 *DataPtr,INT32 connectId)
|
|
|
+{
|
|
|
+ UINT8 Fota_Answer[42];
|
|
|
+ UINT8 Fota_Cmd;
|
|
|
+ Fota_S.Fota_Flash_Addres = Fota_Addres_Begin;
|
|
|
+ if(*(DataPtr+30)==0x01)
|
|
|
+ {
|
|
|
+ Fota_S.Fota_update_flag = true;
|
|
|
+ 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);
|
|
|
+ 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,41);
|
|
|
+ tcpipConnectionSend(connectId,Fota_Answer,42,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);
|
|
|
+ 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);
|
|
|
+ if(Fota_S.Fota_CRC == *(DataPtr+Fota_S.Fota_Recv_Data_Len+42))
|
|
|
+ {
|
|
|
+ BSP_QSPI_Erase_Safe(Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
|
|
|
+ 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);
|
|
|
+ Fota_Answer[3] = 0x01;
|
|
|
+ }
|
|
|
+ else//数据校验失败
|
|
|
+ {
|
|
|
+ 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,41);
|
|
|
+ tcpipConnectionSend(connectId,Fota_Answer,42,0,0,0);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 0x03:
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Fota_S.Fota_update_flag = false;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+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;
|
|
|
+}
|