在recovery和各种reboot前增加 保存时间到calendar,减少ota升级造成的时间偏差
authorSnickerSun <snickersun@163.com>
Tue, 10 Sep 2024 10:55:51 +0000 (18:55 +0800)
committerSnickerSun <snickersun@163.com>
Tue, 10 Sep 2024 10:55:51 +0000 (18:55 +0800)
code/sdk/application/brandy/brandy_recovery/app_os_init.c
code/sdk/application/brandy/brandy_recovery/main.c
code/sdk/application/brandy/brandy_standard/thread_pri_init.c
code/sdk/application/wearable/service/msg_center/src/ota/msg_center_ota.cpp
code/sdk/build/config/target_config/brandy/target_config.py
code/sdk/drivers/peripheral/utils/custom_utils.c
code/sdk/middleware/utils/dfx/diag_dfx_cmd/diag_update/diag_update.c
code/sdk/middleware/utils/update/storage/upg_storage.c

index 70c7606..b9fce36 100755 (executable)
@@ -211,5 +211,13 @@ static void app_main(const void *unused)
         printf("--------------------------\r\n");
         printf("no need upgrade, this branch will never enter\r\n");
     }
+    /*******重启前保存时间到Calendar******/
+    #ifndef MSEC_PER_SEC
+    #define MSEC_PER_SEC        1000L
+    #endif
+    uint64_t time_sec = get_local_timestamp();
+    time_sec = time_sec * MSEC_PER_SEC;
+    uapi_calendar_set_timestamp(time_sec);
+    /***********************************/
     upg_reboot();
 }
index 8ab629f..c825f24 100755 (executable)
 #include "xlt_memory.h"
 #endif
 #endif
-
+#include "calendar.h"
+#ifndef MSEC_PER_SEC
+#define MSEC_PER_SEC        1000L
+#endif
 #define WDT_TIMEOUT_S  30
 #define IMG_NUM_MAX    2
 #define IMG_SEC        0
@@ -225,6 +228,17 @@ static void board_init(uint32_t flash_id, uint32_t flash_unique_id)
 
     pio_func_init();
     gpio_func_init();
+/********启动时获取Canedar时间并同步到设备*****/
+    uapi_calendar_init();
+    calendar_t date;
+    uapi_calendar_get_datetime(&date);
+    print_time(&date);
+    uint64_t sec;
+    uapi_calendar_get_timestamp(&sec);
+    printf("callendar timestamp = %lld \r\n", sec);
+    sec = sec / MSEC_PER_SEC;
+    sync_time(sec, uapi_get_timezone());
+/**********************************/
 }
 
 static void chip_xip_init(void)
index a7b4c29..5af1851 100755 (executable)
@@ -352,6 +352,14 @@ static void upg_check_upgrade(void)
     } else {\r
         PRINT("upgrade success\r\n");\r
     }\r
+    /*******重启前保存时间到Calendar******/\r
+    #ifndef MSEC_PER_SEC\r
+    #define MSEC_PER_SEC        1000L\r
+    #endif\r
+    uint64_t time_sec = get_local_timestamp();\r
+    time_sec = time_sec * MSEC_PER_SEC;\r
+    uapi_calendar_set_timestamp(time_sec);\r
+    /***********************************/\r
     upg_reboot();\r
 }\r
 #endif\r
index 7ae4e61..256c5c1 100644 (file)
@@ -22,7 +22,7 @@
 #ifdef SUPPORT_AUTO_OTA
 #include "auto_ota_service.h"
 #endif
-
+#include "custom_utils.h"
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -186,6 +186,7 @@ errcode_t msg_center_ota_rec_upg_start(uint8_t cmd_id, uint8_t type, void *usr_d
     }
     WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "upg start success!!!!\r\n");
 
+    uapi_calendar_store_date();
     upg_reboot();
     return ERRCODE_SUCC;
 }
