优化睡眠模式文件存储,优化读取cywee密钥 975/1
authorpenglei <1624952103@qq.com>
Sat, 14 Sep 2024 06:29:01 +0000 (14:29 +0800)
committerpenglei <1624952103@qq.com>
Sat, 14 Sep 2024 06:29:01 +0000 (14:29 +0800)
code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h
code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp
code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp
code/sdk/drivers/peripheral/cywee/src/main_dml.c
code/sdk/drivers/peripheral/utils/custom_utils.c

index 482cb10..93a7955 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: penglei 1624952103@qq.com
  * @Date: 2024-06-26 19:36:48
  * @LastEditors: penglei 1624952103@qq.com
- * @LastEditTime: 2024-09-13 12:03:38
+ * @LastEditTime: 2024-09-14 13:04:48
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h
  * @Description:
  *
@@ -77,6 +77,7 @@ namespace OHOS
     bool read_sleep_data(SLEEP_T *data);
     void clean_sleep_data(void);
     bool create_sleep_folder(void);
+    void clean_sleep_file(void);
     // 睡眠状态
     enum class SLEEPSTATE
     {
index 6afb0f3..59041a5 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: penglei 1624952103@qq.com
  * @Date: SLEPPNOTIFY24-06-26 19:36:48
  * @LastEditors: penglei 1624952103@qq.com
- * @LastEditTime: 2024-09-13 17:00:34
+ * @LastEditTime: 2024-09-14 14:26:11
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp
  * @Description:
  *
@@ -56,6 +56,8 @@ namespace OHOS
     static NAP_T nap_data = {0};
     static SLEEP_T sleep_data = {0};
     static SLEEP_STATE_T sleep_status = {0};
+    static uint32_t sleep_update_timestamp = 0;
+    static uint32_t nap_update_timestamp = 0;
 
     bool save_nap_data(NAP_T *data)
     {
@@ -101,7 +103,16 @@ namespace OHOS
         uint32_t fall_asleep_timestamp = data->fall_asleep_timestamp;
         fwrite(&fall_asleep_timestamp, 1, 4, fp);
 
-        uint32_t wake_up_timestamp = data->wake_up_timestamp;
+
+        uint32_t wake_up_timestamp = 0;
+
+        if(data->wake_up_timestamp == 0)
+            uapi_get_timestampe_ss(&wake_up_timestamp);
+        else
+            wake_up_timestamp = data->wake_up_timestamp;
+
+        nap_update_timestamp = wake_up_timestamp;
+
         fwrite(&wake_up_timestamp, 1, 4, fp);
 
         uint16_t total_time = data->total_time;
@@ -141,6 +152,7 @@ namespace OHOS
     static uint32_t fall_asleep_timestamp = 0;
     static uint32_t history_wake_up_timestamp = 0;
     static char day[12] = {0};
+    static char dir_path[64] = {0};
 
     void clean_sleep_data(void)
     {
@@ -152,19 +164,49 @@ namespace OHOS
         memset(time_file_path,0,sizeof(time_file_path));
         memset(status_file_path,0,sizeof(status_file_path));
         memset(day,0,sizeof(day));
+        memset(dir_path,0,sizeof(dir_path));
         fall_asleep_timestamp = 0;
     }
 
+    void clean_sleep_file(void)
+    {
+        uint32_t sleep_time = get_sleep_time_from_config_model();
+        uint32_t wake_up_time = get_wake_up_time_from_config_model();
+        uint32_t sleep_min = ((sleep_time & 0xFFFF0000) >> 16) * 60 + sleep_time & 0x0000FFFF;
+        uint32_t wake_min = ((wake_up_time & 0xFFFF0000) >> 16) * 60 + wake_up_time & 0x0000FFFF;
+        if(sleep_min < wake_min)
+        {
+            uapi_delete_files(dir_path);
+        }
+    }
+
     bool create_sleep_folder(void)
     {
         struct stat info;
-        char dir_path[64] = {0};
 
         uint32_t sleep_time = get_sleep_time_from_config_model();
         uint32_t wake_up_time = get_wake_up_time_from_config_model();
-        
-        if(sleep_time > wake_up_time)
-            uapi_get_YYMMDD_Time_extend(day, '\0' , -1);
+        uint32_t sleep_min = ((sleep_time & 0xFFFF0000) >> 16) * 60 + sleep_time & 0x0000FFFF;
+        uint32_t wake_min = ((wake_up_time & 0xFFFF0000) >> 16) * 60 + wake_up_time & 0x0000FFFF;
+        uint32_t current_min = 0;
+
+        if(sleep_min > wake_min)
+        {
+            time_t rawtime;
+            struct tm* timeinfo;
+
+            time(&rawtime);
+            timeinfo = localtime(&rawtime);
+
+            current_min = timeinfo->tm_hour * 60 + timeinfo->tm_min;
+            
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "sleep_min : %d  ,wake_min : %d ,current_min : %d ", sleep_min,wake_min,current_min);
+            
+            if(current_min >= sleep_min && current_min < 24 * 60)
+                uapi_get_YYMMDD_Time_extend(day, '\0' , -1);
+            else if(current_min >= 24 * 60 && current_min < wake_min)
+                uapi_get_YYMMDD_Time_extend(day, '\0' , 0);
+        }
         else
             uapi_get_YYMMDD_Time_extend(day, '\0' , 0);
 
@@ -177,14 +219,15 @@ namespace OHOS
             }
         }
 
