From 3287d560c3eaec976c3f6679a85639663d239304 Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Sun, 20 Oct 2024 13:03:42 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E6=94=B9=E7=9D=A1=E7=9C=A0=E6=96=87?= =?utf8?q?=E4=BB=B6=E5=AD=98=E5=82=A8=EF=BC=8C=E7=A7=BB=E6=A4=8Ddml?= =?utf8?q?=E5=BA=95=E5=B1=82=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../src/AlarmClockTimerConfig.cpp | 8 +- .../nativeui/sleep/include/SleepModel.h | 23 +- .../nativeui/sleep/src/SleepModel.cpp | 422 +----------------- .../msg_center/src/msg_center_customer.cpp | 158 +++---- .../drivers/peripheral/cywee/Inc/cywee_hal.h | 12 + .../drivers/peripheral/cywee/src/main_dml.c | 375 ++++++++++++++-- .../utils/custom_fileoperate_service.c | 6 +- .../drivers/peripheral/utils/custom_utils.c | 30 ++ .../drivers/peripheral/utils/custom_utils.h | 4 +- 9 files changed, 486 insertions(+), 552 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp b/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp index 7f7190b8b..fa223de82 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp @@ -509,10 +509,10 @@ extern "C" int cmd = 1; uapi_dev_runtime_set_sleep_status(0); // 清零睡眠状态 uapi_dev_runtime_set_absolute_static_status(0); // 清零绝对静止状态 - OHOS::clean_sleep_data(); // 清零睡眠文件存储数据 - if(uapi_dev_runtime_get_nap_monitoring_status() == 1) - uapi_clean_sleep_flag(); // 清除睡眠标志文件 - OHOS::create_sleep_folder(); // 创建睡眠文件夹 + // OHOS::clean_sleep_data(); // 清零睡眠文件存储数据 + // if(uapi_dev_runtime_get_nap_monitoring_status() == 1) + // uapi_clean_sleep_flag(); // 清除睡眠标志文件 + // OHOS::create_sleep_folder(); // 创建睡眠文件夹 set_keep_in_wear_det_mode(0); do_cywee_service_check_msg(CYWEE_SERVICE_CMD_GET_SLEEP_DATA, &cmd); // 强制获取小睡数据,结束小睡 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 d087ca152..7510fb813 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h @@ -33,37 +33,24 @@ namespace OHOS typedef struct { - uint32_t timestamp; // - uint8_t stat; // 状态 - - } SLEEP_STATE_T; - - typedef struct - { - SLEEP_STATE_T sleep_status[SLEEP_STATUS_LENGTH]; - uint8_t status_num; 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; #pragma pack (pop) - bool save_nap_data(NAP_T *data); - uint32_t get_nap_data_size(void); + // bool save_nap_data(NAP_T *data); + // uint32_t get_nap_data_size(void); // bool sleep_mutex_init(void); uint32_t read_sleep_nap_data(char *data, uint32_t size, FILE *fp); void set_nap_data(NAP_T *data); void set_sleep_data(SLEEP_T *data); - bool save_sleep_data(SLEEP_T *data); + // bool save_sleep_data(SLEEP_T *data); bool read_sleep_data(SLEEP_T *data); bool read_nap_data(NAP_T *data); - void clean_sleep_data(void); - bool create_sleep_folder(void); + // void clean_sleep_data(void); + // bool create_sleep_folder(void); std::string get_sleep_asleep_time_str(void); std::string get_sleep_wake_time_str(void); //void clean_sleep_file(void); 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 f46bd88a7..9bc522921 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-10-14 15:41:13 + * @LastEditTime: 2024-10-19 18:48:26 * @FilePath: * /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp * @Description: @@ -59,31 +59,10 @@ 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; - // static uint8_t sleep_mutex_installed = 0; - // static osal_mutex sleep_mutex; - - // bool sleep_mutex_init(void) - // { - // if (sleep_mutex_installed == 1) - // return true; - - // if (sleep_mutex_installed == 0) - // { - // errcode_t ret = osal_mutex_init(&sleep_mutex); - // if (ret != ERRCODE_SUCC) - // { - // PRINT("sleep_mutex lock fail! ret=0x%x\n", ret); - // return false; - // } - // sleep_mutex_installed = 1; - // } - // return true; - // } - /*获取最新睡眠时间戳*/ uint32_t get_sleep_update_timestamp(void) { @@ -95,379 +74,6 @@ namespace OHOS static char nap_file_path[64] = {0}; - //获取小睡数据长度(协议用) - uint32_t get_nap_data_size(void) - { - FILE *fp; - uint32_t size = 0; - fp = fopen(nap_file_path, "rb"); - if (fp == NULL) - { - PRINT("read open %s failed\n",nap_file_path); - return 0; - } - // 获取文件大小 - fseek(fp, 0, SEEK_END); - size = ftell(fp); - fclose(fp); - return size; - } - - 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("user/userdata/sleep", &info) != 0) - { - if (mkdir("user/userdata/sleep", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) - { - return false; // Failed to create folder - } - } - - 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 - } - } - - sprintf_s(nap_file_path, 64, NAP_PATH, day); - - uint32_t size = get_nap_data_size(); - - FILE *fp; - fp = fopen(nap_file_path, "ab+"); //小睡数据全部存入一个文件 - if(fp==NULL) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "save_nap_sleep_data %s fopen fail ", nap_file_path); - return false; - } - - uint8_t id=size/14+1; - - uint16_t nap_size=12; - fwrite(&nap_size, 1, 2, fp); - - fwrite(&id, 1, 1, fp); - - 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 = 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; - - uint8_t total_time_hour = (total_time / 60); - fwrite(&total_time_hour, 1, 1, fp); - - uint8_t total_time_minute = (total_time % 60); - fwrite(&total_time_minute, 1, 1, fp); - - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "save_nap_sleep_data succ"); - - 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)); - } - - uint32_t read_sleep_nap_data(char *data, uint32_t size, FILE *fp) - { - return fread(data, 1, size, fp); - } - - static uint16_t total_time = 0; - static uint16_t total_deep_sleep_time = 0; - static uint16_t total_mild_sleep_time = 0; - static uint16_t total_rem_sleep_time = 0; - static uint16_t total_wake_time = 0; - static char time_file_path[64] = {0}; - static char status_file_path[64] = {0}; - - 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) - { - total_time = 0; - total_deep_sleep_time = 0; - total_mild_sleep_time = 0; - total_rem_sleep_time = 0; - total_wake_time = 0; - 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; - memset(nap_file_path, 0, sizeof(nap_file_path)); - } - - // 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; - - 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; - 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 >= 0 && current_min < wake_min) - uapi_get_YYMMDD_Time_extend(day, '\0', 0); - } - else - uapi_get_YYMMDD_Time_extend(day, '\0', 0); - - sprintf_s(dir_path, 64, SLEEP_DIR_PATH, day); - if (stat("user/userdata/sleep", &info) != 0) - { - if (mkdir("user/userdata/sleep", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != - 0) - { - return false; // Failed to create folder - } - } - - 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; - } - - bool save_sleep_data(SLEEP_T *data) - { - // errcode_t ret; - // ret = osal_mutex_lock(&sleep_mutex); - // if (ret != ERRCODE_SUCC) - // { - // PRINT(" sleep_mutex lock fail! ret=0x%x\n", ret); - // return false; - // } - - if (access(time_file_path, F_OK) == -1) - { - memset(time_file_path, 0, sizeof(time_file_path)); - sprintf_s(time_file_path, 64, SLEEP_TIME_PATH, day); - } - - FILE *fp; - fp = fopen(time_file_path, "wb+"); - if (fp == NULL) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "save_sleep_data fopen fail"); - return false; - } - - uint8_t sleep_type = 1; - fwrite(&sleep_type, 1, 1, fp); - - if (fall_asleep_timestamp == 0) - { - fall_asleep_timestamp = data->fall_asleep_timestamp; - } - fwrite(&fall_asleep_timestamp, 1, 4, fp); - - 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; - - 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); - - uint8_t total_time_minute = (total_time % 60); - fwrite(&total_time_minute, 1, 1, fp); - - total_deep_sleep_time += data->total_deep_sleep_time; - - total_time_hour = (total_deep_sleep_time / 60); - fwrite(&total_time_hour, 1, 1, fp); - - total_time_minute = (total_deep_sleep_time % 60); - fwrite(&total_time_minute, 1, 1, fp); - - total_mild_sleep_time += data->total_mild_sleep_time; - total_time_hour = (total_mild_sleep_time / 60); - fwrite(&total_time_hour, 1, 1, fp); - - total_time_minute = (total_mild_sleep_time % 60); - fwrite(&total_time_minute, 1, 1, fp); - - total_rem_sleep_time += data->total_rem_sleep_time; - total_time_hour = (total_rem_sleep_time / 60); - fwrite(&total_time_hour, 1, 1, fp); - - total_time_minute = (total_rem_sleep_time % 60); - fwrite(&total_time_minute, 1, 1, fp); - - 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); - - total_time_minute = (total_wake_time % 60); - fwrite(&total_time_minute, 1, 1, fp); - - fclose(fp); - - if (data->wake_up_timestamp == 0) // 临时数据清掉 - { - 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; - } - - if (access(status_file_path, F_OK) == -1) // 文件不存在 直接写入 - { - memset(status_file_path, 0, sizeof(status_file_path)); - sprintf_s(status_file_path, 64, SLEEP_STATUS_PATH, day); - fp = fopen(status_file_path, "wb+"); - if (fp == NULL) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "save_sleep_data fopen fail"); - // osal_mutex_unlock(&sleep_mutex); - return false; - } - // if(wake_up_timestamp != 0) - // { - // history_wake_up_timestamp = wake_up_timestamp; //更新历史出睡时间戳 - // } - fwrite(data->sleep_status, sizeof(SLEEP_STATE_T), data->status_num, fp); - } - else // 文件已存在 需要判断是否需要补上清醒状态 - { - fp = fopen(status_file_path, "rb+"); - if (fp == NULL) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "save_sleep_data fopen fail"); - // osal_mutex_unlock(&sleep_mutex); - return false; - } - // fwrite(data->sleep_status, sizeof(SLEEP_STATE_T), data->status_num, fp); - - // 如果本次出睡时间与历史出睡时间不等 且两次睡眠间隔小于2小时 补上清醒状态 - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, - "history_wake_up_timestamp : %d wake_up_timestamp : %d\n", - history_wake_up_timestamp, wake_up_timestamp); - WEARABLE_LOGD( - WEARABLE_LOG_MODULE_APP, - "data->fall_asleep_timestamp - history_wake_up_timestamp : %d \n", - data->fall_asleep_timestamp - history_wake_up_timestamp); - if ((history_wake_up_timestamp > 0) && - (history_wake_up_timestamp != wake_up_timestamp)) - { - fseek(fp, -sizeof(SLEEP_STATE_T), SEEK_END); - SLEEP_STATE_T sleep_status = {0, 0}; - fread(&sleep_status, sizeof(SLEEP_STATE_T), 1, fp); - if (sleep_status.stat == 4) // 如果存在出睡睡觉 替换为清醒 - { - sleep_status.stat = 3; // 清醒状态 - sleep_status.timestamp = - history_wake_up_timestamp; // 清醒状态时间为上一次的出睡时间 - fseek(fp, -sizeof(SLEEP_STATE_T), SEEK_END); - fwrite(&sleep_status, sizeof(SLEEP_STATE_T), 1, fp); // 补上清醒状态 - // fwrite(data->sleep_status, sizeof(SLEEP_STATE_T), data->status_num, - // fp); //写入本次睡眠状态 - fwrite(&data->sleep_status[1], sizeof(SLEEP_STATE_T), - data->status_num - 1, fp); // 跳过入睡状态写入文件 - } - else // 不满足补清醒状态条件 直接写入本次睡眠状态 - { - fseek(fp, 0, SEEK_END); - fwrite(data->sleep_status, sizeof(SLEEP_STATE_T), data->status_num, fp); - } - } - else // 不满足补清醒状态条件 直接写入本次睡眠状态 - { - fseek(fp, 0, SEEK_END); - fwrite(data->sleep_status, sizeof(SLEEP_STATE_T), data->status_num, fp); - } - } - - if (wake_up_timestamp) - { - history_wake_up_timestamp = wake_up_timestamp; // 更新历史出睡时间戳 - } - - fclose(fp); - - // osal_mutex_unlock(&sleep_mutex); - - return true; - } bool is_regular_file(const std::string &file_name) { @@ -514,16 +120,6 @@ namespace OHOS bool read_sleep_data(SLEEP_T *data) { - // errcode_t ret; - - // ret = osal_mutex_lock(&sleep_mutex); - - // if (ret != ERRCODE_SUCC) - // { - // PRINT(" sleep_mutex lock fail! ret=0x%x\n", ret); - // return false; - // } - char day[12] = {0}; uapi_get_YYMMDD_Time(day, '\0'); @@ -591,7 +187,7 @@ namespace OHOS return false; } - if(get_nap_data_size() > 14) //存在多段小睡 UI显示最新的一次数据 + if(uapi_get_file_size(nap_file_path) > 14) //存在多段小睡 UI显示最新的一次数据 fseek(fp, -14, SEEK_END);//移到最后一段数据 fseek(fp, 3, SEEK_CUR); // 将文件指针移动到睡眠类型 @@ -1159,19 +755,7 @@ namespace OHOS #endif /* __cplusplus */ #endif /* __cplusplus */ - void custom_save_sleep_data(void) - { - uapi_dev_runtime_set_sleep_storage_status(1); - save_sleep_data(&sleep_data); - uapi_dev_runtime_set_sleep_storage_status(0); - } - void custom_save_nap_data(void) - { - uapi_dev_runtime_set_sleep_storage_status(1); - save_nap_data(&nap_data); - uapi_dev_runtime_set_sleep_storage_status(0); - } void custom_read_sleep_data(void) { 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 ead4ec097..18a26d0f9 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 @@ -558,11 +558,11 @@ void MsgCenterNotifyLowPowerAlarmProc(const Topic topic, Request* req) #endif #ifdef FD230 -static SLEEP_T sleep_data = {0}; -static NAP_T nap_data = {0}; -static int state_num = 0; -static int current_year = 0; -static uint8_t fall_asleep_state_num = 0; +// static SLEEP_T sleep_data = {0}; +// static NAP_T nap_data = {0}; +// static int state_num = 0; +// static int current_year = 0; +// static uint8_t fall_asleep_state_num = 0; #endif /*NextDay*/ @@ -571,7 +571,7 @@ void MsgCenterNotifyNextDayProc(const Topic topic, Request *req) unused(topic); unused(req); AlarmClockModel::GetInstance()->NextDayNotify(); - current_year = 0; + // current_year = 0; #ifdef FD230 printf("******nextday is begin******\r\n"); /* ----------------------------------- 睡眠相关 ----------------------------------- */ @@ -1382,18 +1382,18 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req) WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyInactivityProc !"); //unused(topic); #ifdef FD230 - uint32_t timestamp = 0; - if(current_year == 0) - { - time_t rawtime; - struct tm* timeinfo; - time(&rawtime); - timeinfo = localtime(&rawtime); - current_year = timeinfo->tm_year + 1900; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timeinfo->tm_year : %d",timeinfo->tm_year); - } + // uint32_t timestamp = 0; + // if(current_year == 0) + // { + // time_t rawtime; + // struct tm* timeinfo; + // time(&rawtime); + // timeinfo = localtime(&rawtime); + // current_year = timeinfo->tm_year + 1900; + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timeinfo->tm_year : %d",timeinfo->tm_year); + // } #endif - 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) { @@ -1417,7 +1417,6 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req) case INACTIVITY_MODE_SEDENTARY_OUTPUT: if(cywee_Inactivity_Info->status == 1) { - SedentaryReminderViewEventListener::GetInstance().record_sedentary_reminder_log(); if (CheckPriority(topic)) { NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); @@ -1431,66 +1430,66 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req) break; //睡眠 - case INACTIVITY_MODE_SLEEPING_OUTPUT: -#ifdef FD230 - // if(state_num < 20) - // { - // sleep_data.sleep_status[state_num].timestamp = day_timestamp + cywee_Inactivity_Info->hour * 60 * 60 + cywee_Inactivity_Info->minute * 60; - // sleep_data.sleep_status[state_num].stat = cywee_Inactivity_Info->status; - // state_num ++; - // } - // if(cywee_Inactivity_Info->status == 0) //0进入睡眠 1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 8未出睡最后一笔输出 12快速动眼 13取消入睡 - // { - // sleep_data.fall_asleep_timestamp = day_timestamp + cywee_Inactivity_Info->hour * 60 * 60 + cywee_Inactivity_Info->minute * 60; - // fall_asleep_state_num = state_num; - // } - // else if(cywee_Inactivity_Info->status == 4) - // { - // sleep_data.wake_up_timestamp = day_timestamp + cywee_Inactivity_Info->hour * 60 * 60 + cywee_Inactivity_Info->minute * 60; - // } - if(state_num < SLEEP_STATUS_LENGTH) - { - uapi_get_timestampe_ss_extend(×tamp,current_year,cywee_Inactivity_Info->month,cywee_Inactivity_Info->day,cywee_Inactivity_Info->hour,cywee_Inactivity_Info->minute,0); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "timestamp : %d ",timestamp); - sleep_data.sleep_status[state_num].timestamp = timestamp; - sleep_data.sleep_status[state_num].stat = cywee_Inactivity_Info->status; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "stat : %d , timestamp : %d ", sleep_data.sleep_status[state_num].stat,sleep_data.sleep_status[state_num].timestamp); - if(sleep_data.sleep_status[state_num].stat == 7 || sleep_data.sleep_status[state_num].stat == 9 || sleep_data.sleep_status[state_num].stat == 13) - { - uapi_get_timestampe_ss(×tamp); - sleep_data.sleep_status[state_num].timestamp = timestamp; - } - 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; - } - else if(sleep_data.sleep_status[state_num].stat == 4) - { - sleep_data.wake_up_timestamp = sleep_data.sleep_status[state_num].timestamp; - } - state_num ++; - } -#endif - break; - - //小睡 - case INACTIVITY_MODE_NAP_OUTPUT: - if(cywee_Inactivity_Info->status == 0) //0进入睡眠 1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 8未出睡最后一笔输出 12快速动眼 13取消入睡 - { -#ifdef FD230 - uapi_get_timestampe_ss_extend(×tamp,current_year,cywee_Inactivity_Info->month,cywee_Inactivity_Info->day,cywee_Inactivity_Info->hour,cywee_Inactivity_Info->minute,0); - nap_data.fall_asleep_timestamp = timestamp; -#endif - } - else if(cywee_Inactivity_Info->status == 14) - { -#ifdef FD230 - uapi_get_timestampe_ss_extend(×tamp,current_year,cywee_Inactivity_Info->month,cywee_Inactivity_Info->day,cywee_Inactivity_Info->hour,cywee_Inactivity_Info->minute,0); - nap_data.wake_up_timestamp = timestamp; -#endif - } - break; +// case INACTIVITY_MODE_SLEEPING_OUTPUT: +// #ifdef FD230 +// // if(state_num < 20) +// // { +// // sleep_data.sleep_status[state_num].timestamp = day_timestamp + cywee_Inactivity_Info->hour * 60 * 60 + cywee_Inactivity_Info->minute * 60; +// // sleep_data.sleep_status[state_num].stat = cywee_Inactivity_Info->status; +// // state_num ++; +// // } +// // if(cywee_Inactivity_Info->status == 0) //0进入睡眠 1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 8未出睡最后一笔输出 12快速动眼 13取消入睡 +// // { +// // sleep_data.fall_asleep_timestamp = day_timestamp + cywee_Inactivity_Info->hour * 60 * 60 + cywee_Inactivity_Info->minute * 60; +// // fall_asleep_state_num = state_num; +// // } +// // else if(cywee_Inactivity_Info->status == 4) +// // { +// // sleep_data.wake_up_timestamp = day_timestamp + cywee_Inactivity_Info->hour * 60 * 60 + cywee_Inactivity_Info->minute * 60; +// // } +// if(state_num < SLEEP_STATUS_LENGTH) +// { +// uapi_get_timestampe_ss_extend(×tamp,current_year,cywee_Inactivity_Info->month,cywee_Inactivity_Info->day,cywee_Inactivity_Info->hour,cywee_Inactivity_Info->minute,0); +// WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "timestamp : %d ",timestamp); +// sleep_data.sleep_status[state_num].timestamp = timestamp; +// sleep_data.sleep_status[state_num].stat = cywee_Inactivity_Info->status; +// WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "stat : %d , timestamp : %d ", sleep_data.sleep_status[state_num].stat,sleep_data.sleep_status[state_num].timestamp); +// if(sleep_data.sleep_status[state_num].stat == 7 || sleep_data.sleep_status[state_num].stat == 9 || sleep_data.sleep_status[state_num].stat == 13) +// { +// uapi_get_timestampe_ss(×tamp); +// sleep_data.sleep_status[state_num].timestamp = timestamp; +// } +// 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; +// } +// else if(sleep_data.sleep_status[state_num].stat == 4) +// { +// sleep_data.wake_up_timestamp = sleep_data.sleep_status[state_num].timestamp; +// } +// state_num ++; +// } +// #endif +// break; + +// //小睡 +// case INACTIVITY_MODE_NAP_OUTPUT: +// if(cywee_Inactivity_Info->status == 0) //0进入睡眠 1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 8未出睡最后一笔输出 12快速动眼 13取消入睡 +// { +// #ifdef FD230 +// uapi_get_timestampe_ss_extend(×tamp,current_year,cywee_Inactivity_Info->month,cywee_Inactivity_Info->day,cywee_Inactivity_Info->hour,cywee_Inactivity_Info->minute,0); +// nap_data.fall_asleep_timestamp = timestamp; +// #endif +// } +// else if(cywee_Inactivity_Info->status == 14) +// { +// #ifdef FD230 +// uapi_get_timestampe_ss_extend(×tamp,current_year,cywee_Inactivity_Info->month,cywee_Inactivity_Info->day,cywee_Inactivity_Info->hour,cywee_Inactivity_Info->minute,0); +// nap_data.wake_up_timestamp = timestamp; +// #endif +// } +// break; default: break; @@ -1503,7 +1502,7 @@ void MsgCenterNotifyInactivityProc(const Topic topic, Request *req) void MsgCenterNotifyInactivityAccumulateTimeProc(const Topic topic, Request* req) { unused(topic); - + #if 0 if(uapi_dev_runtime_get_absolute_static_status()) { memset(&sleep_data,0,sizeof(SLEEP_T)); @@ -1563,6 +1562,7 @@ void MsgCenterNotifyInactivityAccumulateTimeProc(const Topic topic, Request* req free(cywee_Inactivity_Accumulate_Time_Info); cywee_Inactivity_Accumulate_Time_Info = NULL; //uapi_dev_runtime_set_sleep_status(0); +#endif } //APP运动相关 diff --git a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h index b7fb676e0..447c66d34 100644 --- a/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h +++ b/code/sdk/drivers/peripheral/cywee/Inc/cywee_hal.h @@ -502,6 +502,13 @@ typedef struct int total_rem_sleep_time;//动眼 }cywee_inactivity_accumulate_time_t; +typedef struct +{ + uint32_t timestamp; //时间戳 + uint8_t stat; // 状态 + +} SLEEP_STAT_T; + #pragma pack() typedef enum{ CYWEE_MSG_TYPE_ACTIVITY_UPDATE, @@ -566,6 +573,11 @@ void cywee_restart_acc(void); void cywee_log_switch(int cmd); void cywee_get_version(char *databuf,uint8_t len); +void cywee_save_sleep_stat_data(void); + +void cywee_custom_save_sleep_data(void); +void cywee_custom_save_nap_data(void); + extern uint8_t hrs_mode_state; #pragma pack() diff --git a/code/sdk/drivers/peripheral/cywee/src/main_dml.c b/code/sdk/drivers/peripheral/cywee/src/main_dml.c index 89da4be03..8c6c634d3 100644 --- a/code/sdk/drivers/peripheral/cywee/src/main_dml.c +++ b/code/sdk/drivers/peripheral/cywee/src/main_dml.c @@ -23,6 +23,16 @@ #define GSENSON_MSG_COUNT 16 +#define SLEEP_TIME_PATH "/user/userdata/sleep/%s/sleep_time.bin" +#define SLEEP_STATUS_PATH "/user/userdata/sleep/%s/sleep_status.bin" + +#define NAP_PATH "/user/userdata/sleep/%s/nap.bin" +#define SLEEP_DIR_PATH "/user/userdata/sleep/%s" + +#define SLEEP_DATA_DIR "/user/userdata/sleep/" + +#define SLEEP_STATUS_LENGTH 50 + static gsenson_t gxyz_t; static uint8_t gsenson_falg=0; @@ -81,8 +91,31 @@ uint8_t cywee_ble_service_flag = 0; static char cywee_version[20] = {0}; +static SLEEP_STAT_T sleep_stat[SLEEP_STATUS_LENGTH] = {0}; +static cywee_inactivity_accumulate_time_t sleep_time = {0}; +// static NAP_T nap_data = {0}; +static int stat_num = 0; +static int current_year = 0; +static uint32_t fall_asleep_timestamp = 0; +static uint32_t wake_up_timestamp = 0; static uint32_t abs_static_timestampe = 0; static uint32_t asleep_timestampe = 0; +static uint32_t nap_update_timestamp = 0; +static uint32_t sleep_update_timestamp = 0; + +static uint16_t total_time = 0; +static uint16_t total_deep_sleep_time = 0; +static uint16_t total_mild_sleep_time = 0; +static uint16_t total_rem_sleep_time = 0; +static uint16_t total_wake_time = 0; + +static char time_file_path[64] = {0}; +static char status_file_path[64] = {0}; +static char nap_file_path[64] = {0}; + +static char day[12] = {0}; +static char dir_path[64] = {0}; + #ifdef CYWEE_MAC_ACTIVE int cm__hs1__mac_c1_init(void); @@ -93,12 +126,228 @@ int cm__hs1__init(void); int cm__hs1__deinit(void); #endif -typedef struct + +void clean_sleep_data(void) +{ + total_time = 0; + total_deep_sleep_time = 0; + total_mild_sleep_time = 0; + total_rem_sleep_time = 0; + total_wake_time = 0; + stat_num = 0; + current_year = 0; + fall_asleep_timestamp = 0; + wake_up_timestamp = 0; + abs_static_timestampe = 0; + asleep_timestampe = 0; + memset(&sleep_stat,0,SLEEP_STATUS_LENGTH * sizeof(SLEEP_STAT_T)); + 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)); + memset(nap_file_path, 0, sizeof(nap_file_path)); +} + +void cywee_save_nap_data(cywee_inactivity_accumulate_time_t c_inactivity_accumulate_time_t) +{ + char day[12] = {0}; + uapi_get_YYMMDD_Time(day, '\0'); + + sprintf_s(nap_file_path, 64, NAP_PATH, day); + + uint32_t size = uapi_get_file_size(nap_file_path); + + FILE *fp; + fp = fopen(nap_file_path, "ab+"); //小睡数据全部存入一个文件 + if(fp==NULL) + { + CWM_OS_dbgPrintf("save_nap_sleep_data %s fopen fail \n", nap_file_path); + return; + } + + uint8_t id=size/14+1; + + uint16_t nap_size=12; + fwrite(&nap_size, 1, 2, fp); + + fwrite(&id, 1, 1, fp); + + uint8_t sleep_type = 0; //不存睡眠类型 改用文件名判断 + fwrite(&sleep_type, 1, 1, fp); + + fwrite(&fall_asleep_timestamp, 1, 4, fp); + + fwrite(&wake_up_timestamp, 1, 4, fp); + + uint16_t total_time = c_inactivity_accumulate_time_t.total_time; + + uint8_t total_time_hour = (total_time / 60); + fwrite(&total_time_hour, 1, 1, fp); + + uint8_t total_time_minute = (total_time % 60); + fwrite(&total_time_minute, 1, 1, fp); + + CWM_OS_dbgPrintf("save_nap_sleep_data succ \n"); + + fclose(fp); +} + +void cywee_set_sleep_time_data(cywee_inactivity_accumulate_time_t *sleep_data) +{ + memset(&sleep_time, 0, sizeof(cywee_inactivity_accumulate_time_t)); + memcpy_s(&sleep_time, sizeof(cywee_inactivity_accumulate_time_t), sleep_data, sizeof(cywee_inactivity_accumulate_time_t)); +} + +void cywee_save_sleep_time_data(cywee_inactivity_accumulate_time_t sleep_time) { - uint32_t timestamp; // - uint8_t stat; // 状态 + uint8_t flag = 0; //临时数据标志 + + if (access(time_file_path, 0) == -1) + { + memset(time_file_path, 0, sizeof(time_file_path)); + sprintf_s(time_file_path, 64, SLEEP_TIME_PATH, day); + } + + FILE *fp; + fp = fopen(time_file_path, "wb+"); + if(fp == NULL) + { + CWM_OS_dbgPrintf("save_sleep_data fopen fail \n"); + return; + } + + uint8_t sleep_type = 1; + fwrite(&sleep_type, 1, 1, fp); + + fwrite(&fall_asleep_timestamp, 1, 4, fp); + + if (wake_up_timestamp == 0) + { + uapi_get_timestampe_ss(&wake_up_timestamp); + flag = 1; + } -} SLEEP_FLAG_T; + 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); + + uint8_t total_time_minute = (total_time % 60); + fwrite(&total_time_minute, 1, 1, fp); + + total_deep_sleep_time += sleep_time.total_deep_sleep_time; + + total_time_hour = (total_deep_sleep_time / 60); + fwrite(&total_time_hour, 1, 1, fp); + + total_time_minute = (total_deep_sleep_time % 60); + fwrite(&total_time_minute, 1, 1, fp); + + total_mild_sleep_time += sleep_time.total_mild_sleep_time; + total_time_hour = (total_mild_sleep_time / 60); + fwrite(&total_time_hour, 1, 1, fp); + + total_time_minute = (total_mild_sleep_time % 60); + fwrite(&total_time_minute, 1, 1, fp); + + total_rem_sleep_time += sleep_time.total_rem_sleep_time; + total_time_hour = (total_rem_sleep_time / 60); + fwrite(&total_time_hour, 1, 1, fp); + + total_time_minute = (total_rem_sleep_time % 60); + fwrite(&total_time_minute, 1, 1, fp); + + 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); + + total_time_minute = (total_wake_time % 60); + fwrite(&total_time_minute, 1, 1, fp); + + CWM_OS_dbgPrintf("total_time[%d], total_deep_sleep_time[%d], total_mild_sleep_time[%d], total_rem_sleep_time[%d], total_wake_time[%d] \n", + total_time,total_deep_sleep_time,total_mild_sleep_time,total_rem_sleep_time,total_wake_time); + fclose(fp); + + if (flag) // 临时数据清掉 + { + total_deep_sleep_time -= sleep_time.total_deep_sleep_time; + total_mild_sleep_time -= sleep_time.total_mild_sleep_time; + total_rem_sleep_time -= sleep_time.total_rem_sleep_time; + } +} + +void cywee_save_sleep_stat_data(void) +{ + if (access(status_file_path, 0) == -1) // 文件不存在 直接写入 + { + memset(status_file_path, 0, sizeof(status_file_path)); + sprintf_s(status_file_path, 64, SLEEP_STATUS_PATH, day); + + uapi_save_file_data(status_file_path,(uint8_t *)&sleep_stat,stat_num * sizeof(SLEEP_STAT_T),"wb+"); + } + else // 文件已存在 需要判断是否需要补上清醒状态 + { + + FILE *fp = fopen(status_file_path, "rb+"); + if (fp == NULL) + { + CWM_OS_dbgPrintf("save_sleep_data fopen fail \n"); + return; + } + + fseek(fp, -sizeof(SLEEP_STAT_T), SEEK_END); + SLEEP_STAT_T sleep_status = {0, 0}; + fread(&sleep_status, sizeof(SLEEP_STAT_T), 1, fp); + if (sleep_status.stat == 4) // 如果存在出睡睡觉 替换为清醒 + { + sleep_status.stat = 3; // 清醒状态 + // sleep_status.timestamp = history_wake_up_timestamp; // 清醒状态时间为上一次的出睡时间 + fseek(fp, -sizeof(SLEEP_STAT_T), SEEK_END); + fwrite(&sleep_status, sizeof(SLEEP_STAT_T), 1, fp); // 补上清醒状态 + // fwrite(data->sleep_status, sizeof(SLEEP_STATE_T), data->status_num, fp); //写入本次睡眠状态 + + fwrite(&sleep_stat[1], sizeof(SLEEP_STAT_T),stat_num - 1, fp); // 跳过入睡状态写入文件 + + } + else // 不满足补清醒状态条件 直接写入本次睡眠状态 + { + fseek(fp, 0, SEEK_END); + fwrite(&sleep_stat, sizeof(SLEEP_STAT_T), stat_num, fp); + } + fclose(fp); + } + + stat_num = 0; + memset(&sleep_stat,0,SLEEP_STATUS_LENGTH * sizeof(SLEEP_STAT_T)); + +} +void cywee_set_sleep_stat_data(cywee_inactivity_result_t c_inactivity_result_t) +{ + uint32_t timestamp = 0; + if(stat_num < SLEEP_STATUS_LENGTH) + { + uapi_get_timestampe_ss_extend(×tamp,current_year,c_inactivity_result_t.month,c_inactivity_result_t.day,c_inactivity_result_t.hour,c_inactivity_result_t.minute,0); + + sleep_stat[stat_num].timestamp = timestamp; + sleep_stat[stat_num].stat = c_inactivity_result_t.status; + CWM_OS_dbgPrintf("stat : %d , timestamp : %d \n", sleep_stat[stat_num].stat,sleep_stat[stat_num].timestamp); + if(sleep_stat[stat_num].stat == 0) //0进入睡眠 1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 8未出睡最后一笔输出 12快速动眼 13取消入睡 + { + if(fall_asleep_timestamp == 0) + fall_asleep_timestamp = sleep_stat[stat_num].timestamp; + } + else if(sleep_stat[stat_num].stat == 4) + { + wake_up_timestamp = sleep_stat[stat_num].timestamp; + sleep_update_timestamp = wake_up_timestamp; + } + stat_num ++; + } +} void cywee_set_abs_static(void) { @@ -460,12 +709,23 @@ void cywee_time_sync(void) { time_t rawtime; struct tm* timeinfo; + + clean_sleep_data(); + + 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; + uint32_t current_min = 0; + time(&rawtime); timeinfo = localtime(&rawtime); CWM_OS_dbgPrintf("cywee_time_sync : year[%d], mon[%d], day[%d], hour[%d], min[%d], sec[%d] \r\n", timeinfo->tm_year+1900,timeinfo->tm_mon+1,timeinfo->tm_mday, timeinfo->tm_hour,timeinfo->tm_min,timeinfo->tm_sec); + current_year = timeinfo->tm_year+1900; + memset(&scl, 0, sizeof(scl)); scl.iData[0] = 1; scl.iData[1] = timeinfo->tm_year + 1900; @@ -475,6 +735,29 @@ void cywee_time_sync(void) scl.iData[5] = timeinfo->tm_min; scl.iData[6] = timeinfo->tm_sec; CWM_SettingControl(SCL_DATE_TIME, &scl); + + //时间同步以后创建文件夹 + 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; + + if (current_min >= sleep_min && current_min < 24 * 60) + uapi_get_YYMMDD_Time_extend(day, '\0', -1); + else if (current_min >= 0 && current_min < wake_min) + uapi_get_YYMMDD_Time_extend(day, '\0', 0); + } + else + uapi_get_YYMMDD_Time_extend(day, '\0', 0); + + sprintf_s(dir_path, 64, SLEEP_DIR_PATH, day); + uapi_create_folder("user/userdata/sleep"); + uapi_create_folder(dir_path); } void cywee_hrs_update(int hrs_data) @@ -504,14 +787,6 @@ void cywee_wearstatus_update(int wearstatus) csd.fData[0] = wearstatus; CWM_CustomSensorInput(&csd); CWM_OS_dbgPrintf("111wearstatus : %d\r\n",wearstatus); - - if(uapi_dev_runtime_get_sleep_monitoring_status()) - { - SLEEP_FLAG_T sleep_flag_t; - sleep_flag_t.stat = 16 + wearstatus; - uapi_get_timestampe_ss(&sleep_flag_t.timestamp); - uapi_save_sleep_flag(&sleep_flag_t,sizeof(SLEEP_FLAG_T)); - } #endif } @@ -715,7 +990,7 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { cywee_inactivity_result_t c_inactivity_result_t; cywee_inactivity_accumulate_time_t c_inactivity_accumulate_time_t; cywee_activity_result_extre_info_t c_activity_result_extre_info_t; - SLEEP_FLAG_T sleep_flag_t; + switch (sensorEVT->sensorType) { case IDX_ACCEL: gxyz_t.x = sensorEVT->fData[0]; @@ -886,13 +1161,13 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { c_inactivity_result_t.hour = (int)sensorEVT->fData[5]; c_inactivity_result_t.minute = (int)sensorEVT->fData[6]; - /*保存睡眠状态*/ - if(c_inactivity_result_t.status >= 6 && c_inactivity_result_t.status <= 13) - { - uapi_get_timestampe_ss(&sleep_flag_t.timestamp); - sleep_flag_t.stat = c_inactivity_result_t.status; - uapi_save_sleep_flag(&sleep_flag_t,sizeof(SLEEP_FLAG_T)); - } + // /*保存睡眠状态*/ + // if(c_inactivity_result_t.status >= 6 && c_inactivity_result_t.status <= 13) + // { + // uapi_get_timestampe_ss(&sleep_flag_t.timestamp); + // sleep_flag_t.stat = c_inactivity_result_t.status; + // // uapi_save_sleep_flag(&sleep_flag_t,sizeof(SLEEP_FLAG_T)); + // } //0进入睡眠 1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 9未出睡最后一笔输出 12快速动眼 13取消入睡 if(c_inactivity_result_t.status >= 6 && c_inactivity_result_t.status <= 9) @@ -907,10 +1182,24 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { else if(c_inactivity_result_t.status == 4 || c_inactivity_result_t.status == 13) { uapi_dev_runtime_set_sleep_status(0); + if(c_inactivity_result_t.status == 13) + break; } - cywee_func(CYWEE_MSG_TYPE_INACTIVITY_UPDATE,&c_inactivity_result_t,sizeof(cywee_inactivity_result_t)); + + cywee_set_sleep_stat_data(c_inactivity_result_t); + // cywee_func(CYWEE_MSG_TYPE_INACTIVITY_UPDATE,&c_inactivity_result_t,sizeof(cywee_inactivity_result_t)); }else if((int)sensorEVT->fData[0] == 31){ + + if(uapi_dev_runtime_get_absolute_static_status()) + { + uapi_dev_runtime_set_absolute_static_status(0);//清除绝对静止状态 + stat_num = 0; + memset(&sleep_stat,0,SLEEP_STATUS_LENGTH * sizeof(SLEEP_STAT_T)); + fall_asleep_timestamp = 0; + break ; //绝对静止状态不存数据 + } + memset(&c_inactivity_accumulate_time_t,0,sizeof(cywee_inactivity_accumulate_time_t)); @@ -921,7 +1210,9 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { c_inactivity_accumulate_time_t.total_wake_time = (int)sensorEVT->fData[4]; c_inactivity_accumulate_time_t.total_rem_sleep_time = (int)sensorEVT->fData[5]; - cywee_func(CYWEE_MSG_TYPE_INACTIVITY_ACCUMULATE_TIME_UPDATE,&c_inactivity_accumulate_time_t,sizeof(cywee_inactivity_accumulate_time_t)); + cywee_set_sleep_time_data(&c_inactivity_accumulate_time_t); + do_custom_fileoperate_service_check_msg(CUSTOM_FILEOPERATE_MSG_TYPE_SLEEPDATA_SAVE, NULL, 0); + // cywee_func(CYWEE_MSG_TYPE_INACTIVITY_ACCUMULATE_TIME_UPDATE,&c_inactivity_accumulate_time_t,sizeof(cywee_inactivity_accumulate_time_t)); }else if((int)sensorEVT->fData[0] == 22){ @@ -935,11 +1226,19 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { c_inactivity_result_t.minute = (int)sensorEVT->fData[6]; if(c_inactivity_result_t.status == 0) + { uapi_dev_runtime_set_nap_status(1); + //获取小睡入睡时间戳 + uapi_get_timestampe_ss_extend(&fall_asleep_timestamp,current_year,c_inactivity_result_t.month,c_inactivity_result_t.day,c_inactivity_result_t.hour,c_inactivity_result_t.minute,0); + } else if(c_inactivity_result_t.status == 14) + { uapi_dev_runtime_set_nap_status(0); - - cywee_func(CYWEE_MSG_TYPE_INACTIVITY_UPDATE,&c_inactivity_result_t,sizeof(cywee_inactivity_result_t)); + //获取小睡出睡时间戳 + uapi_get_timestampe_ss_extend(&wake_up_timestamp,current_year,c_inactivity_result_t.month,c_inactivity_result_t.day,c_inactivity_result_t.hour,c_inactivity_result_t.minute,0); + nap_update_timestamp = wake_up_timestamp; + } + // cywee_func(CYWEE_MSG_TYPE_INACTIVITY_UPDATE,&c_inactivity_result_t,sizeof(cywee_inactivity_result_t)); }else if((int)sensorEVT->fData[0] == 32){ @@ -952,7 +1251,11 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { c_inactivity_accumulate_time_t.total_wake_time = (int)sensorEVT->fData[4]; c_inactivity_accumulate_time_t.total_rem_sleep_time = (int)sensorEVT->fData[5]; - cywee_func(CYWEE_MSG_TYPE_INACTIVITY_ACCUMULATE_TIME_UPDATE,&c_inactivity_accumulate_time_t,sizeof(cywee_inactivity_accumulate_time_t)); + cywee_set_sleep_time_data(&c_inactivity_accumulate_time_t); + do_custom_fileoperate_service_check_msg(CUSTOM_FILEOPERATE_MSG_TYPE_NAPDATA_SAVE, NULL, 0); + // save_nap_data(c_inactivity_accumulate_time_t); + + // cywee_func(CYWEE_MSG_TYPE_INACTIVITY_ACCUMULATE_TIME_UPDATE,&c_inactivity_accumulate_time_t,sizeof(cywee_inactivity_accumulate_time_t)); } break; case IDX_ALGO_ACTIVITY_OUTPUT: @@ -1031,9 +1334,9 @@ void CWM_AP_SensorListen(pSensorEVT_t sensorEVT) { uapi_get_timestampe_ss(&abs_static_timestampe); if((abs_static_timestampe - asleep_timestampe) >= 60 * 90) { - sleep_flag_t.stat = 15; - sleep_flag_t.timestamp = abs_static_timestampe; - uapi_save_sleep_flag(&sleep_flag_t,sizeof(SLEEP_FLAG_T)); + // sleep_flag_t.stat = 15; + // sleep_flag_t.timestamp = abs_static_timestampe; + // uapi_save_sleep_flag(&sleep_flag_t,sizeof(SLEEP_FLAG_T)); uapi_dev_runtime_set_absolute_static_status(1); cywee_get_sleep_data(1); } @@ -1498,3 +1801,19 @@ void cywee_int_handler(void) } } + +void cywee_custom_save_sleep_data(void) +{ + uapi_dev_runtime_set_sleep_storage_status(1); + cywee_save_sleep_time_data(sleep_time); + cywee_save_sleep_stat_data(); + uapi_dev_runtime_set_sleep_storage_status(0); +} + +void cywee_custom_save_nap_data(void) +{ + uapi_dev_runtime_set_sleep_storage_status(1); + cywee_save_nap_data(sleep_time); + uapi_dev_runtime_set_sleep_storage_status(0); +} + \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c b/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c index 5618eaab4..e065e1cc1 100644 --- a/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c +++ b/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c @@ -46,6 +46,8 @@ #include "player/include/PlayersModelC.h" #include "mmc5603_hal.h" + +#include "cywee_hal.h" typedef struct { uint8_t cmd; @@ -121,10 +123,10 @@ static void custom_fileoperate_service_check_task(void const *arg) case CUSTOM_FILEOPERATE_MSG_TYPE_MESSAGEDATA_SAVE: break; case CUSTOM_FILEOPERATE_MSG_TYPE_SLEEPDATA_SAVE: - custom_save_sleep_data(); + cywee_custom_save_sleep_data(); break; case CUSTOM_FILEOPERATE_MSG_TYPE_NAPDATA_SAVE: - custom_save_nap_data(); + cywee_custom_save_nap_data(); break; case CUSTOM_FILEOPERATE_MSG_TYPE_SLEEPDATA_READ: custom_read_sleep_data(); diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 9077ee8de..bd2062688 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -2870,6 +2870,36 @@ void uapi_vibrator_test(uint32_t test_time) } } +void uapi_create_folder(char *dir_path) +{ + struct stat info; + if (stat(dir_path, &info) != 0) + { + if(mkdir(dir_path, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) + { + PRINT("mkdir %s failed \n",dir_path); + } + } +} + + +//获取小睡数据长度(协议用) +uint32_t uapi_get_file_size(char *filepath) +{ + FILE *fp; + uint32_t size = 0; + fp = fopen(filepath, "rb"); + if (fp == NULL) + { + PRINT("read open %s failed\n",filepath); + return 0; + } + // 获取文件大小 + fseek(fp, 0, SEEK_END); + size = ftell(fp); + fclose(fp); + return size; +} uint8_t uapi_get_cywee_static_state(void) diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index a6ae29bb4..cfdda1443 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -311,10 +311,10 @@ errcode_t uapi_start_audio_test(int volume); errcode_t uapi_stop_audio_test(void); void uapi_save_sleep_flag(uint8_t *data,uint16_t len); -void uapi_clean_sleep_flag(void); void start_save_file_thread(void); - +void uapi_create_folder(char *dir_path); +uint32_t uapi_get_file_size(char *filepath); /** * 资源文件校验码保存在文件 /system/fileschecksum.txt 中 * 读出每一行,输入本函数,检测文件是否正常。 -- 2.17.1