int cmd = 1;\r
uapi_dev_runtime_set_sleep_status(0); // 清零睡眠状态\r
uapi_dev_runtime_set_absolute_static_status(0); // 清零绝对静止状态\r
- OHOS::clean_sleep_data(); // 清零睡眠文件存储数据\r
- if(uapi_dev_runtime_get_nap_monitoring_status() == 1)\r
- uapi_clean_sleep_flag(); // 清除睡眠标志文件\r
- OHOS::create_sleep_folder(); // 创建睡眠文件夹 \r
+ // OHOS::clean_sleep_data(); // 清零睡眠文件存储数据\r
+ // if(uapi_dev_runtime_get_nap_monitoring_status() == 1)\r
+ // uapi_clean_sleep_flag(); // 清除睡眠标志文件\r
+ // OHOS::create_sleep_folder(); // 创建睡眠文件夹 \r
set_keep_in_wear_det_mode(0); \r
do_cywee_service_check_msg(CYWEE_SERVICE_CMD_GET_SLEEP_DATA, &cmd); // 强制获取小睡数据,结束小睡\r
\r
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);
* @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:
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)
{
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)
{
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');
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); // 将文件指针移动到睡眠类型
#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)
{
#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*/
unused(topic);
unused(req);
AlarmClockModel::GetInstance()->NextDayNotify();
- current_year = 0;
+ // current_year = 0;
#ifdef FD230
printf("******nextday is begin******\r\n");
/* ----------------------------------- 睡眠相关 ----------------------------------- */
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)
{
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);
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;
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));
free(cywee_Inactivity_Accumulate_Time_Info);
cywee_Inactivity_Accumulate_Time_Info = NULL;
//uapi_dev_runtime_set_sleep_status(0);
+#endif
}
//APP运动相关
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,
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()
#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;
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);
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)
{
{
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;
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)
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
}
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];
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)
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));
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){
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){
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:
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);
}
}
}
+
+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
#include "player/include/PlayersModelC.h"
#include "mmc5603_hal.h"
+
+#include "cywee_hal.h"
typedef struct
{
uint8_t cmd;
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();
}
}
+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)
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 中
* 读出每一行,输入本函数,检测文件是否正常。