-        if (stat(dir_path, &info) != 0)
+        if(stat(dir_path, &info) != 0)
         {
             if (mkdir(dir_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
             {
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mkdir  fail %s", dir_path);
                 return false; // Failed to create folder
-            }
+            } 
         }
+
         return true; 
     }
 
@@ -213,14 +256,18 @@ namespace OHOS
         }
         fwrite(&fall_asleep_timestamp, 1, 4, fp);
 
-
-        uint32_t wake_up_timestamp = data->wake_up_timestamp;
-        fwrite(&wake_up_timestamp, 1, 4, fp);
+        uint32_t wake_up_timestamp = 0;
 
         if(data->wake_up_timestamp == 0)
-            total_time = data->total_time;
+            uapi_get_timestampe_ss(&wake_up_timestamp);
         else
-            total_time = (wake_up_timestamp - fall_asleep_timestamp) / 60;
+            wake_up_timestamp = data->wake_up_timestamp;
+
+        sleep_update_timestamp = wake_up_timestamp;
+
+        fwrite(&wake_up_timestamp, 1, 4, fp);
+        
+        total_time = (wake_up_timestamp - fall_asleep_timestamp) / 60;
 
         uint8_t total_time_hour = (total_time / 60);
         fwrite(&total_time_hour, 1, 1, fp);
@@ -250,10 +297,8 @@ namespace OHOS
         total_time_minute = (total_rem_sleep_time % 60);
         fwrite(&total_time_minute, 1, 1, fp);
 
-        if(data->wake_up_timestamp == 0)
-            total_wake_time = data->total_wake_time;
-        else
-            total_wake_time = total_time - total_rem_sleep_time - total_mild_sleep_time - total_deep_sleep_time;
+        total_wake_time = total_time - total_rem_sleep_time - total_mild_sleep_time - total_deep_sleep_time;
+
         total_time_hour = (total_wake_time / 60);
         fwrite(&total_time_hour, 1, 1, fp);
 
index 7cacf2f..c7a7452 100644 (file)
@@ -1215,6 +1215,7 @@ void ble_set_sleep_remind(msg_get_sleep_param_info_t data)
         //更新睡眠配置
         OHOS::SleepModel::GetInstance().set_sleep_goal();
         set_sleep_and_wake_time();
