From: hcj <1224667075@qq.com> Date: Tue, 23 Apr 2024 10:13:46 +0000 (+0800) Subject: 升级包下载,及升级结果上报 X-Git-Tag: release_V1.2.70_20241020_135402~1137^2~2 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=0dd16337099029a0a380b5cd33544d72dd814955;p=mirrors%2FFD230.git 升级包下载,及升级结果上报 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/include/Systemupgrade.h b/code/sdk/application/wearable/fd230app/nativeui/system/include/Systemupgrade.h index 9cfc72d8c..6901e3433 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/include/Systemupgrade.h +++ b/code/sdk/application/wearable/fd230app/nativeui/system/include/Systemupgrade.h @@ -20,10 +20,10 @@ namespace OHOS IOT_CODE_SUCCESS=20007,//有新版本,唯一成功id,不是这个都表示没有升级版本data为NULL IOT_CODE_FAIL_1=50000,//设备源版本不能为空 IOT_CODE_FAIL_2=50012,//设备未注册 - SAMPLE_RATE_MAX } iot_code; - + void upgrade_reported_data(void); + class SystemupgradeView { diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/Systemupgrade.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/Systemupgrade.cpp index 857f20702..a33224958 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/Systemupgrade.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/Systemupgrade.cpp @@ -27,6 +27,9 @@ #define UPDATAFWPKGPATH "/update/update.fwpkg" +#define POST_URL "http://test.iot.api.thisiot.com/ota/update-result" +#define JSON_URL "http://test.iot.api.thisiot.com/ota/task?deviceId=%s&sourceVersion=%s" + //https://test.app.api.thisiot.com/ota/task?deviceId=deviceId&sourceVersion=sourceVersion //http://test.iot.api.thisiot.com/ota/task?deviceId=deviceId&sourceVersion=sourceVersion @@ -47,9 +50,61 @@ namespace OHOS static char *Path_ota_package= UPDATAFWPKGPATH; static uint8_t uri_ota_package[256] ={0}; + static const char *imei_str=NULL; + static char *report_jsonString=NULL; + + static err_t httpc_download_headers_done_ui(httpc_state_t *connection, void *arg, struct pbuf *hdr, u16_t hdr_len, u32_t content_len) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "httpc_download_headers_done_ui"); + return 0; + } + + static void httpc_download_result_report_data(void *arg, httpc_result_t httpc_result, u32_t rx_content_len, u32_t srv_res, err_t err) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "httpc_download_result_ui"); + PRINT("httpc_download_result , httpc_result_t %d, rx_content_len %d , srv_res %d, err %d\n", + httpc_result,rx_content_len,srv_res,err); + return ; + } + + // // httpc_get_file( + // const ip_addr_t* server_addr, + // u16_t port, + // const char* uri, + // const httpc_connection_t *settings, + // // // altcp_recv_fn recv_fn, + // void* callback_arg, httpc_state_t **connection) + + static void report_data_by_get_file(char *data,u16_t data_len) + { + settings.use_proxy=0; + + settings.use_post=1; + settings.args=(u8_t*)data; + settings.arglen=data_len; + uint8_t *otadatapath =(uint8_t *)"/update/ota_report_.json"; + + settings.result_fn=httpc_download_result_report_data; + + settings.headers_done_fn=httpc_download_headers_done_ui; + + httpc_state_t* connection=NULL; + err_t rett= httpc_get_file_dns_to_disk( + HTTP_JSON_SERVER_NAME, + PORT, + POST_URL, + &settings, + NULL, + (const char*) otadatapath, + &connection); + PRINT("custom_start_ota_download %d \r\n",rett); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "use_post_"); + + } void upgrade_reported_data(void) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, ""); FILE * fp = fopen(UPDATAREPORT,"rb+"); if(fp==NULL) { @@ -80,13 +135,43 @@ namespace OHOS if(data!=NULL) { char *targetVersion=cJSON_GetObjectItem(data, "targetVersion")->valuestring; + char *taskId=cJSON_GetObjectItem(data, "updateId")->valuestring; char version_buf[128]={0}; uint32_t version_len=128; uapi_get_buildversion((uint8_t*)version_buf,version_len); - if(strcmp(targetVersion,version_buf)==0) - { + // if(strcmp(targetVersion,version_buf)==0) + // { //HTTP_send_data - } + cJSON* dataJSON=cJSON_CreateObject(); + imei_str= const_cast(ConfigModel::GetInstance()->Getimei().c_str()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s",imei_str); + + cJSON_AddStringToObject(dataJSON,"deviceId",imei_str); + + cJSON_AddStringToObject(dataJSON,"companyId",""); + + cJSON_AddStringToObject(dataJSON,"createTime",""); + + cJSON_AddStringToObject(dataJSON,"id",""); + if(strcmp(targetVersion,version_buf)==0) + { + cJSON_AddStringToObject(dataJSON,"result","1"); + } + else + { + cJSON_AddStringToObject(dataJSON,"result","0"); + } + cJSON_AddStringToObject(dataJSON,"taskId",taskId); + cJSON_AddStringToObject(dataJSON,"updateTime",""); + buf = cJSON_PrintUnformatted(dataJSON); + cJSON_Delete(dataJSON); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s",buf); + u16_t buf_len=strlen(buf); + report_data_by_get_file(buf,buf_len); + + remove(UPDATAREPORT); + + // } } cJSON_Delete(data); } @@ -166,12 +251,8 @@ namespace OHOS cJSON *data=cJSON_GetObjectItem(root, "data"); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, ""); - char *jsonString = cJSON_PrintUnformatted(data); - uint32_t data_len=strlen(jsonString); - FILE *FP_= fopen(UPDATAREPORT,"w+"); - fwrite(jsonString,1,data_len,FP_); - fclose(FP_); - printf("data%d %s\r\n",data_len,jsonString); + report_jsonString = cJSON_PrintUnformatted(data); + if(data!=NULL) { @@ -313,12 +394,7 @@ namespace OHOS } //static osTimerId_t upgrade_timer=NULL; - static err_t httpc_download_headers_done_ui(httpc_state_t *connection, void *arg, struct pbuf *hdr, u16_t hdr_len, u32_t content_len) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "httpc_download_headers_done_ui"); - return 0; - } - + static uint32_t custom_start_ota_download_ui_1( uint8_t *uri_str,uint8_t *Path,bool falg,const char *server_name) { @@ -518,12 +594,28 @@ namespace OHOS if(is_new_version) { //下载差分包 - //********** + // //********** container_updating->SetVisible(true); scrollView->SetTouchable(false); scrollView->SetDraggable(false); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "custom_start_ota_download_ui_1"); custom_start_ota_download_ui_1(uri_ota_package,(uint8_t*)Path_ota_package,false,HTTP_FWPGK_SERVER_NAME); + if(report_jsonString!=NULL) + { + uint32_t data_len=strlen(report_jsonString); + if(data_len!=0) + { + FILE *FP_= fopen(UPDATAREPORT,"w+"); + fwrite(report_jsonString,1,data_len,FP_); + fclose(FP_); + printf("data%d %s\r\n",data_len,report_jsonString); + } + + } + + + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, ""); + // upgrade_reported_data(); } } @@ -577,7 +669,7 @@ namespace OHOS } - // char *imei_str= const_cast(ConfigModel::GetInstance()->Getimei().c_str()); + // imei_str= const_cast(ConfigModel::GetInstance()->Getimei().c_str()); // char * version_buf=const_cast(ConfigModel::GetInstance()->GetmoderVer().c_str()); // sprintf((char *)uri,"https://test.app.api.thisiot.com/ota/task?deviceId=%s&sourceVersion=%s",imei_str,version_buf); // custom_start_ota_download_ui_1(uri,(uint8_t*)Path,true); @@ -932,13 +1024,13 @@ namespace OHOS } display_api->set_screen_set_keepon_timeout(-1); memset(uri,0,256); - char *imei_str= const_cast(ConfigModel::GetInstance()->Getimei().c_str()); + imei_str= const_cast(ConfigModel::GetInstance()->Getimei().c_str()); //https://test.app.api.thisiot.com/ota/task?deviceId=deviceId&sourceVersion=sourceVersion // 860132060347507 // v1.1_20240419_152549 - sprintf((char *)uri,"http://test.iot.api.thisiot.com/ota/task?deviceId=%s&sourceVersion=%s",imei_str,"V1.1_20240422_161728");//version_buf); + sprintf((char *)uri,JSON_URL,imei_str,version_buf);//"V1.1_20240422_161728");//version_buf); custom_start_ota_download_ui_1(uri,(uint8_t*)Path,true,HTTP_JSON_SERVER_NAME); - + //report_data_by_get_file(); falg_dwon_json=0; //uograde_service_service_init();