From 99d95b3f893b6d0710fd1b81b258f01dc3620125 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=BD=AD=E7=A3=8A?= <1624952103@qq.com> Date: Wed, 18 Sep 2024 09:52:53 +0000 Subject: [PATCH] Merge #984 into sdk602patch0626 from refs/changes/984/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from 彭磊 * refs/changes/984/head: (5 commits squashed) - 修复g_chipinfo_map映射关系填写错误BUG - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 - Merge branch 'sdk602patch0626' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0626 - 重新打开宏“CYWEE_MAC_ACTIVE” ,修复回退导致的BUG 优。化cywee开机读取密钥 Signed-off-by: aliyun6865282430 <1624952103@qq.com> Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/984 --- .../nativeui/sleep/src/SleepModel.cpp | 14 ++++++-- .../msg_center/src/msg_center_customer.cpp | 22 ++++++++----- .../config/target_config/brandy/config.py | 2 +- .../drivers/peripheral/cywee/src/main_dml.c | 15 +++++---- .../drivers/peripheral/utils/custom_utils.c | 32 +++++++++++++++++-- .../drivers/peripheral/utils/custom_utils.h | 2 +- 6 files changed, 67 insertions(+), 20 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp index 11df8ec5f..c680a35b3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp @@ -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; diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp index fcef14f5e..23fec06b6 100644 --- a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp @@ -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(×tamp); 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); diff --git a/code/sdk/build/config/target_config/brandy/config.py b/code/sdk/build/config/target_config/brandy/config.py index 00210aa45..ea4db77e9 100755 --- a/code/sdk/build/config/target_config/brandy/config.py +++ b/code/sdk/build/config/target_config/brandy/config.py @@ -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', diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index c9978f022..a4ce7f8b5 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -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)); diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 554d4fccf..59539301b 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -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 } diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index 7cf7933ef..ae607ed03 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -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); -- 2.17.1