+        OHOS::clean_sleep_file();  //重设睡眠时间段 删除历史文件
         get_sleep_time_notify();
     }  
     return;
index 7ae64cb..c9978f0 100644 (file)
@@ -87,8 +87,6 @@ static uint32_t asleep_timestampe = 0;
 int cm__hs1__mac_c1_init(void);
 int cm__hs1__deinit(void);
 
-uint8_t SEC_FILE_ADDR[88] = {0};
-
 #else 
 int cm__hs1__init(void);
 int cm__hs1__deinit(void);
@@ -1116,7 +1114,12 @@ int cywee_main_dml(void)
 
     change_mac_from_chipinfo_map();
     uint16_t len = 0;
+    uint16_t *SEC_FILE_ADDR = NULL;
     uapi_cywee_get_mac_key(SEC_FILE_ADDR,&len);
+    if(SEC_FILE_ADDR == NULL)
+    {
+        CWM_OS_dbgPrintf("cywee get mac key failed !!! \r\n");
+    }
     // printf("SEC_FILE_ADDR : ");
     // for(int i = 0 ; i < 78 ; i++)
     //     printf("0x%2x, ",SEC_FILE_ADDR[i]);
@@ -1208,6 +1211,9 @@ int cywee_main_dml(void)
     osal_irq_restore(irqMask);
 #endif
     //get chip information
+#ifdef CYWEE_MAC_ACTIVE
+    free(SEC_FILE_ADDR);
+#endif
 
     memset(&scl, 0, sizeof(scl));
     scl.iData[0] = 1;
index de86dbe..697101f 100644 (file)
@@ -2315,11 +2315,9 @@ void uapi_enter_power_saving_mode(void)
     //关闭蓝牙
     if(uapi_dev_runtime_get_bt_powerstat())
     {
-        
         stop_custom_ble_service();
     }
         
-
     //关闭cat1
     if(uapi_dev_runtime_get_cat1_powerstat())
     {
@@ -2346,11 +2344,11 @@ void uapi_exit_power_saving_mode(void)
     
 
     //打开蓝牙
-    if(uapi_dev_runtime_get_bt_powerstat())
+    if(cm_custom_ble_service_on_flag())
         start_custom_ble_service();
 
     //打开cat1
-    if(uapi_dev_runtime_get_cat1_powerstat())
+    if(cm_poweron_cat1_on_bootup_flag())
         uapi_set4GCapability(true);
 
     //开启心率周期检测(runtime)
@@ -2575,12 +2573,15 @@ void uapi_get_file_data(char *path,uint8_t *data,uint16_t *len)
     }
     else
         fileSize = *len;
+    if(data == NULL)
+        data = (uint8_t *)malloc(fileSize);
 
     size_t bytesRead = fread(data, 1, fileSize, file);
     if (bytesRead != fileSize) 
     {
         PRINT("fread failed \n");
         fclose(file);
+        free(data);
         return ;
     }
     fclose(file);
@@ -2731,7 +2732,7 @@ void uapi_cywee_save_mac_key(const uint8_t *key_data,uint16_t len)
 
 #ifdef CYWEE_MAC_ACTIVE
 
-uint8_t DEFAULT_MAC_KEY[88] = {
+uint8_t DEFAULT_MAC_KEY[] = {
     0x23, 0x20, 0x86, 0xae, 0x58, 0x00, 0x00, 0x00, 0x01, 0x00, 0x1f, 0x02, 0x62, 0x0e, 0x1e, 0x25, 
     0x1f, 0x4e, 0x8b, 0x0b, 0xcc, 0xb1, 0x1f, 0x38, 0x34, 0xfa, 0x71, 0x2e, 0xa4, 0xf0, 0xbd, 0x18, 
     0x49, 0xc2, 0x6d, 0x19, 0x45, 0xfd, 0xd3, 0xbb, 0x68, 0xf8, 0x9c, 0x5a, 0xd7, 0x55, 0xbc, 0x99,