From 3941794b61a85548fc1100ca685ad37d7f30e4dd Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=BD=AD=E7=A3=8A?= <1624952103@qq.com> Date: Fri, 28 Jun 2024 07:37:01 +0000 Subject: [PATCH] Merge #398 into sdk602patch0521 from refs/changes/398/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 优化小睡消息接收处理 * refs/changes/398/head: (2 commits squashed) - 优化小睡消息接收处理 - 补交 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/398 --- .../nativeui/sleep/include/SleepModel.h | 61 ++++++++++- .../nativeui/sleep/src/SleepModel.cpp | 103 ++++++++++++++++++ .../service/msg_center/CMakeLists.txt | 3 +- .../msg_center/src/msg_center_customer.cpp | 92 ++++++++++++++-- 4 files changed, 246 insertions(+), 13 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 ecab3d9ea..1c1f9e53d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h @@ -1,3 +1,13 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-06-26 19:36:48 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2024-06-28 14:25:40 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h + * @Description: + * + * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. + */ /*** * @Date: 2024-06-25 10:34:10 * @LastEditors: Caisking 3449750381@qq.com @@ -10,13 +20,56 @@ #include #include -#include "AppViewIDs.h" -#include "UiConfig.h" -#include "sleep/include/SleepView.h" -#include "sleep/include/SleepControlPresenter.h" +//#include "AppViewIDs.h" +//#include "UiConfig.h" +//#include "sleep/include/SleepView.h" +//#include "sleep/include/SleepControlPresenter.h" #include "string" + + +#define SLEEP_PATH "user/userdata/sleep/%s/sleep_%d.bin" + +#define SLEEP_DIR_PATH "user/userdata/sleep/%s" + + namespace OHOS { + typedef struct + { + uint32_t fall_asleep_timestamp; //入睡 + uint32_t wake_up_timestamp; //出睡 + uint16_t total_time; //总时长 + } NAP_T; + + typedef struct + { + uint32_t fall_asleep_timestamp; //入睡 + uint32_t wake_up_timestamp; //出睡 + uint16_t total_time; //总时长 + uint16_t total_deep_sleep_time;//深睡 + uint16_t total_mild_sleep_time;//浅睡 + uint16_t total_rem_sleep_time;//清醒 + uint16_t total_wake_time;//动眼 + } SLEEP_T; + + typedef struct + { + uint32_t timestamp; // + uint8_t stat; //状态 + + } SLEEP_STATE_T; + + bool save_nap_data(NAP_T *data); + + uint32_t read_nap_data(char *data,uint32_t size,FILE *fp); + + void set_nap_data(NAP_T *data); + + void set_sleep_data(SLEEP_T *data); + void set_sleep_status(SLEEP_STATE_T *data); + uint32_t read_sleep_data(char *data,uint32_t size,FILE *fp); + bool save_sleep_data(SLEEP_T *data); + class SleepModel { public: 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 56870521c..0658e48fb 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp @@ -1,10 +1,113 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-06-26 19:36:48 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2024-06-28 14:34:42 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp + * @Description: + * + * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. + */ #include "sleep/include/SleepModel.h" #include "kv_store.h" #include "securec.h" +#include "sleep/include/SleepControlPresenter.h" +#include "custom_utils.h" +#include + + namespace OHOS { + static NAP_T nap_data = {0}; + static SLEEP_T sleep_data = {0}; + static SLEEP_STATE_T sleep_status = {0}; + bool save_nap_data(NAP_T *data) + { + struct stat info; + char dir_path[64]={0}; + char file_path[64]={0}; + char day[12]={0}; + uapi_get_YYMMDD_Time(day,'\0'); + + sprintf_s(dir_path,64,SLEEP_DIR_PATH,day); + if (stat(dir_path, &info) != 0) + { + if (mkdir(dir_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) + { + return false; // Failed to create folder + } + } + uint32_t creationTime; + int ret =uapi_get_timestampe_ss(&creationTime); + + sprintf_s(file_path,64,SLEEP_PATH,day,creationTime); + + FILE *fp; + fp=fopen(file_path,"wb+"); + if(fp==NULL) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "save_nap_sleep_data fopen fail"); + return false; + } + + uint8_t sleep_type=0; + fwrite(&sleep_type,1,1,fp); + + 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; + fwrite(&wake_up_timestamp,1,4,fp); + + uint16_t total_time=data->total_time; + fwrite(&total_time,1,2,fp); + + + + fclose(fp); + return true; + + } + + void set_nap_data(NAP_T *data) + { + memset(&nap_data,0,sizeof(NAP_T)); + memcpy_s(&nap_data,sizeof(NAP_T),data,sizeof(NAP_T)); + save_nap_data(&nap_data); + } + + uint32_t read_nap_data(char *data,uint32_t size,FILE *fp) + { + return fread(data,1,size,fp); + } + + bool save_sleep_data(SLEEP_T *data) + { + return true; + } + + void set_sleep_data(SLEEP_T *data) + { + memset(&sleep_data,0,sizeof(SLEEP_T)); + memcpy_s(&sleep_data,sizeof(SLEEP_T),data,sizeof(SLEEP_T)); + save_sleep_data(&sleep_data); + } + + void set_sleep_status(SLEEP_STATE_T *data) + { + memset(&sleep_status,0,sizeof(SLEEP_STATE_T)); + memcpy_s(&sleep_status,sizeof(SLEEP_STATE_T),data,sizeof(SLEEP_STATE_T)); + + //save_sleep_data(&sleep_status); + } + + uint32_t read_sleep_data(char *data,uint32_t size,FILE *fp) + { + return fread(data,1,size,fp); + } + SleepModel::SleepModel() {} SleepModel::~SleepModel() {} SleepModel &SleepModel::GetInstance() diff --git a/code/sdk/application/wearable/service/msg_center/CMakeLists.txt b/code/sdk/application/wearable/service/msg_center/CMakeLists.txt index 0fe23e29a..60cfd4e42 100644 --- a/code/sdk/application/wearable/service/msg_center/CMakeLists.txt +++ b/code/sdk/application/wearable/service/msg_center/CMakeLists.txt @@ -14,6 +14,7 @@ set(PRIVATE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/../../nativeapp/nativeui/phoneservice/include ${CMAKE_CURRENT_SOURCE_DIR}/../../fd230app/nativeui/producttest/include ${CMAKE_CURRENT_SOURCE_DIR}/../../fd230app/nativeui/system/include + ${CMAKE_CURRENT_SOURCE_DIR}/../../fd230app/nativeui/sleep/include ${CMAKE_CURRENT_SOURCE_DIR}/../../fd230app/nativeui/config/include ${CMAKE_CURRENT_SOURCE_DIR}/../../fd230app/nativeui/main/include/dial ${CMAKE_CURRENT_SOURCE_DIR}/../../fd230app/nativeui/bloodoxygen/include @@ -111,7 +112,7 @@ set(PRIVATE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/../../nativeapp/nativeui/alarmclocktimerconfig/include ${CMAKE_CURRENT_SOURCE_DIR}/../../nativeapp/nativeui/alarm/include ${CMAKE_CURRENT_SOURCE_DIR}/../../fd230app/nativeui/system/include - + ${CMAKE_CURRENT_SOURCE_DIR}/../../fd230app/nativeui/sleep/include ${CMAKE_CURRENT_SOURCE_DIR}/../../fd230app/nativeui/producttest/include ${CMAKE_CURRENT_SOURCE_DIR}/../../fd230app/nativeui/phone/include ${CMAKE_CURRENT_SOURCE_DIR}/../../fd230app/nativeui/config/include 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 22a1d2842..f03333e03 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 @@ -38,6 +38,8 @@ #include "bletest.h" //#include "TraingCardPresenter.h" #include "custom_runtime.h" +#include "custom_utils.h" +#include "SleepModel.h" #ifdef FD230 #include "DialModelCharge.h" #include "DialModelHeartRate.h" @@ -949,7 +951,7 @@ void MsgCenterNotifyActivityProc(const Topic topic, Request* req) return; } - int rets = memcpy_s(c_activity_result_t, req->len, (cywee_activity_result_t*)req->data, req->len); + int rets = memcpy_s(c_activity_result_t, req->len, (cywee_activity_result_t*)req->data, req->len); if (rets != EOK) { free(c_activity_result_t); @@ -967,6 +969,8 @@ void MsgCenterNotifyActivityProc(const Topic topic, Request* req) if(c_activity_result_t->MHR_zone>=2) set_fat_time_data(); + free(c_activity_result_t); + c_activity_result_t = NULL; } void MsgCenterNotifyActivityExtraInfoProc(const Topic topic, Request* req) @@ -974,12 +978,15 @@ void MsgCenterNotifyActivityExtraInfoProc(const Topic topic, Request* req) unused(topic); } +static SLEEP_T sleep_data = {0}; +static NAP_T nap_data = {0}; + void MsgCenterNotifyInactivityProc(const Topic topic, Request *req) { WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyInactivityProc !"); unused(topic); - PRINT("request %d\r\n", req->msgId); - + uint32_t timestamp = 0; + OHOS::SLEEP_STATE_T state_data = {0}; cywee_inactivity_result_t *cywee_Inactivity_Info = (cywee_inactivity_result_t *)malloc(req->len); if (!cywee_Inactivity_Info) { @@ -996,12 +1003,7 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req) return; } - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "cywee_Inactivity_Info->sedentary_status = %d, stand_freq = %d", cywee_Inactivity_Info->status, cywee_Inactivity_Info->stand_freq); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "cywee_Inactivity_Info->output_number = %d", cywee_Inactivity_Info->output_number); - if(cywee_Inactivity_Info->status==9) - { - set_stand_falg(); - } static int interval = 0;//久坐间隔时间 switch (cywee_Inactivity_Info->output_number) @@ -1016,8 +1018,45 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req) (SedentaryReminderViewEventListener::GetInstance().IsReminderTime() == true)) { NotificationManager::GetInstance()->ShowNotify(showSedentaryReminderNotify, (uint16_t)topic, true); } + } + else if(cywee_Inactivity_Info->status==9) + { + set_stand_falg(); + } + break; + + //睡眠 + case INACTIVITY_MODE_SLEEPING_OUTPUT: + + uapi_get_timestampe_ss(×tamp); + state_data.timestamp = timestamp; + state_data.stat = cywee_Inactivity_Info->status; + set_sleep_status(&state_data); + + if(cywee_Inactivity_Info->status == 6) //0进入睡眠 1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 8未出睡最后一笔输出 12快速动眼 13取消入睡 + { + sleep_data.fall_asleep_timestamp = timestamp; + } + else if(cywee_Inactivity_Info->status == 14) + { + sleep_data.wake_up_timestamp = timestamp; } break; + + //小睡 + case INACTIVITY_MODE_NAP_OUTPUT: + if(cywee_Inactivity_Info->status == 6) //0进入睡眠 1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 8未出睡最后一笔输出 12快速动眼 13取消入睡 + { + uapi_get_timestampe_ss(×tamp); + nap_data.fall_asleep_timestamp = timestamp; + } + else if(cywee_Inactivity_Info->status == 14) + { + uapi_get_timestampe_ss(×tamp); + nap_data.wake_up_timestamp = timestamp; + } + break; + default: break; } @@ -1029,6 +1068,43 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req) void MsgCenterNotifyInactivityAccumulateTimeProc(const Topic topic, Request* req) { unused(topic); + + cywee_inactivity_accumulate_time_t *cywee_Inactivity_Accumulate_Time_Info = (cywee_inactivity_accumulate_time_t *)malloc(req->len); + if (!cywee_Inactivity_Accumulate_Time_Info) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Memory allocation failure"); + return; + } + + int rets = memcpy_s(cywee_Inactivity_Accumulate_Time_Info, req->len, (cywee_inactivity_accumulate_time_t*)req->data, req->len); + if (rets != EOK) + { + free(cywee_Inactivity_Accumulate_Time_Info); + cywee_Inactivity_Accumulate_Time_Info = NULL; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "memcpy_s cywee_Inactivity_Accumulate_Time_Info failed, ret = %d", rets); + return; + } + + if(nap_data.wake_up_timestamp != 0) + { + nap_data.total_time = cywee_Inactivity_Accumulate_Time_Info->total_time; + set_nap_data(&nap_data); + memset(&nap_data,0,sizeof(NAP_T)); + free(cywee_Inactivity_Accumulate_Time_Info); + cywee_Inactivity_Accumulate_Time_Info = NULL; + return ; + } + + 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; + sleep_data.total_mild_sleep_time = cywee_Inactivity_Accumulate_Time_Info->total_mild_sleep_time; + sleep_data.total_wake_time = cywee_Inactivity_Accumulate_Time_Info->total_wake_time; + sleep_data.total_rem_sleep_time = cywee_Inactivity_Accumulate_Time_Info->total_rem_sleep_time; + + set_sleep_data(&sleep_data); + memset(&sleep_data,0,sizeof(SLEEP_T)); + free(cywee_Inactivity_Accumulate_Time_Info); + cywee_Inactivity_Accumulate_Time_Info = NULL; } //APP运动相关 -- 2.17.1