重新打开宏“CYWEE_MAC_ACTIVE” ,修复回退导致的BUG 优。化cywee开机读取密钥 984/1 984/head
authorpenglei <1624952103@qq.com>
Wed, 18 Sep 2024 09:43:58 +0000 (17:43 +0800)
committerpenglei <1624952103@qq.com>
Wed, 18 Sep 2024 09:43:58 +0000 (17:43 +0800)
code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp
code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp
code/sdk/build/config/target_config/brandy/config.py
code/sdk/drivers/peripheral/cywee/src/main_dml.c
code/sdk/drivers/peripheral/utils/custom_utils.c
code/sdk/drivers/peripheral/utils/custom_utils.h

index 11df8ec..c680a35 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-14 14:59:37
+ * @LastEditTime: 2024-09-18 16:54:42
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp
  * @Description:
  *
@@ -233,6 +233,8 @@ namespace OHOS
 
     bool save_sleep_data(SLEEP_T *data)
     {
+        bool ephemeral_data = false; //临时数据标志
+
         if(access(time_file_path, F_OK) == -1)
         {
             memset(time_file_path,0,sizeof(time_file_path));
@@ -312,6 +314,7 @@ namespace OHOS
             total_deep_sleep_time -= data->total_deep_sleep_time;
             total_mild_sleep_time -= data->total_mild_sleep_time;
             total_rem_sleep_time -= data->total_rem_sleep_time;
+            ephemeral_data = true;
         }
 
         if(access(status_file_path, F_OK) == -1)
@@ -336,7 +339,7 @@ namespace OHOS
                 return false;
             }
 
-            if(history_wake_up_timestamp != data->wake_up_timestamp && ((data->fall_asleep_timestamp - history_wake_up_timestamp) < 2 * 60 * 60))
+            if(!ephemeral_data && history_wake_up_timestamp != data->wake_up_timestamp && ((data->fall_asleep_timestamp - history_wake_up_timestamp) < 2 * 60 * 60))
             {
                 fseek(fp, -sizeof(SLEEP_STATE_T), SEEK_END);
                 SLEEP_STATE_T sleep_status = {0,0};
@@ -347,7 +350,14 @@ namespace OHOS
                 fwrite(&data->sleep_status[1], sizeof(SLEEP_STATE_T), data->status_num - 1, fp); //跳过入睡状态写入文件
             }
             else
+            {
+                if(data->wake_up_timestamp != 0)
+                {
+                    history_wake_up_timestamp = data->wake_up_timestamp; //更新历史出睡时间戳
+                }
                 fwrite(data->sleep_status, sizeof(SLEEP_STATE_T), data->status_num, fp);
+            }
+
         }
         fclose(fp);
         return true;
index fcef14f..23fec06 100644 (file)
@@ -506,6 +506,7 @@ static SLEEP_T sleep_data = {0};
 static NAP_T nap_data = {0};
 static int state_num = 0;
 static uint32_t day_timestamp = 0;
+static uint32_t current_day = 0;
 static uint8_t fall_asleep_state_num = 0;
 #endif
 
@@ -1253,6 +1254,7 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req)
         timeinfo = localtime(&rawtime);
         uapi_get_timestampe_ss(&timestamp);
         day_timestamp = timestamp - (timeinfo->tm_hour * 60 * 60 + timeinfo->tm_min * 60 + timeinfo->tm_sec);
+        current_day = timeinfo->tm_mday;
     }
 #endif
     OHOS::SLEEP_STATE_T state_data = {0};
