From b58e14353855931c55280f3b77d4fab964684c70 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Sat, 14 Sep 2024 11:30:51 +0800 Subject: [PATCH] =?utf8?q?=E7=B3=BB=E7=BB=9F=E5=8D=87=E7=BA=A7=E6=9B=B4?= =?utf8?q?=E6=94=B9=20BUG=E5=85=88=E5=BB=B6=E6=9C=9F=EF=BC=8C=E5=90=8E?= =?utf8?q?=E7=BB=AD=E5=86=8D=E7=BB=9F=E4=B8=80=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../systemupdate/include/SystemUpdateModel.h | 15 +- .../systemupdate/src/SystemUpdateModel.cpp | 61 +++----- .../systemupdate/src/SystemUpdateView.cpp | 133 +++++++----------- 3 files changed, 80 insertions(+), 129 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/systemupdate/include/SystemUpdateModel.h b/code/sdk/application/wearable/fd230app/nativeui/systemupdate/include/SystemUpdateModel.h index 319ac05b1..c0c424443 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/systemupdate/include/SystemUpdateModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/systemupdate/include/SystemUpdateModel.h @@ -8,15 +8,20 @@ #ifndef SYSTEM_UPDATE_MODEL_H #define SYSTEM_UPDATE_MODEL_H + +#include +#include + +#define USE_THISIOT 1 +// http://iot.api.thisiot.com/ota/task/v2?deviceId=28110668A5D4&sourceVersion=1.1.41 #if USE_THISIOT -#define HTTP_JSON_SERVER_NAME "test.iot.api.thisiot.com"//"test.app.api.thisiot.com"//获取升级服务器 +#define HTTP_JSON_SERVER_NAME "iot.api.thisiot.com"//"test.app.api.thisiot.com"//获取升级服务器 #define HTTP_FWPGK_SERVER_NAME "r-oss.thisiot.com"//"//升级包服务器 #define PORT (80)//(443)//http端口号 -#define POST_URL "http://test.iot.api.thisiot.com/ota/update-result"//上报url -#define JSON_URL "http://test.iot.api.thisiot.com/ota/task?deviceId=%s&sourceVersion=%s"//获取升级url +#define POST_URL "http://iot.api.thisiot.com/ota/update-result"//上报url +#define JSON_URL "http://iot.api.thisiot.com/ota/task?deviceId=%s&sourceVersion=%s"//获取升级url #else -#include -#include + /** * http://icfota.snicker.com.cn:8089/fd230ota.jsp?product=FD230&pkgver=V1.1_20240316_115535&imei=864430010001091 查看 返回的"UptoDate" == False,即可根据"url"地址下载,文件校验可以后面再加。 diff --git a/code/sdk/application/wearable/fd230app/nativeui/systemupdate/src/SystemUpdateModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/systemupdate/src/SystemUpdateModel.cpp index e8395337a..fdcc17983 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/systemupdate/src/SystemUpdateModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/systemupdate/src/SystemUpdateModel.cpp @@ -27,10 +27,7 @@ #include "NativeAbility.h" namespace OHOS { - static char *report_jsonString=NULL; static int fwpkg_size=0; - - static void upgrade_report_task(void *arg) { FILE * fp = fopen(UPDATAREPORT,"rb+"); @@ -69,42 +66,13 @@ namespace OHOS int start_report_timer(void) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"uapi_upgrade_service_init !\r\n"); - app_task_definition_t taskcfg={0}; - taskcfg.create_queue_handle = NULL; - taskcfg.attr.name="report_upgrade_service"; - taskcfg.attr.priority = TASK_PRIORITY_APP; - taskcfg.attr.stack_size = 1024*4; - taskcfg.func = upgrade_report_task; - taskcfg.use_mem = USE_EXTEND_MEM; - - errcode_t ret=uapi_create_osThread_custom(&taskcfg); - if(ret != ERRCODE_SUCC) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"create uapi_upgrade_service_init failed %d!\r\n",ret); - return ERRCODE_FAIL; - } - return ERRCODE_SUCC; } void SystemUpdateModel::report_jsonString_write() { - if(report_jsonString!=NULL) - { - uint32_t data_len=strlen(report_jsonString); - if(data_len!=0) - { - FILE *FP_= fopen(UPDATAREPORT,"w+"); - printf("升级文件保存 \r\n"); - fwrite(report_jsonString,1,data_len,FP_); - fclose(FP_); - printf("data%d %s\r\n",data_len,report_jsonString); - free(report_jsonString); - report_jsonString=NULL; - } - } + return; } @@ -211,7 +179,7 @@ namespace OHOS char *buf=(char *)malloc(1024); memset((void*)buf,0,1024); int ret =fread(buf,1,1024,fp); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "httpc_download_result_ui %d %s\r\n",ret,buf); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s\r\n",buf); if(ret==0) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "fread %d",ret); @@ -219,7 +187,13 @@ namespace OHOS free(buf); return false; } - cJSON *root = cJSON_Parse(buf); + char *p=buf; + while (*p!='{') + { + p++; + } + + cJSON *root = cJSON_Parse(p); free(buf); if(root==NULL) { @@ -227,22 +201,21 @@ namespace OHOS } else if(root!=NULL) { - int code=cJSON_GetObjectItem(root, "code")->valueint; char *msg_json = cJSON_GetObjectItem(root, "msg")->valuestring; + if(msg_json) strcpy(msg,msg_json); + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "msg_json"); + } int success=cJSON_GetObjectItem(root, "success")->valueint; - char msg_buf[256]={0}; - - if(code=IOT_CODE_SUCCESS) + if(code==IOT_CODE_SUCCESS) { cJSON *data=cJSON_GetObjectItem(root, "data"); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, ""); - report_jsonString = cJSON_PrintUnformatted(data); - //cJSON_Delete(data); - if(data!=NULL) { cJSON *downloadFileVo=cJSON_GetObjectItem(data, "downloadFileVo"); @@ -268,11 +241,12 @@ namespace OHOS memset(NEW_VISON,0,MSG_LEN); sprintf((char *)NEW_VISON,"%s",targetVersion); - } + } } else { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "code!=IOT_CODE_SUCCESS"); + return false; } WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s",msg); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "httpc_download_result_ui"); @@ -280,7 +254,6 @@ namespace OHOS } fclose(fp); - return true; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/systemupdate/src/SystemUpdateView.cpp b/code/sdk/application/wearable/fd230app/nativeui/systemupdate/src/SystemUpdateView.cpp index af8a9d2d9..a5abdc641 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/systemupdate/src/SystemUpdateView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/systemupdate/src/SystemUpdateView.cpp @@ -30,6 +30,9 @@ #include "linux/delay.h" #include "cat1_ctl.h" #include "cat1_server_hal.h" +#include "bts_le_gap.h" +#include "custom_http_download.h" + #ifdef __cplusplus #if __cplusplus extern "C" @@ -57,7 +60,6 @@ namespace OHOS // osThreadAttr_t g_alipay_attr = { // "alipay_task", 0, NULL, 0, NULL, ALIPAT_MSG_STACK_SIZE, TASK_PRIORITY_ALIPAY_APP, 0, 0 // }; - static httpc_connection_t settings = {0}; static uint8_t uri[256] ={0};// (uint8_t*) //"http://icfota.snicker.com.cn:8089/fd230ota.jsp?product=FD230&pkgver=V1.1_20240316_115535&imei=864430010001091"; @@ -79,7 +81,7 @@ namespace OHOS // { // display_api->turn_on_screen(); // } - // display_api->set_auto_timeout_function(off); + display_api->set_auto_timeout_function(off); } @@ -108,9 +110,9 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "httpc_download_result_ui"); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"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); - uapi_cat1_keep_wakeup(0); LCD_auto_timeout(true); SystemUpdateModel ::GetInstance().OTA_Update_msg_back(OTA_UPDATA_MSG_NEW_VER); + http_single_download_stop(); return ; } @@ -119,9 +121,10 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "httpc_download_result_ui"); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"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); - uapi_cat1_keep_wakeup(0); + LCD_auto_timeout(true); SystemUpdateModel ::GetInstance().OTA_Update_msg_back(OTA_UPDATA_MSG_FWKG); + http_single_download_stop(); return ; } @@ -135,28 +138,7 @@ namespace OHOS 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 *)UPDATAREPORT_; - - settings.result_fn=httpc_download_result_report_data; - settings.file_rx_fn = httpc_download_file_recv_ui; - 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); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"custom_start_ota_download %d \r\n",rett); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "use_post_"); + return; } void upgrade_reported_data(void) @@ -241,28 +223,14 @@ namespace OHOS } - static uint32_t custom_start_ota_download_ui_1( uint8_t *uri_str,uint8_t *Path,uint8_t falg,const char *server_name) + static uint32_t custom_start_ota_download_ui( uint8_t *uri_str,uint8_t *Path,uint8_t falg,const char *server_name) { - //(uint8_t*)argv[0]; uint8_t *otadatapath = (uint8_t*)Path; + err_t rett; WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"custom_start_ota_download %s to %s\r\n",uri_str,otadatapath); - uapi_cat1_keep_wakeup(1); LCD_auto_timeout(false); - if(falg==OTA_BUTTON_GET_VISON) - { - settings.use_post=0; - settings.result_fn=httpc_download_result_ui; - settings.file_rx_fn = NULL; - } - else if(falg==OTA_BUTTON_GET_ABLE_DOWNLOAD) - { - settings.use_post=0; - settings.result_fn=httpc_download_FWPKG_result_ui; - settings.file_rx_fn = httpc_download_file_recv_ui; - } - FILE * fp= fopen((char *)Path,"rb"); if(fp!=NULL) { @@ -270,48 +238,50 @@ namespace OHOS int ret= remove((char *)Path); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "file remove!!!!!!!!!!!!! %d ",ret); } - - - settings.headers_done_fn=httpc_download_headers_done_ui; - - httpc_state_t* connection=NULL; - err_t rett = httpc_get_file_dns_to_disk( - server_name, - PORT, - (const char*) uri_str, - (const httpc_connection_t *)&settings, - NULL, - (const char*) otadatapath, - &connection); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"custom_start_ota_download %d \r\n",rett); - if(rett!=0) - { - // if(SystemupgradeView::GetInstance()) - // SystemupgradeView::GetInstance()->set_string_value(NULL,false); + if(falg==OTA_BUTTON_GET_VISON) + { + rett =http_single_download_start((uint8_t*)server_name,PORT,uri_str,otadatapath, + httpc_download_result_ui,httpc_download_headers_done_ui,NULL); } - return rett;// ERRCODE_SUCC; + else if(falg==OTA_BUTTON_GET_ABLE_DOWNLOAD) + { + rett =http_single_download_start((uint8_t*)server_name,PORT,uri_str,otadatapath, + httpc_download_FWPKG_result_ui,httpc_download_headers_done_ui,httpc_download_file_recv_ui); + } + + return rett; + } static void start_get_updata_json(void) { memset(uri,0,256); - imei_str= const_cast(ConfigModel::GetInstance()->Getimei().c_str()); - char version_buf[128]={0}; - uint32_t version_len=128; - uapi_get_buildversion((uint8_t*)version_buf,version_len); + char Mac_str[32]={0}; + char version_buf[32]={0}; + + bd_addr_t addr_info; + int ret = gap_ble_get_local_addr(&addr_info); + + sprintf_s(Mac_str,32,"%02X%02X%02X%02X%02X%02X",addr_info.addr[5],addr_info.addr[4],addr_info.addr[3], + addr_info.addr[2],addr_info.addr[1],addr_info.addr[0]); + + uint8_t _major,_mid,_minor; + uapi_get_fw_version(&_major,&_mid,&_minor); + sprintf_s(version_buf,32,"%d.%d.%d",_major,_mid,_minor); + #if OTA_UPDATA_TEST sprintf((char *)uri,JSON_URL,"860132060347762","V1.1.14_20240706_182936_CT"); #else - sprintf((char *)uri,JSON_URL,imei_str,version_buf); + sprintf((char *)uri,JSON_URL,Mac_str,version_buf); #endif - custom_start_ota_download_ui_1(uri,(uint8_t*)UPDATAJSONPATH,OTA_BUTTON_GET_VISON,HTTP_JSON_SERVER_NAME); + custom_start_ota_download_ui(uri,(uint8_t*)UPDATAJSONPATH,OTA_BUTTON_GET_VISON,HTTP_JSON_SERVER_NAME); } static void start_get_updata_fwpkg(void) { - if(ERRCODE_SUCC==custom_start_ota_download_ui_1(SystemUpdateModel ::GetInstance().uri_ota_package,(uint8_t*)UPDATAFWPKGPATH,OTA_BUTTON_GET_ABLE_DOWNLOAD,HTTP_FWPGK_SERVER_NAME)) + if(ERRCODE_SUCC==custom_start_ota_download_ui(SystemUpdateModel ::GetInstance().uri_ota_package,(uint8_t*)UPDATAFWPKGPATH,OTA_BUTTON_GET_ABLE_DOWNLOAD,HTTP_FWPGK_SERVER_NAME)) { SystemUpdateModel ::GetInstance().button_flag=OTA_BUTTON_GET_DOWNLOADING; @@ -421,7 +391,6 @@ namespace OHOS start_dwonload(); break; case OTA_BUTTON_GET_ABLE_UPDTAT: - SystemUpdateModel ::GetInstance() .report_jsonString_write(); #if OTA_UPDATA_TEST uapi_reboot_device(); #else @@ -665,8 +634,13 @@ namespace OHOS IMEIlabel->SetStyle(STYLE_TEXT_FONT, 30); IMEIlabel->SetStyle(STYLE_LINE_HEIGHT, 35); - imei_str= const_cast(ConfigModel::GetInstance()->Getimei().c_str()); - IMEIlabel->SetText(imei_str); + bd_addr_t addr_info; + int ret = gap_ble_get_local_addr(&addr_info); + char Mac_str[32]={0}; + sprintf_s(Mac_str,32,"%02X%02X%02X%02X%02X%02X",addr_info.addr[5],addr_info.addr[4],addr_info.addr[3], + addr_info.addr[2],addr_info.addr[1],addr_info.addr[0]); + + IMEIlabel->SetText(Mac_str); IMEIlabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); IMEIlabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); IMEIlabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); @@ -700,10 +674,13 @@ namespace OHOS VersionIdLabel->SetPosition(33, 262+30, 400, 35); VersionIdLabel->SetStyle(STYLE_TEXT_FONT, 30); VersionIdLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + + char version_buf[32]={0}; + uint8_t _major,_mid,_minor; + uapi_get_fw_version(&_major,&_mid,&_minor); + sprintf_s(version_buf,32,"%d.%d.%d",_major,_mid,_minor); + - char version_buf[128]={0}; - uint32_t version_len=128; - uapi_get_buildversion((uint8_t*)version_buf,version_len); VersionIdLabel->SetText(version_buf); @@ -829,11 +806,11 @@ namespace OHOS updatasider->SetStyle(STYLE_BORDER_RADIUS, 100); updatasider->SetBackgroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND); updatasider->SetForegroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND); - updatasider->SetSliderColor(Color::GetColorFromRGBA(0x19, 0x19, 0x19, 0xff), Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff)); + updatasider->SetSliderColor(Color::GetColorFromRGBA(0x19, 0x19, 0x19, 0xff), Color::GetColorFromRGBA(0xfA, 0xfA, 0xfA, 0xff)); updatasider->SetForegroundStyle(STYLE_BACKGROUND_OPA, 0xff); updatasider->SetDraggable(false); updatasider->SetVisible(false); - + updatasider->SetTouchable(false); updatasider->SetValue(0); @@ -861,16 +838,12 @@ namespace OHOS UpdateNowLabel->SetText("获取升级"); NEWMSGLabel->SetText(""); NEWVersionIdLabel->SetText(""); - } if(flag==OTA_BUTTON_GET_ABLE_DOWNLOAD) { UpdateNowLabel->SetText("开始下载"); NEWMSGLabel->SetText(SystemUpdateModel ::GetInstance().OTA_MSG); NEWVersionIdLabel->SetText(SystemUpdateModel ::GetInstance().NEW_VISON); - - - } if(flag==OTA_BUTTON_GET_DOWNLOADING) { -- 2.17.1