From: SnickerSun Date: Tue, 7 May 2024 02:20:14 +0000 (+0800) Subject: 优化ota升级界面,保证下载时cat1不休眠,且随时可以退出界面。 X-Git-Tag: release_V1.2.70_20241020_135402~1113^2~18^2 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=32cd95e6e2968675bb3ccf181156bb81fd5ae23b;p=mirrors%2FFD230.git 优化ota升级界面,保证下载时cat1不休眠,且随时可以退出界面。 优化http_client,支持下载文件进度提醒。 修复at下载指令。 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp index 6829336ab..b03e9e20a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp @@ -186,14 +186,14 @@ namespace OHOS if (strcmp(view.GetViewId(), SYSTEM_UPGRADE) == 0) { - isSystemUpgradeState = true; + // isSystemUpgradeState = true; SystemupgradeView::GetInstance()->statr_down_fwpkg(); } if (strcmp(view.GetViewId(), "labelButton1_exit") == 0) { // SystemView::GetInstance()->ChangeSlice(VIEW_SETTING);; NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); - isSystemUpgradeState = false; + // isSystemUpgradeState = false; } return true; } @@ -278,7 +278,7 @@ namespace OHOS bool SystemPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 { - if (!isSystemUpgradeState) + // if (!isSystemUpgradeState) { // 如果处于系统升级状态power键返回功能无效 UNUSED(view); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemPresenter::OnKeyAct"); 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 2081d8e57..1558a10b8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/Systemupgrade.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/Systemupgrade.cpp @@ -43,10 +43,16 @@ namespace OHOS static uint8_t uri_ota_package[256] ={0}; static const char *imei_str=NULL; static char *report_jsonString=NULL; - + static uint32_t file_total_len = 0; 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"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "httpc_download_headers_done_ui hdrlen %d, file len %d\r\n",hdr_len,content_len); + file_total_len = content_len; + return 0; + } + static err_t httpc_download_file_recv_ui(httpc_state_t *connection, u32_t rx_len,u32_t rx_total_len) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "httpc_download_file_recv_ui recv %d bytes total received %d filelen %d\r\n",rx_len,rx_total_len,file_total_len); return 0; } @@ -82,8 +88,8 @@ namespace OHOS uint8_t *otadatapath =(uint8_t *)UPDATAREPORT_; settings.result_fn=httpc_download_result_report_data; - - settings.headers_done_fn=httpc_download_headers_done_ui; + 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( @@ -365,7 +371,7 @@ namespace OHOS 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); - uapi_cat1_wakeup_cat1(0); + uapi_cat1_keep_wakeup(0); if(httpc_result!=0) { SystemupgradeView::GetInstance()->init_fail(1); @@ -383,7 +389,7 @@ namespace OHOS 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); - uapi_cat1_wakeup_cat1(0); + uapi_cat1_keep_wakeup(0); upgrade_service_service_init();//线程当timer用 return ; @@ -398,8 +404,7 @@ namespace OHOS //(uint8_t*)argv[0]; uint8_t *otadatapath = (uint8_t*)Path; PRINT("custom_start_ota_download %s to %s\r\n",uri_str,otadatapath); - - uapi_cat1_wakeup_cat1(1); + uapi_cat1_keep_wakeup(1); if(falg) { settings.result_fn=httpc_download_result_ui; @@ -417,6 +422,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "file remove!!!!!!!!!!!!! %d ",ret); } + settings.file_rx_fn = httpc_download_file_recv_ui; settings.headers_done_fn=httpc_download_headers_done_ui; settings.use_post=0; httpc_state_t* connection=NULL; @@ -428,7 +434,6 @@ namespace OHOS NULL, (const char*) otadatapath, &connection); - PRINT("custom_start_ota_download %d \r\n",rett); if(rett!=0) SystemupgradeView::GetInstance()->set_string_value(NULL,false); @@ -1027,7 +1032,8 @@ namespace OHOS //https://test.app.api.thisiot.com/ota/task?deviceId=deviceId&sourceVersion=sourceVersion // 860132060347507 // v1.1_20240419_152549 - sprintf((char *)uri,JSON_URL,imei_str,version_buf);//"V1.1_20240422_161728");//version_buf); + // sprintf((char *)uri,JSON_URL,"860132060347507","V1.1_20240422_161728"); + sprintf((char *)uri,JSON_URL,imei_str,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; diff --git a/code/sdk/drivers/peripheral/utils/custom_runtime.h b/code/sdk/drivers/peripheral/utils/custom_runtime.h index da896fb50..9fb53e1dd 100644 --- a/code/sdk/drivers/peripheral/utils/custom_runtime.h +++ b/code/sdk/drivers/peripheral/utils/custom_runtime.h @@ -27,12 +27,25 @@ typedef enum{ CAT1_5G } cat1_network_type_t; + +/** + * cat1_powerOn 0,1 + * volte volte开关 + * network_on 0,1 + * cat1_network_type, 0, 无网络, 1 GSM,2 3G , 4 4G/LTE + * sim 1,0 + * signal 1,31 ; 99 no signal + * opera -1 , "CNUTS" + * imei + * pyVer + * modemVer +*/ typedef struct { uint8_t cat1_powerOn; uint8_t volte ; uint8_t network_on ; - uint8_t cat1_network_type ; + uint8_t cat1_network_type ; int sim ; int signal ; char opera[20] ; diff --git a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c index c780737f5..6e58ff7ec 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c @@ -95,16 +95,21 @@ void httpc_download_result(void *arg, httpc_result_t httpc_result, u32_t rx_cont 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); //通讯结束,休眠cat1 - uapi_cat1_wakeup_cat1(0); + uapi_cat1_keep_wakeup(0); return ; } - +static uint32_t file_total_len = 0; err_t httpc_download_headers_done(httpc_state_t *connection, void *arg, struct pbuf *hdr, u16_t hdr_len, u32_t content_len) { PRINT("httpc_download_headers_done , hdr_len %d ,content_len %d\n",hdr_len,content_len); + file_total_len = content_len; + return 0; +} +err_t httpc_download_file_recv_ui(httpc_state_t *connection, u32_t rx_len,u32_t rx_total_len) +{ + PRINT("httpc_download_file_recv_ui recv %d bytes total received %d filelen %d\r\n",rx_len,rx_total_len,file_total_len); return 0; } - static uint32_t custom_start_ota_download(uint8_t *para, uint32_t paraLen, char *strCommonCmd) { UNUSED(strCommonCmd); @@ -124,15 +129,18 @@ static uint32_t custom_start_ota_download(uint8_t *para, uint32_t paraLen, char } //通讯开始,唤醒cat1 - uapi_cat1_wakeup_cat1(1); + uapi_cat1_keep_wakeup(1); uint8_t *server = (uint8_t*)argv[0]; - uint8_t port = atoi((const char*)argv[1]); + uint16_t port = atoi((const char*)argv[1]); uint8_t *uri = (uint8_t*)argv[2]; uint8_t *otadatapath = (uint8_t*)argv[3]; PRINT("custom_start_ota_download %s:%d %s to %s\r\n",server,port,uri,otadatapath); httpc_connection_t settings = {0}; settings.result_fn=httpc_download_result; + settings.file_rx_fn = httpc_download_file_recv_ui; settings.headers_done_fn=httpc_download_headers_done; + settings.use_post = 0 ; + httpc_state_t* connection=NULL; err_t rett = httpc_get_file_dns_to_disk( (const char*) server, diff --git a/code/sdk/open_source/openharmony/third_party/lwip/src/apps/http/http_client.c b/code/sdk/open_source/openharmony/third_party/lwip/src/apps/http/http_client.c index 4afebb380..efdeae929 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/src/apps/http/http_client.c +++ b/code/sdk/open_source/openharmony/third_party/lwip/src/apps/http/http_client.c @@ -85,7 +85,7 @@ #define HTTPC_DEBUG_SERIOUS (HTTPC_DEBUG | LWIP_DBG_LEVEL_SERIOUS) #define HTTPC_POLL_INTERVAL 1 -#define HTTPC_POLL_TIMEOUT 80 /* 15 seconds */ +#define HTTPC_POLL_TIMEOUT 160 /* 15 seconds */ #define HTTPC_CONTENT_LEN_INVALID 0xFFFFFFFF @@ -367,7 +367,11 @@ httpc_tcp_recv(void *arg, struct altcp_pcb *pcb, struct pbuf *p, err_t r) req->rx_content_len += p->tot_len; if (req->recv_fn != NULL) { /* directly return here: the connection migth already be aborted from the callback! */ - return req->recv_fn(req->callback_arg, pcb, p, r); + err_t error=req->recv_fn(req->callback_arg, pcb, p, r); + if (req->conn_settings && req->conn_settings->file_rx_fn) { + req->conn_settings->file_rx_fn(req,p->tot_len,req->rx_content_len); + } + return error; } else { altcp_recved(pcb, p->tot_len); pbuf_free(p); @@ -515,7 +519,7 @@ static int httpc_create_request_string(const httpc_connection_t *settings, const char* server_name, int server_port, const char* uri, int use_host, char *buffer, size_t buffer_size) { - printf("httpc_create_request_string use_post %d use_proxy %d use_host %dhost %d\r\n",settings->use_post,settings->use_proxy,use_host); + printf("httpc_create_request_string use_post %d use_proxy %d use_host %d \r\n",settings->use_post,settings->use_proxy,use_host); if (settings->use_proxy) { LWIP_ASSERT("server_name != NULL", server_name != NULL); if (server_port != HTTP_DEFAULT_PORT) @@ -532,7 +536,7 @@ httpc_create_request_string(const httpc_connection_t *settings, const char* serv if (settings->use_post) { return snprintf(buffer, buffer_size, HTTPC_REQ_11_HOST_FORMAT_POST(uri, server_name, settings->arglen, settings->args)); - printf("%s\r\n",buffer); + // printf("%s\r\n",buffer); } return snprintf(buffer, buffer_size, HTTPC_REQ_11_HOST_FORMAT(uri, server_name)); } @@ -619,7 +623,7 @@ httpc_init_connection_common(httpc_state_t **connection, const httpc_connection_ /* set up request buffer */ req_len2 = httpc_create_request_string(settings, server_name, server_port, uri, use_host, (char *)req->request->payload, req_len + 1); - printf("%s\r\n",(char *)req->request->payload); + // printf("%s\r\n",(char *)req->request->payload); if (req_len2 != req_len) { httpc_free_state(req); return ERR_VAL; @@ -764,6 +768,9 @@ typedef struct _httpc_filestate static void httpc_fs_result(void *arg, httpc_result_t httpc_result, u32_t rx_content_len, u32_t srv_res, err_t err); +static void httpc_fs_receive_bytes(void *arg, u32_t rx_received_len, u32_t total_len ); + + /** Initalize http client state for download to file system */ static err_t httpc_fs_init(httpc_filestate_t **filestate_out, const char* local_file_name, @@ -789,7 +796,7 @@ httpc_fs_init(httpc_filestate_t **filestate_out, const char* local_file_name, /* copy client settings but override result callback */ memcpy(&filestate->settings, settings, sizeof(httpc_connection_t)); filestate->settings.result_fn = httpc_fs_result; - + f = fopen(local_file_name, "wb"); if(f == NULL) { /* could not open file */ @@ -842,6 +849,7 @@ httpc_fs_tcp_recv(void *arg, struct altcp_pcb *pcb, struct pbuf *p, err_t err) for (q = p; q != NULL; q = q->next) { fwrite(q->payload, 1, q->len, filestate->file); } + // printf("received file bufsize %d\r\n",p->tot_len); altcp_recved(pcb, p->tot_len); pbuf_free(p); return ERR_OK; diff --git a/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/apps/http_client.h b/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/apps/http_client.h index 29667e047..1cce15ef4 100644 --- a/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/apps/http_client.h +++ b/code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/apps/http_client.h @@ -121,6 +121,7 @@ typedef void (*httpc_result_fn)(void *arg, httpc_result_t httpc_result, u32_t rx * @return if != ERR_OK is returned, the connection is aborted */ typedef err_t (*httpc_headers_done_fn)(httpc_state_t *connection, void *arg, struct pbuf *hdr, u16_t hdr_len, u32_t content_len); +typedef err_t (*httpc_file_rx_fn)(httpc_state_t *connection, u32_t rx_len,u32_t rx_total_len); typedef struct _httpc_connection { ip_addr_t proxy_addr; @@ -138,6 +139,9 @@ typedef struct _httpc_connection { It can abort the connection by returning != ERR_OK */ httpc_headers_done_fn headers_done_fn; + /* this callback is called after receiving some bytes of download file + */ + httpc_file_rx_fn file_rx_fn; //添加post u8_t use_post; u16_t arglen;