@@ -1312,6 +1314,10 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req)
             if(state_num < SLEEP_STATUS_LENGTH)
             {
                 sleep_data.sleep_status[state_num].timestamp = day_timestamp + cywee_Inactivity_Info->hour * 60 * 60 + cywee_Inactivity_Info->minute * 60;
+                if(current_day != cywee_Inactivity_Info->day)
+                {
+                    sleep_data.sleep_status[state_num].timestamp -= 24 * 60 * 60;
+                }
                 sleep_data.sleep_status[state_num].stat = cywee_Inactivity_Info->status;
                 if(sleep_data.sleep_status[state_num].stat == 7 || sleep_data.sleep_status[state_num].stat == 13)
                 {
@@ -1321,7 +1327,7 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req)
                 if(sleep_data.sleep_status[state_num].stat == 0) //0进入睡眠  1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 8未出睡最后一笔输出 12快速动眼 13取消入睡
                 {
                     sleep_data.fall_asleep_timestamp = sleep_data.sleep_status[state_num].timestamp;
-                    fall_asleep_state_num = state_num;
+                    //fall_asleep_state_num = state_num;
                 }
                 else if(sleep_data.sleep_status[state_num].stat == 4)
                 {
@@ -1364,7 +1370,7 @@ void MsgCenterNotifyInactivityAccumulateTimeProc(const Topic topic, Request* req
     {
         memset(&sleep_data,0,sizeof(SLEEP_T));
         state_num = 0;
-        fall_asleep_state_num = 0;
+        //fall_asleep_state_num = 0;
         uapi_dev_runtime_set_absolute_static_status(0);
         return;
     }
@@ -1393,11 +1399,11 @@ void MsgCenterNotifyInactivityAccumulateTimeProc(const Topic topic, Request* req
     }
     else if(cywee_Inactivity_Accumulate_Time_Info->output_number == INACTIVITY_MODE_SLEEPING_ACCUMULATE_TIME_OUTPUT)
     {
-        if(sleep_data.fall_asleep_timestamp > sleep_data.wake_up_timestamp)
-        {
-            sleep_data.fall_asleep_timestamp -= 24 * 60 * 60;
-            sleep_data.sleep_status[fall_asleep_state_num].timestamp = sleep_data.fall_asleep_timestamp;
-        }
+        // if(sleep_data.fall_asleep_timestamp > sleep_data.wake_up_timestamp && sleep_data.wake_up_timestamp != 0)
+        // {
+        //     sleep_data.fall_asleep_timestamp -= 24 * 60 * 60;
+        //     sleep_data.sleep_status[fall_asleep_state_num].timestamp = sleep_data.fall_asleep_timestamp;
+        // }
 
         sleep_data.total_time = cywee_Inactivity_Accumulate_Time_Info->total_time;
         sleep_data.total_deep_sleep_time = cywee_Inactivity_Accumulate_Time_Info->total_deep_sleep_time;
@@ -1409,7 +1415,7 @@ void MsgCenterNotifyInactivityAccumulateTimeProc(const Topic topic, Request* req
         set_sleep_data(&sleep_data);
         memset(&sleep_data,0,sizeof(SLEEP_T));
         state_num = 0;
-        fall_asleep_state_num = 0;
+        //fall_asleep_state_num = 0;
     }
 #endif
     free(cywee_Inactivity_Accumulate_Time_Info);
index 00210aa..ea4db77 100755 (executable)
@@ -143,7 +143,7 @@ target = {
                     #"MEM_CHECK",
                     #'ENABLE_WEBSOCKET',
                     'CYWEE_SPORT',
-                    #'CYWEE_MAC_ACTIVE',
+                    'CYWEE_MAC_ACTIVE',
                     'SUPPORT_TCPIP',                                   
                     'SUPPORT_HID_SERVICE',
                     'SUPPORT_BAIDU_MAP',
index c9978f0..a4ce7f8 100644 (file)
@@ -1113,15 +1113,14 @@ 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);
+
+    uint8_t *SEC_FILE_ADDR = uapi_cywee_get_mac_key();
     if(SEC_FILE_ADDR == NULL)
     {
-        CWM_OS_dbgPrintf("cywee get mac key failed !!! \r\n");
+        CWM_OS_dbgPrintf("cywee get mac key failed !!!\r\n");
     }
     // printf("SEC_FILE_ADDR : ");
-    // for(int i = 0 ; i < 78 ; i++)
+    // for(int i = 0 ; i < len ; i++)
     //     printf("0x%2x, ",SEC_FILE_ADDR[i]);
     // printf("\n");
 #endif
@@ -1212,7 +1211,11 @@ int cywee_main_dml(void)
 #endif
     //get chip information
 #ifdef CYWEE_MAC_ACTIVE
-    free(SEC_FILE_ADDR);
+    if(SEC_FILE_ADDR != NULL)
+    {
+        free(SEC_FILE_ADDR);
+    }
+
 #endif
 
     memset(&scl, 0, sizeof(scl));
index 554d4fc..5953930 100644 (file)
@@ -2734,14 +2734,42 @@ uint8_t DEFAULT_MAC_KEY[] = {
     0xaf, 0x57, 0xb7, 0xc3, 0x46, 0x93, 0x75, 0x10,  
 };
 #endif
-void uapi_cywee_get_mac_key(uint8_t *key_data,uint16_t *len)
+uint8_t* uapi_cywee_get_mac_key(void)
 {
 #ifdef CYWEE_MAC_ACTIVE
     if(access(CYWEE_MAC_KEY_PATH, F_OK) == -1)
     {
         uapi_save_file_data(CYWEE_MAC_KEY_PATH,DEFAULT_MAC_KEY,sizeof(DEFAULT_MAC_KEY),"wb");
     }
-    uapi_get_file_data(CYWEE_MAC_KEY_PATH,key_data,len);
+    // uapi_get_file_data(CYWEE_MAC_KEY_PATH,key_data,len);
+    FILE *file;
+    uint16_t fileSize;
+    uint8_t *data = NULL;
+    file = fopen(CYWEE_MAC_KEY_PATH, "rb"); 
+    if (file == NULL) 
+    {
+        PRINT("read open %s failed\n",CYWEE_MAC_KEY_PATH);
+        return NULL;
+    }
+
+    // 获取文件大小
+    fseek(file, 0, SEEK_END);
+    fileSize = ftell(file);
+    fseek(file, 0, SEEK_SET);
+
+    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 NULL;
+    }
+    fclose(file);
+    return data;
 #endif
 }
 
index 7cf7933..ae607ed 100644 (file)
@@ -248,7 +248,7 @@ void uapi_cywee_time_sync(void);
 void uapi_cywee_get_chipinfo(char *databuf,uint8_t len);
 void uapi_cywee_get_version(char *databuf,uint8_t len);
 void uapi_cywee_save_mac_key(const uint8_t *key_data,uint16_t len);
-void uapi_cywee_get_mac_key(uint8_t *key_data,uint16_t *len);
+uint8_t* uapi_cywee_get_mac_key(void);
 void uapi_get_sleep_date_on_log(char *time);
 void uapi_ppg_get_id(uint8_t *chip_id);