1、Optimize transmission string matching rules

2、change Kconfig for mqtt and ota
This commit is contained in:
wgzAIIT 2023-09-08 12:08:16 +08:00
parent 117789121e
commit 5da9a9c4ae
3 changed files with 26 additions and 23 deletions

View File

@ -9,7 +9,7 @@ menu "lib using MQTT"
if LIB_USING_MQTT if LIB_USING_MQTT
choice choice
prompt "Choose xiuos platform or Alibaba Cloud platform." prompt "Choose xiuos platform or Alibaba Cloud platform."
default ALIBABA_PLATFORM default XIUOS_PLATFORM
config XIUOS_PLATFORM config XIUOS_PLATFORM
bool "xiuos platform." bool "xiuos platform."
@ -34,11 +34,11 @@ menu "lib using MQTT"
default "xiuosiot" default "xiuosiot"
config PLATFORM_SERVERIP config PLATFORM_SERVERIP
string "mqtt platform server ip." string "xiuos platform server ip."
default "115.238.53.59" default "115.238.53.59"
config PLATFORM_SERVERPORT config PLATFORM_SERVERPORT
string "mqtt platform server port." string "xiuos platform server port."
default "1883" default "1883"
endmenu endmenu
endif endif
@ -58,11 +58,11 @@ menu "lib using MQTT"
default "d2e613c4f714b6b0774bd7b68eeceae3" default "d2e613c4f714b6b0774bd7b68eeceae3"
config PLATFORM_SERVERIP config PLATFORM_SERVERIP
string "mqtt platform server ip." string "Alibaba Cloud platform server ip."
default "101.133.196.127" default "101.133.196.127"
config PLATFORM_SERVERPORT config PLATFORM_SERVERPORT
string "mqtt platform server port." string "Alibaba Cloud platform server port."
default "1883" default "1883"
endmenu endmenu
endif endif

View File

@ -7,7 +7,7 @@ menu "OTA function"
if TOOL_USING_OTA if TOOL_USING_OTA
choice choice
prompt "Compile bootloader bin or application bin." prompt "Compile bootloader bin or application bin."
default MCUBOOT_BOOTLOADER default MCUBOOT_APPLICATION
config MCUBOOT_BOOTLOADER config MCUBOOT_BOOTLOADER
bool "Config as bootloader." bool "Config as bootloader."

View File

