forked from xuos/xiuos
				
			OTA prints prompt message when upgrade is not required
This commit is contained in:
		
							parent
							
								
									aa3e6c9370
								
							
						
					
					
						commit
						c2abf66f23
					
				|  | @ -29,7 +29,7 @@ | ||||||
| #define REPLY_TIME_OUT 10 | #define REPLY_TIME_OUT 10 | ||||||
| 
 | 
 | ||||||
| #ifdef TOOL_USING_OTA | #ifdef TOOL_USING_OTA | ||||||
| #define ENTM_RECV_MAX (OTA_FRAME_SIZE + 512) | #define ENTM_RECV_MAX (OTA_FRAME_SIZE + 1024) | ||||||
| #else | #else | ||||||
| #define ENTM_RECV_MAX 256 | #define ENTM_RECV_MAX 256 | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | @ -421,13 +421,13 @@ bool MQTT_SendHeart(void) | ||||||
| /*******************************************************************************
 | /*******************************************************************************
 | ||||||
| * 函 数 名: MQTT_DealPublishData | * 函 数 名: MQTT_DealPublishData | ||||||
| * 功能描述: 处理服务器发来的等级0的推送数据,附带topic信息 | * 功能描述: 处理服务器发来的等级0的推送数据,附带topic信息 | ||||||
| * 形    参: redata:接收的数据,data_len:要处理的数据长度 | * 形    参: data:接收的数据,data_len:要处理的数据长度 | ||||||
| * 返 回 值: 报文中主题部分+实际负载的长度 | * 返 回 值: 报文中主题部分+实际负载的长度 | ||||||
| *******************************************************************************/ | *******************************************************************************/ | ||||||
| uint16_t MQTT_DealPublishData(uint8_t *data, uint16_t data_len) | uint16_t MQTT_DealPublishData(uint8_t *data, uint16_t data_len) | ||||||
| { | { | ||||||
|     uint8_t i; |     uint8_t i; | ||||||
|     uint16_t cmdpos,cmdlen; |     uint16_t startPos,payloadLen; | ||||||
| 
 | 
 | ||||||
|     for(i = 1;i < 5;i++) |     for(i = 1;i < 5;i++) | ||||||
|     { |     { | ||||||
|  | @ -436,16 +436,16 @@ uint16_t MQTT_DealPublishData(uint8_t *data, uint16_t data_len) | ||||||
|             break; |             break; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     //1代表固定报头占一个字节,i代表可变报头长度字段所占用字节数,2代表主题长度字段占2字节,cmdpos代表报文里主题名称起始位置
 |     //1代表固定报头占一个字节,i代表可变报头长度字段所占用字节数,2代表主题长度字段占2字节,startPos代表报文里主题名称起始位置
 | ||||||
|     cmdpos = 1+i+2; |     startPos = 1+i+2; | ||||||
|     //data_len减去1+i+2就是报文中主题部分+实际负载的长度
 |     //data_len减去1+i+2就是报文中主题部分+实际负载的长度
 | ||||||
|     cmdlen = data_len-(1+i+2); |     payloadLen = data_len-(1+i+2); | ||||||
| 
 | 
 | ||||||
|     if(data_len <= CMD_SIZE) |     if(data_len <= CMD_SIZE) | ||||||
|     { |     { | ||||||
|         memset(Platform_mqtt.cmdbuff, 0, CMD_SIZE); |         memset(Platform_mqtt.cmdbuff, 0, CMD_SIZE); | ||||||
|         memcpy(Platform_mqtt.cmdbuff, &data[cmdpos], cmdlen); |         memcpy(Platform_mqtt.cmdbuff, &data[startPos], payloadLen); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     return cmdlen; |     return payloadLen; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -28,8 +28,8 @@ | ||||||
| #define  KEEPALIVE_TIME               300   //保活时间(单位s),300s
 | #define  KEEPALIVE_TIME               300   //保活时间(单位s),300s
 | ||||||
| #define  HEART_TIME                200000   //空闲时发送心跳包的时间间隔(单位ms),200s
 | #define  HEART_TIME                200000   //空闲时发送心跳包的时间间隔(单位ms),200s
 | ||||||
| #define  PACK_SIZE                    512   //存放报文数据缓冲区大小
 | #define  PACK_SIZE                    512   //存放报文数据缓冲区大小
 | ||||||
| #define  MQTT_FRAME_SIZE             3072   //保存推送的PUBLISH报文中的数据负载大小,最大3k
 | #define  MQTT_FRAME_SIZE             2048   //保存推送的PUBLISH报文中的数据负载大小,最大2k
 | ||||||
| #define  CMD_SIZE (MQTT_FRAME_SIZE + 512)   //保存推送的PUBLISH报文中的数据缓冲区大小
 | #define  CMD_SIZE (MQTT_FRAME_SIZE + 1024)  //保存推送的PUBLISH报文中的数据缓冲区大小
 | ||||||
| #define  CLIENTID_SIZE                 64   //存放客户端ID的缓冲区大小
 | #define  CLIENTID_SIZE                 64   //存放客户端ID的缓冲区大小
 | ||||||
| #define  USERNAME_SIZE                 64   //存放用户名的缓冲区大小
 | #define  USERNAME_SIZE                 64   //存放用户名的缓冲区大小
 | ||||||
| #define  PASSWARD_SIZE                 64   //存放密码的缓冲区大小
 | #define  PASSWARD_SIZE                 64   //存放密码的缓冲区大小
 | ||||||
|  |  | ||||||
|  | @ -67,9 +67,9 @@ menu "OTA function" | ||||||
|          |          | ||||||
|         config OTA_FRAME_SIZE |         config OTA_FRAME_SIZE | ||||||
|             int "OTA receive data frame size." |             int "OTA receive data frame size." | ||||||
|             default 3072 if OTA_BY_PLATFORM |             default 2048 if OTA_BY_PLATFORM | ||||||
|             default 1024 if OTA_BY_TCPSERVER |             default 1024 if OTA_BY_TCPSERVER | ||||||
|             default 256 if MCUBOOT_BOOTLOADER |             default 0 if MCUBOOT_BOOTLOADER | ||||||
|     endif |     endif | ||||||
| 
 | 
 | ||||||
| endmenu | endmenu | ||||||
|  |  | ||||||
|  | @ -401,6 +401,13 @@ static bool UpdateNewApplication(void) | ||||||
|     } |     } | ||||||
|     else |     else | ||||||
|     { |     { | ||||||
|  |         // 如果OTA升级状态为准备状态但APP分区与download分区版本相同,不需要进行升级,重置status,打印提示信息
 | ||||||
|  |         if((ota_info.status == OTA_STATUS_READY) && (ota_info.os.crc32 == ota_info.down.crc32))  | ||||||
|  |         { | ||||||
|  |             ota_info.status == OTA_STATUS_IDLE; | ||||||
|  |             UpdateOTAFlag(&ota_info); | ||||||
|  |             mcuboot.print_string("\r\n------The app partition is the same as the download partition, no need to upgrade!------\r\n"); | ||||||
|  |         } | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
| finish: | finish: | ||||||
|  | @ -801,7 +808,7 @@ SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHE | ||||||
| #else | #else | ||||||
|     #error "The value of FRAME_LEN should not be greater than MQTT_FRAME_SIZE!!" |     #error "The value of FRAME_LEN should not be greater than MQTT_FRAME_SIZE!!" | ||||||
| #endif | #endif | ||||||
| static uint8_t MqttRxbuf[FRAME_LEN + 512]; | static uint8_t MqttRxbuf[FRAME_LEN + 1024]; | ||||||
| static uint8_t FrameBuf[FRAME_LEN]; | static uint8_t FrameBuf[FRAME_LEN]; | ||||||
| static OTA_TCB platform_ota; | static OTA_TCB platform_ota; | ||||||
| 
 | 
 | ||||||
|  | @ -828,12 +835,12 @@ static void PropertyVersion(void) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| /*-------------------------------------------------*/ | /*******************************************************************************
 | ||||||
| /*函数名:OTA下载数据                              */ | * 函 数 名: OTA_Download | ||||||
| /*参  数:size:本次下载量                         */ | * 功能描述: OTA下载数据 | ||||||
| /*参  数:offset:本次下载偏移量                   */ | * 形    参: size:本次下载量,offset:本次下载偏移量 | ||||||
| /*返回值:无                                       */ | * 返 回 值: 无 | ||||||
| /*-------------------------------------------------*/ | *******************************************************************************/ | ||||||
| static void OTA_Download(int size, int offset) | static void OTA_Download(int size, int offset) | ||||||
| { | { | ||||||
|     uint8_t tempdatabuff[128]; |     uint8_t tempdatabuff[128]; | ||||||
|  | @ -860,7 +867,7 @@ static void mqttCloudInteraction(void* parameter) | ||||||
|     uint32_t flashdestination = DOWN_FLAH_ADDRESS; |     uint32_t flashdestination = DOWN_FLAH_ADDRESS; | ||||||
|     uint8_t topicdatabuff[2][32]; |     uint8_t topicdatabuff[2][32]; | ||||||
|     char *ptr1, *ptr2; |     char *ptr1, *ptr2; | ||||||
|     uint16_t cmdlen; |     uint16_t payloadLen; | ||||||
| 
 | 
 | ||||||
|     mcuboot.flash_init(); |     mcuboot.flash_init(); | ||||||
|     memset(&ota_info, 0, sizeof(ota_info_t)); |     memset(&ota_info, 0, sizeof(ota_info_t)); | ||||||
|  | @ -916,7 +923,7 @@ reconnect: | ||||||
|         else if(MqttRxbuf[0] == 0x30) |         else if(MqttRxbuf[0] == 0x30) | ||||||
|         { |         { | ||||||
|             freecnt = 0; |             freecnt = 0; | ||||||
|             cmdlen = MQTT_DealPublishData(MqttRxbuf, datalen); |             payloadLen = MQTT_DealPublishData(MqttRxbuf, datalen); | ||||||
| 
 | 
 | ||||||
|             // 1.获取新版本固件大小及版本信息
 |             // 1.获取新版本固件大小及版本信息
 | ||||||
|             ptr1 = strstr((char *)Platform_mqtt.cmdbuff,topicdatabuff[0]);  |             ptr1 = strstr((char *)Platform_mqtt.cmdbuff,topicdatabuff[0]);  | ||||||
|  | @ -1021,7 +1028,7 @@ reconnect: | ||||||
|                 KPrintf("------Start download joson file !------\r\n"); |                 KPrintf("------Start download joson file !------\r\n"); | ||||||
|                 memset(jsonfilename,0,sizeof(jsonfilename)); |                 memset(jsonfilename,0,sizeof(jsonfilename)); | ||||||
|                 memset(FrameBuf,0,sizeof(FrameBuf)); |                 memset(FrameBuf,0,sizeof(FrameBuf)); | ||||||
|                 memcpy(FrameBuf, &Platform_mqtt.cmdbuff[strlen(jsontopicdatabuff)],cmdlen-strlen(jsontopicdatabuff));  |                 memcpy(FrameBuf, &Platform_mqtt.cmdbuff[strlen(jsontopicdatabuff)],payloadLen-strlen(jsontopicdatabuff));  | ||||||
|                  |                  | ||||||
|                 cJSON *json_obj = cJSON_Parse(FrameBuf); |                 cJSON *json_obj = cJSON_Parse(FrameBuf); | ||||||
|                 char* product_name = cJSON_GetObjectItem(json_obj, "productName")->valuestring; |                 char* product_name = cJSON_GetObjectItem(json_obj, "productName")->valuestring; | ||||||
|  | @ -1113,12 +1120,12 @@ static void PropertyVersion(void) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| /*-------------------------------------------------*/ | /*******************************************************************************
 | ||||||
| /*函数名:OTA下载数据                              */ | * 函 数 名: OTA_Download | ||||||
| /*参  数:size:本次下载量                         */ | * 功能描述: OTA下载数据 | ||||||
| /*参  数:offset:本次下载偏移量                   */ | * 形    参: size:本次下载量,offset:本次下载偏移量 | ||||||
| /*返回值:无                                       */ | * 返 回 值: 无 | ||||||
| /*-------------------------------------------------*/ | *******************************************************************************/ | ||||||
| static void OTA_Download(int size, int offset) | static void OTA_Download(int size, int offset) | ||||||
| { | { | ||||||
|     uint8_t topicdatabuff[64]; |     uint8_t topicdatabuff[64]; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue