优化ota升级界面,保证下载时cat1不休眠,且随时可以退出界面。 133/1 133/head 134/target/1
authorSnickerSun <snickersun@163.com>
Tue, 7 May 2024 02:20:14 +0000 (10:20 +0800)
committerSnickerSun <snickersun@163.com>
Tue, 7 May 2024 02:20:14 +0000 (10:20 +0800)
优化http_client,支持下载文件进度提醒。
修复at下载指令。

code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/system/src/Systemupgrade.cpp
code/sdk/drivers/peripheral/utils/custom_runtime.h
code/sdk/drivers/peripheral/utils/custom_utils_at_cmd.c
code/sdk/open_source/openharmony/third_party/lwip/src/apps/http/http_client.c
code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/apps/http_client.h

index 6829336..b03e9e2 100644 (file)
@@ -186,14 +186,14 @@ namespace OHOS
 \r
         if (strcmp(view.GetViewId(), SYSTEM_UPGRADE) == 0)\r
         {\r
-            isSystemUpgradeState = true;\r
+            // isSystemUpgradeState = true;\r
             SystemupgradeView::GetInstance()->statr_down_fwpkg();\r
         }\r
         if (strcmp(view.GetViewId(), "labelButton1_exit") == 0)\r
         {\r
             // SystemView::GetInstance()->ChangeSlice(VIEW_SETTING);;\r
             NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING);\r
-            isSystemUpgradeState = false;\r
+            // isSystemUpgradeState = false;\r
         }\r
         return true;\r
     }\r
@@ -278,7 +278,7 @@ namespace OHOS
 \r
     bool SystemPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件\r
     {\r
-        if (!isSystemUpgradeState)\r
+        // if (!isSystemUpgradeState)\r
         { // 如果处于系统升级状态power键返回功能无效\r
             UNUSED(view);\r
             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemPresenter::OnKeyAct");\r
index 2081d8e..1558a10 100644 (file)
@@ -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;
index da896fb..9fb53e1 100644 (file)
@@ -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] ;
index c780737..6e58ff7 100644 (file)
@@ -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, 
index 4afebb3..efdeae9 100644 (file)
@@ -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;
index 29667e0..1cce15e 100644 (file)
@@ -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;