|
@@ -721,7 +721,7 @@ void TcpDataEncode(uint32 *PtrSendAddr, uint16 *SendLen)
|
|
|
static uint32 TcpSendTimeCounter = 0;
|
|
|
TcpSendTimeCounter++;
|
|
|
|
|
|
- if (TcpSendTimeCounter == 1)
|
|
|
+ if (TcpSendTimeCounter%60 == 0)
|
|
|
{
|
|
|
DataIdx = VerMsg; //版本信息发送
|
|
|
}
|
|
@@ -1418,9 +1418,46 @@ void Fota_Ftp(void)
|
|
|
uint8 ftp_ErrCnt = 0;
|
|
|
char *ATCmdSend = NULL;
|
|
|
uint8 ATCmdSendLen = 0;
|
|
|
+ char ATSendDataBuffer[100] = {0};
|
|
|
uint8 *UartRecvPtr = NULL;
|
|
|
uint16 ReadLen = 0;
|
|
|
uint8 *retptr = NULL;
|
|
|
+ char temp[70]=",qx,qx900,120.27.243.131,21,0,0.0.1.5,0.0.1.5,/Debug/V0.0.1.5.bin,";
|
|
|
+ /*URL信息解析*/
|
|
|
+ char *databuffer[20];
|
|
|
+ char *accountPtr;
|
|
|
+ char *passwordPtr;
|
|
|
+ char *ftpServerIpPtr;
|
|
|
+ char *ftpServerPort;
|
|
|
+ char *filePathPtr;
|
|
|
+ char *filenamePtr;
|
|
|
+ char keyFilename[20]={0};
|
|
|
+ char *p = NULL;
|
|
|
+ p = strtok(temp, ",");
|
|
|
+ uint8 index = 0;
|
|
|
+ while (p)
|
|
|
+ {
|
|
|
+ databuffer[index] = p;
|
|
|
+ p = strtok(NULL, ",");
|
|
|
+ index++;
|
|
|
+ }
|
|
|
+ accountPtr = databuffer[0];
|
|
|
+ passwordPtr = databuffer[1];
|
|
|
+ ftpServerIpPtr = databuffer[2];
|
|
|
+ ftpServerPort = databuffer[3];
|
|
|
+ filePathPtr = databuffer[7];
|
|
|
+ for(sint8 i=strlen(filePathPtr);i--;i<0)
|
|
|
+ {
|
|
|
+ if(*(filePathPtr+i)=='/')
|
|
|
+ {
|
|
|
+ *(filePathPtr+i) = 0;
|
|
|
+ filenamePtr = filePathPtr+i+1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ memcpy(keyFilename,filenamePtr,mstrlen(filenamePtr)-3);
|
|
|
+ memcpy(&keyFilename[mstrlen(filenamePtr)-3],"zl",strlen("zl"));
|
|
|
while(!ftp_EndFlg)
|
|
|
{
|
|
|
vTaskDelay(pdMS_TO_TICKS(100));
|
|
@@ -1458,8 +1495,8 @@ void Fota_Ftp(void)
|
|
|
case 1://login
|
|
|
{
|
|
|
uint8 *UartData = NULL;
|
|
|
- ATCmdSend = (char *)("AT+CFTPSLOGIN=\"nas.fast-fun.cn\",21,\"qx\",\"qx900\",0\r\n");
|
|
|
- UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, mstrlen(ATCmdSend), &UartRecvPtr, &ReadLen, pdMS_TO_TICKS(1000));
|
|
|
+ sprintf(ATSendDataBuffer, "AT+CFTPSLOGIN=\"%s\",%s,\"%s\",\"%s\",0\r\n", ftpServerIpPtr, ftpServerPort,accountPtr,passwordPtr);
|
|
|
+ UART_Query_Data(UART_LPUART1, UART_LPUART1, ATSendDataBuffer, mstrlen(ATSendDataBuffer), &UartRecvPtr, &ReadLen, pdMS_TO_TICKS(1000));
|
|
|
while (1)
|
|
|
{
|
|
|
UART_Receive_Data(UART_LPUART1,&UartData, &ReadLen,10000);
|
|
@@ -1474,11 +1511,42 @@ void Fota_Ftp(void)
|
|
|
{
|
|
|
ftp_ErrCnt++;
|
|
|
}
|
|
|
+ if(UartData != NULL)
|
|
|
+ {
|
|
|
+ free(UartData);
|
|
|
+ }
|
|
|
+ UartData = NULL;
|
|
|
+ }
|
|
|
+ if(UartRecvPtr != NULL)
|
|
|
+ {
|
|
|
+ free(UartRecvPtr);
|
|
|
+ }
|
|
|
+ UartRecvPtr = NULL;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 2://transmit bin file from server to module
|
|
|
+ {
|
|
|
+ uint8 *UartData = NULL;
|
|
|
+ sprintf(ATSendDataBuffer, "AT+CFTPSGETFILE=\"%s/%s\"\r\n", filePathPtr,filenamePtr);
|
|
|
+ UART_Query_Data(UART_LPUART1, UART_LPUART1, ATSendDataBuffer, mstrlen(ATSendDataBuffer), &UartRecvPtr, &ReadLen, pdMS_TO_TICKS(1000));
|
|
|
+ while (1)
|
|
|
+ {
|
|
|
+ UART_Receive_Data(UART_LPUART1,&UartData, &ReadLen,10000);
|
|
|
+ retptr = (uint8 *)strstr((char *)UartData, (char *)("+CFTPSGETFILE: 0"));
|
|
|
+ if (retptr)
|
|
|
+ {
|
|
|
+ ftp_ErrCnt = 0;
|
|
|
+ ftp_process++;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ftp_ErrCnt++;
|
|
|
+ }
|
|
|
if(ftp_ErrCnt>5)
|
|
|
{
|
|
|
ftp_ErrCnt = 0;
|
|
|
- ftp_process = 0;
|
|
|
- ftp_EndFlg = 1;
|
|
|
+ ftp_process++;
|
|
|
break;
|
|
|
}
|
|
|
if(UartData != NULL)
|
|
@@ -1494,11 +1562,11 @@ void Fota_Ftp(void)
|
|
|
UartRecvPtr = NULL;
|
|
|
break;
|
|
|
}
|
|
|
- case 2://transmit server to module
|
|
|
+ case 3://transmit zl file from server to module
|
|
|
{
|
|
|
uint8 *UartData = NULL;
|
|
|
- ATCmdSend = (char *)("AT+CFTPSGETFILE=\"V0.0.1.5.bin\"\r\n");
|
|
|
- UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, mstrlen(ATCmdSend), &UartRecvPtr, &ReadLen, pdMS_TO_TICKS(1000));
|
|
|
+ sprintf(ATSendDataBuffer, "AT+CFTPSGETFILE=\"%s/%s\"\r\n", filePathPtr,keyFilename);
|
|
|
+ UART_Query_Data(UART_LPUART1, UART_LPUART1, ATSendDataBuffer, mstrlen(ATSendDataBuffer), &UartRecvPtr, &ReadLen, pdMS_TO_TICKS(1000));
|
|
|
while (1)
|
|
|
{
|
|
|
UART_Receive_Data(UART_LPUART1,&UartData, &ReadLen,10000);
|
|
@@ -1532,39 +1600,17 @@ void Fota_Ftp(void)
|
|
|
UartRecvPtr = NULL;
|
|
|
break;
|
|
|
}
|
|
|
- case 3://get data from module
|
|
|
+ case 4://logout
|
|
|
{
|
|
|
- uint8 *UartData = NULL;
|
|
|
- uint32 currentAddr = 0;
|
|
|
- uint16 readLen = 128;
|
|
|
- uint32 fileLen = 65535;
|
|
|
- ATCmdSend = (char *)("AT+FSATTRI=V0.0.1.5.bin\r\n");
|
|
|
+ ATCmdSend = (char *)("AT+CFTPSLOGOUT\r\n");
|
|
|
UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, mstrlen(ATCmdSend), &UartRecvPtr, &ReadLen, pdMS_TO_TICKS(100));
|
|
|
if (ReadLen > 0)
|
|
|
{
|
|
|
retptr = (uint8 *)strstr((char *)UartRecvPtr, (char *)("OK"));
|
|
|
if (retptr)
|
|
|
{
|
|
|
- while(readLen!=0)
|
|
|
- {
|
|
|
- sprintf(ATCmdSend, "AT+CFTRANTX=\"c:/V0.0.1.5.bin\",%d,%d\r\n\r\n", currentAddr, readLen);
|
|
|
- UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, mstrlen(ATCmdSend), &UartData, &ReadLen, pdMS_TO_TICKS(100));
|
|
|
- if (ReadLen > 0)
|
|
|
- {
|
|
|
- retptr = (uint8 *)strstr((char *)UartData, (char *)("+CFTRANTX: DATA"));
|
|
|
- if (retptr)
|
|
|
- {
|
|
|
- //数据处理区域
|
|
|
- currentAddr = currentAddr + readLen;
|
|
|
- readLen = min(fileLen-currentAddr,readLen);
|
|
|
- }
|
|
|
- }
|
|
|
- if(UartData != NULL)
|
|
|
- {
|
|
|
- free(UartData);
|
|
|
- }
|
|
|
- UartData = NULL;
|
|
|
- }
|
|
|
+ ftp_process++;
|
|
|
+ ftp_ErrCnt = 0;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
@@ -1578,9 +1624,9 @@ void Fota_Ftp(void)
|
|
|
UartRecvPtr = NULL;
|
|
|
break;
|
|
|
}
|
|
|
- case 4://logout
|
|
|
+ case 5://stop
|
|
|
{
|
|
|
- ATCmdSend = (char *)("AT+CFTPSLOGOUT\r\n");
|
|
|
+ ATCmdSend = (char *)("AT+CFTPSSTOP\r\n");
|
|
|
UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, mstrlen(ATCmdSend), &UartRecvPtr, &ReadLen, pdMS_TO_TICKS(100));
|
|
|
if (ReadLen > 0)
|
|
|
{
|
|
@@ -1588,7 +1634,6 @@ void Fota_Ftp(void)
|
|
|
if (retptr)
|
|
|
{
|
|
|
ftp_process++;
|
|
|
- ftp_ErrCnt = 0;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
@@ -1602,16 +1647,64 @@ void Fota_Ftp(void)
|
|
|
UartRecvPtr = NULL;
|
|
|
break;
|
|
|
}
|
|
|
- case 5://stop
|
|
|
+ case 6://get data from module
|
|
|
{
|
|
|
- ATCmdSend = (char *)("AT+CFTPSSTOP\r\n");
|
|
|
- UART_Query_Data(UART_LPUART1, UART_LPUART1, ATCmdSend, mstrlen(ATCmdSend), &UartRecvPtr, &ReadLen, pdMS_TO_TICKS(100));
|
|
|
- if (ReadLen > 0)
|
|
|
- {
|
|
|
- retptr = (uint8 *)strstr((char *)UartRecvPtr, (char *)("OK"));
|
|
|
+ char findDataBuffer[25] = {0};
|
|
|
+ uint8 *UartData = NULL;
|
|
|
+ uint32 currentAddr = 0;
|
|
|
+ uint16 readLenAsk = 256;
|
|
|
+ uint16 FotaRecvDataLen_8 = 0;
|
|
|
+ uint32 fileLen = 65535;
|
|
|
+ uint32 FlashAddStart = 0;
|
|
|
+ uint32 appReceviedCRC;
|
|
|
+ uint16 getDataLenErrCount = 0;
|
|
|
+ sprintf(ATSendDataBuffer, "AT+CFTRANTX=\"c:/%s\",0,6\r\n\r\n",keyFilename);
|
|
|
+ UART_Query_Data(UART_LPUART1, UART_LPUART1, ATSendDataBuffer, mstrlen(ATSendDataBuffer), &UartData, &ReadLen, pdMS_TO_TICKS(5000));
|
|
|
+ if (ReadLen == (6+45))
|
|
|
+ {
|
|
|
+ retptr = (uint8 *)strstr((char *)UartRecvPtr, (char *)("+CFTRANTX: DATA"));
|
|
|
if (retptr)
|
|
|
{
|
|
|
- ftp_process++;
|
|
|
+ fileLen = (*(retptr+22)<<24)|(*(retptr+23)<<16)|(*(retptr+24)<<8)|(*(retptr+25)<<0);
|
|
|
+ appReceviedCRC = (*(retptr+20)<<8)|(*(retptr+21)<<0);
|
|
|
+ Hal_FlsGetAppVectorTableStartAddr(&FlashAddStart);
|
|
|
+ Hal_FlsErase(FlashAddStart,fileLen + FLS_INTERNAL_WRITE_SIZE, 50);
|
|
|
+ Hal_SetAppInfo(fileLen, appReceviedCRC, CONTROLLER_SELF);
|
|
|
+ while(readLenAsk!=0)
|
|
|
+ {
|
|
|
+ sprintf(ATSendDataBuffer, "AT+CFTRANTX=\"c:/%s\",%d,%d\r\n\r\n", filenamePtr,currentAddr, readLenAsk);
|
|
|
+ UART_Query_Data(UART_LPUART1, UART_LPUART1, ATSendDataBuffer, mstrlen(ATSendDataBuffer), &UartData, &ReadLen, pdMS_TO_TICKS(5000));
|
|
|
+ sprintf(findDataBuffer, "+CFTRANTX: DATA,%d", readLenAsk);
|
|
|
+ if (ReadLen == (readLenAsk+45))
|
|
|
+ {
|
|
|
+ retptr = (uint8 *)strstr((char *)UartData, findDataBuffer);
|
|
|
+ if (retptr)
|
|
|
+ {
|
|
|
+ uint8 *fileDataPtr = retptr+ 2 + mstrlen(findDataBuffer);
|
|
|
+ FotaRecvDataLen_8 = ((readLenAsk+7)/8)*8;
|
|
|
+ Hal_FlsWrite(FlashAddStart + currentAddr, fileDataPtr, FotaRecvDataLen_8, 100);
|
|
|
+ //数据处理区域
|
|
|
+ currentAddr = currentAddr + readLenAsk;
|
|
|
+ readLenAsk = min(fileLen-currentAddr,readLenAsk);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ getDataLenErrCount++;
|
|
|
+ }
|
|
|
+ if(UartData != NULL)
|
|
|
+ {
|
|
|
+ free(UartData);
|
|
|
+ }
|
|
|
+ UartData = NULL;
|
|
|
+ if(getDataLenErrCount>=500)
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(getDataLenErrCount<500&&Hal_FlsCheckIsTransferSucceed()==TRUE){
|
|
|
+ Fota_update_flag = TRUE;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
else
|