From f78a43aee77b680c7c9b470bf3f228c1f695aebb Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Sat, 14 Sep 2024 14:29:01 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E7=9D=A1=E7=9C=A0=E6=A8=A1?= =?utf8?q?=E5=BC=8F=E6=96=87=E4=BB=B6=E5=AD=98=E5=82=A8=EF=BC=8C=E4=BC=98?= =?utf8?q?=E5=8C=96=E8=AF=BB=E5=8F=96cywee=E5=AF=86=E9=92=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/sleep/include/SleepModel.h | 3 +- .../nativeui/sleep/src/SleepModel.cpp | 79 +++++++++++++++---- .../service/ble_service/blemoder/bletest.cpp | 1 + .../drivers/peripheral/cywee/src/main_dml.c | 10 ++- .../drivers/peripheral/utils/custom_utils.c | 11 +-- 5 files changed, 79 insertions(+), 25 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h index 482cb102c..93a7955ba 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h @@ -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 { 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 6afb0f371..59041a56c 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-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); diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp index 7cacf2fa4..c7a7452bf 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -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; diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index 7ae64cbc6..c9978f022 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -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; diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index de86dbea4..697101f58 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -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, -- 2.17.1