@ -726,7 +726,7 @@ static void app_ota_by_4g(void)
} }
} }
mcuboot.flash_deinit(); mcuboot.flash_deinit();
KPrintf("ota file transfer complete,start reboot!\n"); KPrintf("firmware file transfer successful,start reboot!\n");
MdelayKTask(2000); MdelayKTask(2000);
mcuboot.op_reset(); mcuboot.op_reset();
} }
@ -758,6 +758,7 @@ static void PropertyVersion(void)
memset(tempdatabuff,0,128); memset(tempdatabuff,0,128);
sprintf(tempdatabuff,"{\"clientId\":\"%s\",\"version\":\"%s\"}",CLIENTID,ota_info.os.version); sprintf(tempdatabuff,"{\"clientId\":\"%s\",\"version\":\"%s\"}",CLIENTID,ota_info.os.version);
KPrintf("------current version is:%s------\r\n",ota_info.os.version);
MQTT_PublishDataQs1("xiuosiot/ota/version",tempdatabuff,strlen(tempdatabuff)); //发送等级QS=1的PUBLISH报文 MQTT_PublishDataQs1("xiuosiot/ota/version",tempdatabuff,strlen(tempdatabuff)); //发送等级QS=1的PUBLISH报文
} }
@ -794,7 +795,7 @@ static void app_ota_by_platform(void* parameter)
uint32_t heart_time = 0; uint32_t heart_time = 0;
uint32_t flashdestination = DOWN_FLAH_ADDRESS; uint32_t flashdestination = DOWN_FLAH_ADDRESS;
uint8_t topicdatabuff[2][64]; uint8_t topicdatabuff[2][64];
char *ptr; char *ptr1, *ptr2;
mcuboot.flash_init(); mcuboot.flash_init();
memset(&ota_info, 0, sizeof(ota_info_t)); memset(&ota_info, 0, sizeof(ota_info_t));
@ -829,14 +830,15 @@ reconnect:
{ {
freecnt = 0; freecnt = 0;
MQTT_DealPublishData(MqttRxbuf, datalen); MQTT_DealPublishData(MqttRxbuf, datalen);
ptr = strstr((char *)Platform_mqtt.cmdbuff,topicdatabuff[0]); ptr1 = strstr((char *)Platform_mqtt.cmdbuff,topicdatabuff[0]);
if(ptr != NULL) ptr2 = strstr((char *)Platform_mqtt.cmdbuff,"{\"fileSize\":");
if((ptr1 != NULL) &&(ptr2 != NULL))
{ {
if(sscanf(ptr+strlen(topicdatabuff[0])+1,"{\"fileSize\":%d,\"version\":\"%11s\",\"fileId\":%d,\"md5\":\"%*32s\"}",&platform_ota.size,platform_ota.version,&platform_ota.streamId)==3) if(sscanf(ptr2,"{\"fileSize\":%d,\"version\":\"%11s\",\"fileId\":%d,\"md5\"",&platform_ota.size,platform_ota.version,&platform_ota.streamId)==3)
{ {
KPrintf("ota file size:%d\r\n",platform_ota.size); KPrintf("------Start the firmware file transfer!------\r\n");
KPrintf("ota file id:%d\r\n",platform_ota.streamId); KPrintf("file size:%d,file id:%d,file version:%s\r\n",platform_ota.size,platform_ota.streamId,platform_ota.version);
KPrintf("ota file version:%s\r\n",platform_ota.version); KPrintf("---------------------------------------------\r\n");
if(mcuboot.op_flash_erase(DOWN_FLAH_ADDRESS,platform_ota.size) != kStatus_Success) if(mcuboot.op_flash_erase(DOWN_FLAH_ADDRESS,platform_ota.size) != kStatus_Success)
{ {
KPrintf("Failed to erase target fash!\n"); KPrintf("Failed to erase target fash!\n");
@ -877,7 +879,7 @@ reconnect:
else else
{ {
KPrintf("current frame[%d] is written to flash 0x%x address successful.\n", platform_ota.num -1, flashdestination); KPrintf("current frame[%d] is written to flash 0x%x address successful.\n", platform_ota.num -1, flashdestination);
KPrintf("Current progress is %d/%d\r\n",platform_ota.num,platform_ota.counter); KPrintf("current progress is %d/%d.\r\n",platform_ota.num,platform_ota.counter);
flashdestination += platform_ota.downlen; flashdestination += platform_ota.downlen;
platform_ota.num++; platform_ota.num++;
} }
@ -946,11 +948,11 @@ reconnect:
strncpy(ota_info.error_message, "No error message!",sizeof(ota_info.error_message)); strncpy(ota_info.error_message, "No error message!",sizeof(ota_info.error_message));
UpdateOTAFlag(&ota_info); UpdateOTAFlag(&ota_info);
KPrintf("ota file transfer complete,start reboot!\n"); KPrintf("firmware file transfer successful,start reboot!\n");
} }
else else
{ {
KPrintf("ota file transfer failed,start reboot!\n"); KPrintf("firmware file transfer failed,start reboot!\n");
} }
MQTT_UnSubscribeTopic(topicdatabuff[0]); MQTT_UnSubscribeTopic(topicdatabuff[0]);
MQTT_UnSubscribeTopic(topicdatabuff[1]); MQTT_UnSubscribeTopic(topicdatabuff[1]);
@ -982,6 +984,7 @@ static void PropertyVersion(void)
memset(tempdatabuff,0,128); memset(tempdatabuff,0,128);
sprintf(tempdatabuff,"{\"id\": \"1\",\"params\": {\"version\": \"%s\"}}",ota_info.os.version); sprintf(tempdatabuff,"{\"id\": \"1\",\"params\": {\"version\": \"%s\"}}",ota_info.os.version);
KPrintf("------current version is:%s------\r\n",ota_info.os.version);
MQTT_PublishDataQs1(topicdatabuff,tempdatabuff,strlen(tempdatabuff)); //发送等级QS=1的PUBLISH报文 MQTT_PublishDataQs1(topicdatabuff,tempdatabuff,strlen(tempdatabuff)); //发送等级QS=1的PUBLISH报文
} }
@ -1061,9 +1064,9 @@ reconnect:
{ {
if(sscanf(ptr,"{\"code\":\"1000\",\"data\":{\"size\":%d,\"streamId\":%d,\"sign\":\"%*32s\",\"dProtocol\":\"mqtt\",\"version\":\"%11s\"",&platform_ota.size,&platform_ota.streamId,platform_ota.version)==3) if(sscanf(ptr,"{\"code\":\"1000\",\"data\":{\"size\":%d,\"streamId\":%d,\"sign\":\"%*32s\",\"dProtocol\":\"mqtt\",\"version\":\"%11s\"",&platform_ota.size,&platform_ota.streamId,platform_ota.version)==3)
{ {
KPrintf("ota file size:%d\r\n",platform_ota.size); KPrintf("------Start the firmware file transfer!------\r\n");
KPrintf("ota file id:%d\r\n",platform_ota.streamId); KPrintf("file size:%d,file id:%d,file version:%s\r\n",platform_ota.size,platform_ota.streamId,platform_ota.version);
KPrintf("ota file version:%s\r\n",platform_ota.version); KPrintf("---------------------------------------------\r\n");
if(mcuboot.op_flash_erase(DOWN_FLAH_ADDRESS,platform_ota.size) != kStatus_Success) if(mcuboot.op_flash_erase(DOWN_FLAH_ADDRESS,platform_ota.size) != kStatus_Success)
{ {
KPrintf("Failed to erase target fash!\n"); KPrintf("Failed to erase target fash!\n");
@ -1104,7 +1107,7 @@ reconnect:
else else
{ {
KPrintf("current frame[%d] is written to flash 0x%x address successful.\n", platform_ota.num -1, flashdestination); KPrintf("current frame[%d] is written to flash 0x%x address successful.\n", platform_ota.num -1, flashdestination);
KPrintf("Current progress is %d/%d\r\n",platform_ota.num,platform_ota.counter); KPrintf("current progress is %d/%d.\r\n",platform_ota.num,platform_ota.counter);
flashdestination += platform_ota.downlen; flashdestination += platform_ota.downlen;
platform_ota.num++; platform_ota.num++;
} }
@ -1173,11 +1176,11 @@ reconnect:
strncpy(ota_info.error_message, "No error message!",sizeof(ota_info.error_message)); strncpy(ota_info.error_message, "No error message!",sizeof(ota_info.error_message));
UpdateOTAFlag(&ota_info); UpdateOTAFlag(&ota_info);
KPrintf("ota file transfer complete,start reboot!\n"); KPrintf("firmware file transfer successful,start reboot!\n");
} }
else else
{ {
KPrintf("ota file transfer failed,start reboot!\n"); KPrintf("firmware file transfer failed,start reboot!\n");
} }
MQTT_UnSubscribeTopic(topicdatabuff); MQTT_UnSubscribeTopic(topicdatabuff);
MQTT_Disconnect(); MQTT_Disconnect();