index 83bd831..79496f1 100755 (executable)
@@ -140,7 +140,7 @@ target_template = {
         'ram_component_set': ['std_common_lib', 'mem', 'cpu', 'lpc', 'dma',
                               'xip_os', 'ipc', 'watchdog', 'uart', 'otp', 'efuse_v100',
                               'gpio_v100', 'spi', 'qspi', 'cpu_trace', 'time_set', 'security',
-                              'update_recovery', 'i2c', 'pmp_set', 'flash', 'button'
+                              'update_recovery', 'i2c', 'pmp_set', 'flash', 'button','calendar'
                               ],
         'bin_name': 'recovery',
         'application': 'recovery',
index 0ee82b1..51b0176 100644 (file)
@@ -163,11 +163,14 @@ extern void uapi_sys_shipmode(uint32_t arg);
 extern void cm_sync_all_config_to_disk(void);
 void uapi_poweroff_device(void)
 {
-    
+     //重启前要保存时间
+    uapi_calendar_store_date();
     uapi_sys_shipmode(0);
 }
 void uapi_reboot_device(void)
 {
+     //重启前要保存时间
+    uapi_calendar_store_date();
     mcu_os_sys_reset(NULL,NULL);
 }
 
@@ -450,6 +453,7 @@ errcode_t uaip_cmd_update_request(void)
     } else {
         printf("uapi_upg_request_upgrade OK!!\r\n");
         /* app中下载后直接开始升级流程,升级流程结束后重启 */
+        uapi_calendar_store_date();
         /* IOT设备重启 */
         upg_reboot();
     }
@@ -2024,31 +2028,31 @@ uint32_t uapi_calendar_recover_date(void)
 #endif
 }
 
-#include "chip_system_time.h"
-void test_bandy_time(uint32_t timestamp)
-{
-    struct tm tm;
-    struct timeval tv;
-    // uint32_t time = 1716044461;  // 2024-5-18 15:1:1  网站转换:2024-05-18 23:01:01
-    printf("--------SYNC TIME----------\r\n");
-    get_current_timestamp();
-    get_current_time(&tv, &tm);
-    sync_time(timestamp, 8*4);
-    get_current_timestamp();
-    get_current_time(&tv, &tm);
-    printf("--------SAVE TIME----------\r\n");
-    get_current_timestamp();
-    get_current_time(&tv, &tm);
-    save_time();
-    get_current_timestamp();
-    get_current_time(&tv, &tm);
-    printf("--------RESTORE TIME----------\r\n");
-    get_current_timestamp();
-    get_current_time(&tv, &tm);
-    restore_time();
-    get_current_timestamp();
-    get_current_time(&tv, &tm);
-}
+// #include "chip_system_time.h"
+// void test_bandy_time(uint32_t timestamp)
+// {
+//     struct tm tm;
+//     struct timeval tv;
+//     // uint32_t time = 1716044461;  // 2024-5-18 15:1:1  网站转换:2024-05-18 23:01:01
+//     printf("--------SYNC TIME----------\r\n");
+//     get_current_timestamp();
+//     get_current_time(&tv, &tm);
+//     sync_time(timestamp, 8*4);
+//     get_current_timestamp();
+//     get_current_time(&tv, &tm);
+//     printf("--------SAVE TIME----------\r\n");
+//     get_current_timestamp();
+//     get_current_time(&tv, &tm);
+//     save_time();
+//     get_current_timestamp();
+//     get_current_time(&tv, &tm);
+//     printf("--------RESTORE TIME----------\r\n");
+//     get_current_timestamp();
+//     get_current_time(&tv, &tm);
+//     restore_time();
+//     get_current_timestamp();
+//     get_current_time(&tv, &tm);
+// }
 
 void uapi_ppg_get_id(uint8_t *chip_id)
 {
index 2f0f684..061dd06 100755 (executable)
@@ -68,6 +68,8 @@ STATIC errcode_t diag_cmd_update_start(uint16_t cmd_id, void *cmd_param, uint16_
         } else {
             uapi_diag_report_packet(cmd_id, option, (uint8_t *)&ret, (uint16_t)sizeof(errcode_t), true);
             printf("uapi_update_start_test OK!\r\n");
+            /**重启前要保存时间*/
+            uapi_calendar_store_date();
             upg_reboot();
         }
     } while (0);
index dcc38a0..c4e0254 100755 (executable)
@@ -305,6 +305,8 @@ errcode_t uapi_upg_request_upgrade(bool reset)
     }
     /* app中下载后直接开始升级流程,升级流程结束后重启 */
     if (reset) {
+        /**重启前要保存时间*/
+        uapi_calendar_store_date();
         /* IOT设备重启 */
         upg_reboot();
     }