+/*
+ * @Author: penglei 1624952103@qq.com
+ * @Date: 2024-06-26 19:36:48
+ * @LastEditors: penglei 1624952103@qq.com
+ * @LastEditTime: 2024-06-28 11:17:48
+ * @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
#include <cstdint>
#include <map>
-#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_state(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:
+/*
+ * @Author: penglei 1624952103@qq.com
+ * @Date: 2024-06-26 19:36:48
+ * @LastEditors: penglei 1624952103@qq.com
+ * @LastEditTime: 2024-06-28 11:49: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 <sys/stat.h>
+
+
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)
+ {
+ if(data->fall_asleep_timestamp)
+ nap_data.fall_asleep_timestamp=data->fall_asleep_timestamp;
+
+ if(data->wake_up_timestamp)
+ nap_data.wake_up_timestamp=data->wake_up_timestamp;
+
+ if(data->total_time)
+ nap_data.total_time=data->total_time;
+
+ if(nap_data.total_time!=0 && nap_data.wake_up_timestamp!=0 && nap_data.fall_asleep_timestamp!=0 )
+ {
+ save_nap_data(&nap_data);
+ nap_data.total_time=0;
+ nap_data.wake_up_timestamp=0;
+ nap_data.fall_asleep_timestamp=0;
+ }
+ }
+
+ 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)
+ {
+ if(data->fall_asleep_timestamp)
+ sleep_data.fall_asleep_timestamp=data->fall_asleep_timestamp;
+
+ if(data->wake_up_timestamp)
+ sleep_data.wake_up_timestamp=data->wake_up_timestamp;
+
+ if(data->total_time)
+ sleep_data.total_time=data->total_time;
+
+ if(data->total_deep_sleep_time)
+ sleep_data.total_deep_sleep_time=data->total_deep_sleep_time;
+
+ if(data->total_mild_sleep_time)
+ sleep_data.total_mild_sleep_time=data->total_mild_sleep_time;
+
+ if(data->total_rem_sleep_time)
+ sleep_data.total_rem_sleep_time=data->total_rem_sleep_time;
+
+ if(data->total_wake_time)
+ sleep_data.total_wake_time=data->total_wake_time;
+
+ save_sleep_data(&sleep_data);
+ memset(&sleep_data,0,sizeof(SLEEP_T));
+ }
+
+ void set_sleep_state(SLEEP_STATE_T *data)
+ {
+ memset(&sleep_status,0,sizeof(SLEEP_STATE_T));
+
+ if(data->timestamp)
+ sleep_status.timestamp=data->timestamp;
+
+ if(data->stat)
+ sleep_status.stat=data->stat;
+
+ //save_sleep_data(&sleep_status);
+ }
+
+ uint32_t read_sleep_data(char *data,uint32_t size,FILE *fp)
+ {
+ return fread(data,1,size,fp);
+ }
+
+ void GetSleepTime(); // 获取睡眠时间
+
+
SleepModel::SleepModel() {}
SleepModel::~SleepModel() {}
SleepModel &SleepModel::GetInstance()
${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
${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
#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"
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)
{
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)
(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_state(&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;
}
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));
+ 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));
}
//APP运动相关