|
@@ -202,7 +202,7 @@ sint8 TcpDataSendFunc(sint8 ConnectId)
|
|
|
outValue = tcpipConnectionSend(ConnectId, (uint8 *)pSendDataAddr, DataSendLen); //发送函数
|
|
|
if (pSendDataAddr != 0)
|
|
|
{
|
|
|
- free((uint8 *)(pSendDataAddr));
|
|
|
+ vPortFree((uint8 *)(pSendDataAddr));
|
|
|
}
|
|
|
pSendDataAddr = 0;
|
|
|
return outValue;
|
|
@@ -728,7 +728,7 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
|
|
|
GPSInfo GpsRecvData;
|
|
|
GPSMsgtoTcpType GpsToTcpInfo;
|
|
|
*SendLen = sizeof(GpsToTcpInfo);
|
|
|
- SendBuffer = malloc(*SendLen);
|
|
|
+ SendBuffer = pvPortMalloc(*SendLen);
|
|
|
uint16 tac = 0;
|
|
|
uint32 cellId = 0;
|
|
|
uint8 DataLen = (uint16)sizeof(GpsToTcpInfo.gpsInfo);
|
|
@@ -796,7 +796,7 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
|
|
|
{
|
|
|
VersionMsgtoTcpType VerMsgToTcpInfo;
|
|
|
*SendLen = sizeof(VersionMsgtoTcpType);
|
|
|
- SendBuffer = malloc(*SendLen);
|
|
|
+ SendBuffer = pvPortMalloc(*SendLen);
|
|
|
uint16 DataLen = 0;
|
|
|
DataLen = (uint16)sizeof(VerMsgToTcpInfo.VerInfo);
|
|
|
VerMsgToTcpInfo.startSymbol[0] = TCP_START_SYM1;
|
|
@@ -859,7 +859,7 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
|
|
|
uint16 ProtocolFluctedLen = AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + BmsOtherTemp + OtherTemp; //电池信息协议变动长度
|
|
|
uint16 DataLen;
|
|
|
*SendLen = ProtocolFixedLen + ProtocolFluctedLen;
|
|
|
- SendBuffer = malloc(*SendLen);
|
|
|
+ SendBuffer = pvPortMalloc(*SendLen);
|
|
|
GetCSQValue(&CSQValue);
|
|
|
*(SendBuffer + 0) = TCP_START_SYM1; //起始码-1
|
|
|
*(SendBuffer + 1) = TCP_START_SYM2; //起始码-2
|
|
@@ -925,7 +925,7 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
|
|
|
{
|
|
|
StorageInfoToTcp StorageInfo;
|
|
|
*SendLen = sizeof(StorageInfo);
|
|
|
- SendBuffer = malloc(*SendLen);
|
|
|
+ SendBuffer = pvPortMalloc(*SendLen);
|
|
|
uint16 DataLen = 0;
|
|
|
DataLen = (uint16)sizeof(StorageInfo.StorageMsg);
|
|
|
StorageInfo.startSymbol[0] = TCP_START_SYM1;
|
|
@@ -962,7 +962,7 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
|
|
|
{
|
|
|
StorageInfoToTcp2 StorageInfo2;
|
|
|
*SendLen = sizeof(StorageInfo2);
|
|
|
- SendBuffer = malloc(*SendLen);
|
|
|
+ SendBuffer = pvPortMalloc(*SendLen);
|
|
|
uint16 DataLen = 0;
|
|
|
DataLen = (uint16)sizeof(StorageInfo2.StorageMsg2);
|
|
|
StorageInfo2.startSymbol[0] = TCP_START_SYM1;
|
|
@@ -1021,7 +1021,7 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
|
|
|
{
|
|
|
AccInfoToTcp AccInfoToTcpMsg;
|
|
|
*SendLen = sizeof(AccInfoToTcpMsg);
|
|
|
- SendBuffer = malloc(*SendLen);
|
|
|
+ SendBuffer = pvPortMalloc(*SendLen);
|
|
|
uint16 DataLen = 0;
|
|
|
DataLen = (uint16)sizeof(AccInfoToTcpMsg.AccMsg);
|
|
|
AccInfoToTcpMsg.startSymbol[0] = TCP_START_SYM1;
|
|
@@ -1188,6 +1188,7 @@ static void TcpDataInfoRecvHandle(uint8 *DataRecv, uint16 DataRecvLen)
|
|
|
memcpy(&TcpCmdAnswer[24], (Ptr + 24), 6);
|
|
|
TcpCmdAnswer[30] = bcc_chk(TcpCmdAnswer, 30);
|
|
|
tcpipConnectionSend(SocketId, TcpCmdAnswer, 31);
|
|
|
+ vTaskDelay(pdMS_TO_TICKS(1000));
|
|
|
Fota_Ftp(Ptr + 32);
|
|
|
}
|
|
|
else if (*(Ptr + 30) == 0x80) //远程锁定命令
|
|
@@ -1520,7 +1521,10 @@ void Fota_Ftp(uint8 *dataPtrIn)
|
|
|
uint32 appReceviedCRC;
|
|
|
uint16 getDataLenErrCount = 0;
|
|
|
uint8 *UartData = NULL;
|
|
|
- UartData = malloc(512);
|
|
|
+ uint8 *FlashData = NULL;
|
|
|
+ uint8 *fileDataPtr = NULL;
|
|
|
+ UartData = pvPortMalloc(512);
|
|
|
+ FlashData = pvPortMalloc(512);
|
|
|
#if SEGGER_PRINTF==1
|
|
|
SEGGER_RTT_printf("[%d]UartData1=%X\r\n",__LINE__,UartData);
|
|
|
#endif
|
|
@@ -1541,9 +1545,11 @@ void Fota_Ftp(uint8 *dataPtrIn)
|
|
|
while(readLenAsk!=0)
|
|
|
{
|
|
|
#if SEGGER_PRINTF==1
|
|
|
- SEGGER_RTT_printf("[%d]UartData2=%X\r\n",__LINE__,UartData);
|
|
|
+ SEGGER_RTT_printf("[%d]UartData2=%X,FlashData=%X,err=%d\r\n",__LINE__,UartData,FlashData,getDataLenErrCount);
|
|
|
#endif
|
|
|
memset(UartData,0x00,512);
|
|
|
+ memset(FlashData,0x00,512);
|
|
|
+ UART_Reset(UART_LPUART1);
|
|
|
memset(ATSendDataBuffer,0x00,sizeof(ATSendDataBuffer));
|
|
|
sprintf(ATSendDataBuffer, "AT+CFTRANTX=\"c:/%s\",%d,%d\r\n", filenamePtr,currentAddr, readLenAsk);
|
|
|
UART_Query_Data(UART_LPUART1, UART_LPUART1, ATSendDataBuffer, mstrlen(ATSendDataBuffer), UartData, &ReadLen, pdMS_TO_TICKS(5000));
|
|
@@ -1553,13 +1559,41 @@ void Fota_Ftp(uint8 *dataPtrIn)
|
|
|
retptr = (uint8 *)strstr((char *)UartData, findDataBuffer);
|
|
|
if (retptr)
|
|
|
{
|
|
|
- uint8 *fileDataPtr = retptr+ 2 + mstrlen(findDataBuffer);
|
|
|
+ uint16 uartcrc = 0x00;
|
|
|
+ uint16 flashcrc = 0xff;
|
|
|
+ fileDataPtr = retptr+ 2 + mstrlen(findDataBuffer);
|
|
|
FotaRecvDataLen_8 = ((readLenAsk+7)/8)*8;
|
|
|
Hal_FlsWrite(FlashAddStart + currentAddr, fileDataPtr, FotaRecvDataLen_8, 100);
|
|
|
- //数据处理区域
|
|
|
- currentAddr = currentAddr + readLenAsk;
|
|
|
+ Hal_FlsRead(FlashAddStart + currentAddr, FlashData, FotaRecvDataLen_8, 100);
|
|
|
+ uartcrc = CRC16_Modbus(fileDataPtr,FotaRecvDataLen_8);
|
|
|
+ flashcrc = CRC16_Modbus(FlashData,FotaRecvDataLen_8);
|
|
|
+ if(flashcrc==uartcrc)
|
|
|
+ {
|
|
|
+ currentAddr = currentAddr + readLenAsk;
|
|
|
+ getDataLenErrCount = 0;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+#if SEGGER_PRINTF==1
|
|
|
+ for(uint16 i=0;i<FotaRecvDataLen_8;i++)
|
|
|
+ {
|
|
|
+ SEGGER_RTT_printf("%02X-%02X ",*(fileDataPtr+i),*(FlashData+i));
|
|
|
+ }
|
|
|
+ SEGGER_RTT_printf("\r\n[%d]flashcrc=%X,uartcrc=%X,currentAddr = %d,fileDataPtr=%X,retptr=%X\r\n",__LINE__,uartcrc,flashcrc,currentAddr,fileDataPtr,retptr);
|
|
|
+#endif
|
|
|
+ uint32 secflash = (FlashAddStart + currentAddr) & 0xFFFFF000;
|
|
|
+ if(secflash>0)
|
|
|
+ {
|
|
|
+ currentAddr = secflash - FlashAddStart;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ currentAddr = 0;
|
|
|
+ }
|
|
|
+ MemIf_JobResultType ret = Hal_FlsErase(secflash,4096, 100);
|
|
|
+ getDataLenErrCount++;
|
|
|
+ }
|
|
|
readLenAsk = min(fileLen-currentAddr,readLenAsk);
|
|
|
- getDataLenErrCount = 0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -1570,11 +1604,12 @@ void Fota_Ftp(uint8 *dataPtrIn)
|
|
|
{
|
|
|
getDataLenErrCount++;
|
|
|
}
|
|
|
- if(getDataLenErrCount>=50)
|
|
|
+ if(getDataLenErrCount>=100)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
if(getDataLenErrCount<50&&Hal_FlsCheckIsTransferSucceed()==TRUE)
|
|
|
{
|
|
|
ftp_process++;
|
|
@@ -1589,7 +1624,8 @@ void Fota_Ftp(uint8 *dataPtrIn)
|
|
|
{
|
|
|
ftp_EndFlg = 1;
|
|
|
}
|
|
|
- free(UartData);
|
|
|
+ vPortFree(UartData);
|
|
|
+ vPortFree(FlashData);
|
|
|
break;
|
|
|
}
|
|
|
case 7://delete the bin and zl files
|