* @Author: penglei 1624952103@qq.com
* @Date: SLEPPNOTIFY24-06-26 19:36:48
* @LastEditors: penglei 1624952103@qq.com
- * @LastEditTime: 2024-11-11 16:59:29
+ * @LastEditTime: 2024-11-27 11:15:14
* @FilePath:
* /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp
* @Description:
return result; // 返回结果字符串
}
+ std::string get_sleep_star_str(void)
+ {
+
+ std::string result;
+
+ uint16_t datelen = 0;
+ uint8_t sleep_data[256] = {0};
+
+ uint32_t asleep_time = 0;
+ uint32_t wake_up_time = 0;
+ uint16_t total_time = 0;
+ uint16_t total_deep_sleep_time = 0;
+ uint16_t total_mild_sleep_time = 0;
+ uint16_t total_rem_sleep_time = 0;
+ uint16_t total_wake_time = 0;
+ uint32_t timestampe = 0;
+ int status = -1;
+ uint8_t index = 0;
+ char timestampe_str[10] = {0};
+ char status_str[20] = {0};
+
+ char day[12] = {0};
+ uapi_get_YYMMDD_Time(day, '\0');
+
+ char file_path[64] = {0};
+ sprintf_s(file_path, 64, SLEEP_TIME_PATH, day);
+
+ uapi_get_file_data(file_path,sleep_data,&datelen);
+
+ if(datelen == 0)
+ {
+ PRINT("fread error datelen == 0 \n");
+ return "没有文件";
+ }
+
+ asleep_time = *(uint32_t*)&sleep_data[1];
+ wake_up_time = *(uint32_t*)&sleep_data[5];
+
+ total_time = sleep_data[9] * 60 + sleep_data[10];
+ total_deep_sleep_time = sleep_data[11] * 60 + sleep_data[12];
+ total_mild_sleep_time = sleep_data[13] * 60 + sleep_data[14];
+ total_rem_sleep_time = sleep_data[15] * 60 + sleep_data[16];
+ total_wake_time = sleep_data[17] * 60 + sleep_data[18];
+
+ char asleep_time_str[10] = {0};
+ uapi_get_TIME_STR(asleep_time,asleep_time_str, '.', ':',DATE_H_M);
+
+ char wake_up_time_str[10] = {0};
+ uapi_get_TIME_STR(wake_up_time,wake_up_time_str, '.', ':',DATE_H_M);
+
+ result += std::string("入睡时间: ") + asleep_time_str + " " + std::to_string(asleep_time) + "\n";
+ result += std::string("出睡时间: ") + wake_up_time_str + " " + std::to_string(wake_up_time) + "\n";
+ result += std::string("总时长: ") + std::to_string(total_time) + "\n";
+ result += std::string("深睡时长: ") + std::to_string(total_deep_sleep_time) + "\n";
+ result += std::string("浅睡时长: ") + std::to_string(total_mild_sleep_time) + "\n";
+ result += std::string("快速眼动时长: ") + std::to_string(total_rem_sleep_time) + "\n";
+ result += std::string("清醒时长: ") + std::to_string(total_wake_time) + "\n";
+
+ // PRINT("入睡时间 : %s %d \n",asleep_time_str,asleep_time);
+ // PRINT("出睡时间 : %s %d \n",wake_up_time_str,wake_up_time);
+ // PRINT("总时长 : %d 分钟\n",total_time);
+ // PRINT("深睡时长 : %d 分钟\n",total_deep_sleep_time);
+ // PRINT("浅睡时长 : %d 分钟\n",total_mild_sleep_time);
+ // PRINT("快速眼动时长 : %d 分钟\n",total_rem_sleep_time);
+ // PRINT("清醒时长 : %d 分钟\n",total_wake_time);
+
+ char statuspath[64] = {0};
+ uapi_get_YYMMDD_Time(day, '\0');
+ sprintf_s(statuspath, 64, SLEEP_STATUS_PATH, day);
+
+
+ memset(sleep_data,0,sizeof(sleep_data));
+ datelen = 0;
+ uapi_get_file_data(statuspath,sleep_data,&datelen);
+
+ if(datelen == 0)
+ {
+ PRINT("fread error datelen == 0 \n");
+ return result += "\n 没有状态文件";
+ }
+
+ while(datelen)
+ {
+ memset(timestampe_str,0,sizeof(timestampe_str));
+ memset(status_str,0,sizeof(status_str));
+ timestampe = *(uint32_t*)&sleep_data[index];
+ uapi_get_TIME_STR(timestampe,timestampe_str, '.', ':',DATE_H_M);
+ status = sleep_data[index + 4];
+ //0进入睡眠 1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 8未出睡最后一笔输出 12快速动眼 13取消入睡
+ switch(status)
+ {
+ case 0:
+ strcpy(status_str,"进入睡眠");
+ break;
+ case 1:
+ strcpy(status_str,"浅睡");
+ break;
+ case 2:
+ strcpy(status_str,"深睡");
+ break;
+ case 3:
+ strcpy(status_str,"清醒");
+ break;
+ case 4:
+ strcpy(status_str,"结束睡眠");
+ break;
+ case 6:
+ strcpy(status_str,"入睡通知");
+ break;
+ case 7:
+ strcpy(status_str,"出睡最后一笔输出");
+ break;
+ case 9:
+ strcpy(status_str,"未出睡最后一笔输出");
+ break;
+ case 12:
+ strcpy(status_str,"快速动眼");
+ break;
+ case 13:
+ strcpy(status_str,"取消入睡");
+ break;
+ default:
+ break;
+
+ }
+
+ // PRINT("时间 : %d %s 状态:%s\n",timestampe,timestampe_str,status_str);
+
+ result += std::string(status_str) + std::to_string(timestampe) + "\n";
+
+ index+=5;
+ datelen -= 5;
+ }
+ return result;
+ }
std::string get_sleep_asleep_time_str(void)
{
static uint8_t timeout = 0;
+static uint8_t wake_up_flag = 0;
+
#ifdef CYWEE_MAC_ACTIVE
int cm__hs1__mac_c1_init(void);
int cm__hs1__deinit(void);
memset(status_file_path, 0, sizeof(status_file_path));
memset(dir_path, 0, sizeof(dir_path));
memset(nap_file_path, 0, sizeof(nap_file_path));
+ wake_up_flag = 0;
}
void cywee_save_nap_data(cywee_inactivity_accumulate_time_t c_inactivity_accumulate_time_t)
stat_num = 0;
memset(sleep_stat,0,SLEEP_STATUS_LENGTH * sizeof(SLEEP_STAT_T));
+ if(wake_up_flag)
+ uapi_dev_runtime_set_sleep_status(0);
+
}
void cywee_set_sleep_stat_data(cywee_inactivity_result_t c_inactivity_result_t)
{
{
if(c_inactivity_result_t.status == 6)
{
+ wake_up_flag = 0;
uapi_dev_runtime_set_sleep_status(1);
uapi_get_timestampe_ss(&asleep_timestampe);
}
}
else if(c_inactivity_result_t.status == 4 || c_inactivity_result_t.status == 13)
{
- uapi_dev_runtime_set_sleep_status(0);
+ wake_up_flag = 1;
if(c_inactivity_result_t.status == 13)
break;
}