添加开机升级自动上报升级结果
authorhcj <1224667075@qq.com>
Wed, 24 Apr 2024 02:57:17 +0000 (10:57 +0800)
committerhcj <1224667075@qq.com>
Wed, 24 Apr 2024 02:57:17 +0000 (10:57 +0800)
code/sdk/application/wearable/fd230app/nativeui/system/include/SystemModel.h
code/sdk/application/wearable/fd230app/nativeui/system/include/Systemupgrade.h
code/sdk/application/wearable/fd230app/nativeui/system/src/SystemModel.cpp
code/sdk/application/wearable/fd230app/nativeui/system/src/Systemupgrade.cpp
code/sdk/drivers/peripheral/slip/cat1Service/CMakeLists.txt
code/sdk/drivers/peripheral/slip/cat1Service/cat1_server_hal.cpp
code/sdk/drivers/peripheral/slip/cat1Service/cat1_server_hal.h
code/sdk/drivers/peripheral/utils/custom_utils.c
code/sdk/open_source/openharmony/third_party/lwip/src/include/lwip/apps/http_client.h

index 6901e34..6c2ab86 100644 (file)
 #include "components/ui_label_button_ext.h"
 #include "cat1_ctl.h"
 
+#define HTTP_JSON_SERVER_NAME "test.iot.api.thisiot.com"//"test.app.api.thisiot.com"//获取升级服务器
+#define HTTP_FWPGK_SERVER_NAME "r-oss.thisiot.com"//"//升级包服务器
+#define PORT (80)//(443)//http端口号
+#define UPDATAJSONPATH "/update/ota_start_.json"//获取升级的得到的json
+
+#define UPDATAREPORT "/update/ota_start_reported_.json"//点升级后保存下来的json
+
+#define UPDATAFWPKGPATH "/update/update.fwpkg" //升级包
+
+#define UPDATAREPORT_  "/update/ota_report_.json"//上报升级得到的json
+
+#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
+
 namespace OHOS
 {
     typedef enum {
index b7c2261..127f06c 100644 (file)
@@ -1,8 +1,89 @@
 
 #include "system/include/SystemModel.h"
+#include "system/include/Systemupgrade.h"
+#include "wearable_log.h"
+#include "UiConfig.h"
+#include "custom_utils.h"
+#include "stdio.h"
+#include <iostream>
+#include <fstream>
+#include "cJSON.h"
+#include "config/include/ConfigModel.h"
+#include "lwip/err.h"
+#include "power_display_service.h"
+#include "cmsis_os2.h"
+#include "los_memory.h"
+#include "thread_init.h"
+ #include "lwip/apps/http_client.h"
+ #include "tcxo.h"
+ #include "cat1_server.h"
+ #include "linux/delay.h"
+
+#define UPDATAREPORT_M UPDATAREPORT
 
 namespace OHOS
 {
+    static void upgrade_report_task(void  *arg)
+    {
+        FILE * fp = fopen(UPDATAREPORT_M,"rb+");
+        bool falg=false;
+        if(fp!=NULL)
+        {
+            falg=true;
+            PRINT("UPDATAREPORT_M IS TRUE!\r\n");
+            fclose(fp);
+        }
+       
+        while (falg)
+        {
+            
+            for(int i=0;i<60;i++)
+            {
+                msleep(1000);
+            }
+            if(ConfigModel::GetInstance()->GetCat1_4Gability())
+            {
+                upgrade_reported_data();
+            }
+            for(int i=0;i<60;i++)
+            {
+                msleep(1000);
+            }
+            fp = fopen(UPDATAREPORT_M,"rb+");
+            if(fp!=NULL)
+            {
+                falg=true;
+                fclose(fp);
+            }
+            else
+            {
+                falg=false;
+            }
+        } 
+        PRINT("UPDATAREPORT IS OK!\r\n");
+    }
+
+    int start_report_timer(void)
+    {
+        PRINT("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)
+        {
+            PRINT("create uapi_upgrade_service_init failed %d!\r\n",ret);
+            return ERRCODE_FAIL;
+        }
+
+        return ERRCODE_SUCC;
+
+    }
 
     SystemModel *SystemModel::GetInstance(void)
     {
index a332249..28accae 100644 (file)
  #include "cat1_server.h"
  #include "linux/delay.h"
 
-#define HTTP_JSON_SERVER_NAME "test.iot.api.thisiot.com"//"test.app.api.thisiot.com"
-#define HTTP_FWPGK_SERVER_NAME "r-oss.thisiot.com"//"
-#define PORT (80)//(443)
-#define UPDATAJSONPATH "/update/ota_start_.json"
 
-#define UPDATAREPORT "/update/ota_start_reported_.json"
-
-#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
 
@@ -64,10 +54,15 @@ 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);
+        if(srv_res==200 && err==0)
+        remove(UPDATAREPORT);
+
         return ;
     }
+    
+    
 
-
+   
     // // httpc_get_file(
     //     const ip_addr_t* server_addr, 
     //     u16_t port, 
@@ -83,7 +78,7 @@ namespace OHOS
         settings.use_post=1;
         settings.args=(u8_t*)data;
         settings.arglen=data_len;
-        uint8_t *otadatapath =(uint8_t *)"/update/ota_report_.json";
+        uint8_t *otadatapath =(uint8_t *)UPDATAREPORT_;
 
         settings.result_fn=httpc_download_result_report_data;
     
@@ -169,8 +164,7 @@ namespace OHOS
                 u16_t buf_len=strlen(buf);
                 report_data_by_get_file(buf,buf_len);
 
-                remove(UPDATAREPORT);
-
+               
            // }
         }   
         cJSON_Delete(data);
@@ -594,7 +588,7 @@ namespace OHOS
         if(is_new_version)
         {
             //下载差分包
-            // //**********
+            // // //**********
             container_updating->SetVisible(true);
             scrollView->SetTouchable(false);
             scrollView->SetDraggable(false);
@@ -606,6 +600,7 @@ namespace OHOS
                 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);
index 76f2702..be64061 100644 (file)
@@ -13,6 +13,7 @@ set(PRIVATE_HEADER
     ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits
     ${ROOT_DIR}/application/wearable/nativeapp/nativeui/heartrate/include
     ${ROOT_DIR}/application/wearable/fd230app/nativeui/phone/include
+    ${ROOT_DIR}/application/wearable/fd230app/nativeui/system/include
 )
 
 set(SOURCES
index 7a44178..090a022 100644 (file)
@@ -17,7 +17,7 @@
 #include "samgr_lite.h"
 #include "thread_adapter.h"
 #include "graphic_service.h"
-
+#include "SystemModel.h"
 #ifdef __cplusplus
 
 extern "C" {
@@ -150,6 +150,11 @@ int cat1_msg_event_sendmsg_toUI(char* callno)
     return ERRCODE_SUCC;
 }
 
+void up_report_timer(void)
+{
+     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "up_report_timer_");
+    OHOS::start_report_timer();
+}
 
 
 
index 6cdc82a..4c5290b 100644 (file)
@@ -19,6 +19,7 @@ int callend_event_sendmsg_toUI(char* callno);
 int incomingcall_event_sendmsg_toUI(char* callno);
 int calldial_event_sendmsg_toUI(char* callno);
 int cat1_msg_event_sendmsg_toUI(char* callno);
+void up_report_timer(void);
 #ifdef __cplusplus
 #if __cplusplus
 }
index d430101..e30ed72 100644 (file)
@@ -229,6 +229,7 @@ void startup_post_init_task(void)
 
     LOS_Msleep(5000);
     addressbookToRead(NULL);
+    up_report_timer();
     if ( poweron_cat1_on_bootup_flag() )
     {
         PRINT("PowerOn Cat1 !\r\n");