#include "AppViewIDs.h"\r
#include "player/include/PlayersView.h"\r
#include "record/include/RecordingPlayerView.h"\r
+\r
#ifdef __cplusplus\r
extern "C"\r
{\r
{\r
// 设置状态为小睡\r
uapi_dev_runtime_set_nap_status(0); // 清零小睡状态\r
+ uapi_dev_runtime_set_absolute_static_status(0); // 清零绝对静止状态\r
uapi_dev_runtime_set_nap_monitoring_status(1);\r
uapi_dev_runtime_set_sleep_monitoring_status(0);\r
OHOS::SleepModel::GetInstance().ReInitData(); // 更新睡眠数据\r
else if ((!WAKE_TIME_RANGE) && (uapi_dev_runtime_get_sleep_monitoring_status() == 0))\r
{\r
uapi_dev_runtime_set_sleep_status(0); // 清零睡眠状态\r
+ uapi_dev_runtime_set_absolute_static_status(0); // 清零绝对静止状态\r
+ OHOS::clean_sleep_data(); // 清零睡眠文件存储数据\r
uapi_dev_runtime_set_sleep_monitoring_status(1);\r
uapi_dev_runtime_set_nap_monitoring_status(0);\r
do_cywee_service_check_msg(CYWEE_SERVICE_CMD_GET_SLEEP_DATA, NULL); // 强制获取小睡数据,结束小睡\r
#include "NativeAbility.h"
#include "battery_hal.h"
-#define MAX_UNWARE_COUNT 30
+#define MAX_UNWARE_COUNT 10
#define MAX_VALID_SPO2_COUNT 30
#define MAX_DISVALID_SPO2_COUNT 100
namespace OHOS
* @Author: penglei 1624952103@qq.com
* @Date: 2024-06-26 19:36:48
* @LastEditors: penglei 1624952103@qq.com
- * @LastEditTime: 2024-09-03 14:30:14
+ * @LastEditTime: 2024-09-04 19:02:28
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h
* @Description:
*
// #include "sleep/include/SleepControlPresenter.h"
#include "string"
-#define SLEEP_PATH "user/userdata/sleep/%s/sleep_%d.bin"
+#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_%d.bin"
#define SLEEP_DIR_PATH "user/userdata/sleep/%s"
void set_sleep_data(SLEEP_T *data);
bool save_sleep_data(SLEEP_T *data);
bool read_sleep_data(SLEEP_T *data);
-
+ void clean_sleep_data(void);
// 睡眠状态
enum class SLEEPSTATE
{
* @Author: penglei 1624952103@qq.com
* @Date: SLEPPNOTIFY24-06-26 19:36:48
* @LastEditors: penglei 1624952103@qq.com
- * @LastEditTime: SLEPPNOTIFY24-06-28 16:52:58
+ * @LastEditTime: 2024-09-05 09:33:51
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp
* @Description:
*
uint32_t creationTime;
int ret = uapi_get_timestampe_ss(&creationTime);
- sprintf_s(file_path, 64, SLEEP_PATH, day, creationTime);
+ sprintf_s(file_path, 64, NAP_PATH, day, creationTime);
FILE *fp;
fp = fopen(file_path, "wb+");
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;
+
+ 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));
+ fall_asleep_timestamp = 0;
+ }
+
+
bool save_sleep_data(SLEEP_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');
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);
+ 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(file_path, "wb+");
+ fp = fopen(time_file_path, "wb+");
if (fp == NULL)
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "save_nap_sleep_data fopen fail");
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "save_sleep_data fopen fail");
return false;
}
uint8_t sleep_type = 1;
fwrite(&sleep_type, 1, 1, fp);
- uint32_t fall_asleep_timestamp = data->fall_asleep_timestamp;
+ if(fall_asleep_timestamp == 0)
+ {
+ 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;
+ 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);
- uint16_t total_deep_sleep_time = data->total_deep_sleep_time;
+ 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);
- uint16_t total_mild_sleep_time = data->total_mild_sleep_time;
+ 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);
- uint16_t total_rem_sleep_time = data->total_rem_sleep_time;
+ 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);
- uint16_t total_wake_time = data->total_wake_time;
+ 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(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(time_file_path, "wb+");
+ }
+ else
+ {
+ fp = fopen(time_file_path, "ab+");
+ }
+
+ if (fp == NULL)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "save_sleep_data fopen fail");
+ return false;
+ }
fwrite(data->sleep_status, sizeof(SLEEP_STATE_T), data->status_num, fp);
fclose(fp);
uapi_get_YYMMDD_Time(day, '\0');
char file_path[64] = {0};
- sprintf_s(file_path, 64, "%s%s/", SLEEP_DATA_DIR, day);
-
- // 打开目录
- DIR *dir;
- struct dirent *ent;
- if ((dir = opendir(file_path)) != NULL)
+ sprintf_s(file_path, 64, SLEEP_TIME_PATH, day);
+
+ FILE *fp = fopen(file_path, "rb");
+ if (fp == NULL)
{
- while ((ent = readdir(dir)) != NULL)
- {
- char file_name[64];
- sprintf_s(file_name, 64, "%s%s", file_path, ent->d_name);
-
- if (is_regular_file(file_name)) // 判断是否为文件
- {
- FILE *fp = fopen(file_name, "rb");
- if (fp == NULL)
- {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "read_sleep_data fopen fail");
- continue;
- }
-
- // 读取睡眠类型
- uint8_t sleep_type;
- fread(&sleep_type, 1, 1, fp);
-
- if (sleep_type == 0)
- {
- fclose(fp);
- continue;
- }
-
- // 入睡时间
- uint32_t fall_asleep_timestamp;
- fread(&fall_asleep_timestamp, 1, 4, fp);
-
- // 起床时间
- uint32_t wake_up_timestamp;
- fread(&wake_up_timestamp, 1, 4, fp);
-
- // 睡眠总时间
- uint8_t total_time_hour, total_time_minute;
- fread(&total_time_hour, 1, 1, fp);
- fread(&total_time_minute, 1, 1, fp);
- uint16_t total_time = total_time_hour * 60 + total_time_minute;
-
- // 累加睡眠数据
- data->fall_asleep_timestamp = (data->fall_asleep_timestamp == 0) ? fall_asleep_timestamp : min(data->fall_asleep_timestamp, fall_asleep_timestamp);
- data->wake_up_timestamp = max(data->wake_up_timestamp, wake_up_timestamp);
- data->total_time += total_time;
-
- fclose(fp);
- }
- }
- closedir(dir);
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "read_sleep_data fopen fail");
+ return false;
}
- else
+
+ // 读取睡眠类型
+ uint8_t sleep_type;
+ fread(&sleep_type, 1, 1, fp);
+
+ if (sleep_type == 0)
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "cannot open directory");
+ fclose(fp);
return false;
}
+ // 入睡时间
+ uint32_t fall_asleep_timestamp;
+ fread(&fall_asleep_timestamp, 1, 4, fp);
+
+ // 起床时间
+ uint32_t wake_up_timestamp;
+ fread(&wake_up_timestamp, 1, 4, fp);
+
+ // 睡眠总时间
+ uint8_t total_time_hour, total_time_minute;
+ fread(&total_time_hour, 1, 1, fp);
+ fread(&total_time_minute, 1, 1, fp);
+ uint16_t total_time = total_time_hour * 60 + total_time_minute;
+
+ // 累加睡眠数据
+ data->fall_asleep_timestamp = fall_asleep_timestamp;
+ data->wake_up_timestamp =wake_up_timestamp;
+ data->total_time = total_time;
+
+ fclose(fp);
+
return true;
- }
+}
+
void set_sleep_data(SLEEP_T *data)
{
memset(&sleep_data, 0, sizeof(SLEEP_T));
hand_watch_first_time_Paired();\r
svr_ble_adv_stop();\r
\r
- // gap_conn_param_update_t conn_param = { 0 };\r
- // conn_param.conn_handle = conn_id; /* param 0: conn_handle */\r
- // conn_param.interval_min =140*16; /* param 1: interval_min */\r
- // conn_param.interval_max = 160*16; /* param 2: interval_max */\r
- // conn_param.slave_latency = 20; /* param 3: slave_latency */\r
- // conn_param.timeout_multiplier = 160*32; /* param 4: timeout_multiplier */\r
- // errcode_t ret = gap_ble_connect_param_update(&conn_param);\r
- // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"gap ble update connection parameters ret: %u\n", ret); \r
+ gap_conn_param_update_t conn_param = { 0 };\r
+ conn_param.conn_handle = conn_id; /* param 0: conn_handle */\r
+ conn_param.interval_min =150; /* param 1: interval_min */\r
+ conn_param.interval_max = 150; /* param 2: interval_max */\r
+ conn_param.slave_latency = 20; /* param 3: slave_latency */\r
+ conn_param.timeout_multiplier = 160*32; /* param 4: timeout_multiplier */\r
+ errcode_t ret = gap_ble_connect_param_update(&conn_param);\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"gap ble update connection parameters ret: %u\n", ret); \r
}\r
\r
\r
{
unused(topic);
+ if(uapi_dev_runtime_get_absolute_static_status())
+ {
+ memset(&sleep_data,0,sizeof(SLEEP_T));
+ state_num = 0;
+ fall_asleep_state_num = 0;
+ uapi_dev_runtime_set_absolute_static_status(0);
+ return;
+ }
+
cywee_inactivity_accumulate_time_t *cywee_Inactivity_Accumulate_Time_Info = (cywee_inactivity_accumulate_time_t *)malloc(req->len);
if (!cywee_Inactivity_Accumulate_Time_Info)
{
int CWM_OS_dbgOutput(const char * format)
{
PRINT("%s", format);
- if(cywee_ble_service_flag)
+ if(cywee_ble_service_flag == 1)
ble_cywee_server_send_input_report((uint8_t *)format,strlen(format));
return 0;
}
uint8_t cywee_ble_service_flag = 0;
-static uint8_t is_abs_static_state = 0;
-
static char cywee_version[20] = {0};
+static uint32_t abs_static_timestampe = 0;
+static uint32_t asleep_timestampe = 0;
+
#ifdef CYWEE_MAC_ACTIVE
int cm__hs1__mac_c0_init(void);
int cm__hs1__mac_c0r_init(void);
void cywee_wearstatus_update(int wearstatus)
{
- if(is_abs_static_state == 1)
- {
- wearstatus = 0;
- is_abs_static_state = 0;
- }
memset(&csd, 0, sizeof(CUSTOM_OFFBODY_DETECT));
csd.sensorType = CUSTOM_OFFBODY_DETECT;
csd.fData[0] = wearstatus;
//0进入睡眠 1潜睡 2深睡 3清醒 4结束睡眠 6入睡 7出睡最后一笔输出 8未出睡最后一笔输出 12快速动眼 13取消入睡
if(c_inactivity_result_t.status == 6)
+ {
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);
-
+ }
cywee_func(CYWEE_MSG_TYPE_INACTIVITY_UPDATE,&c_inactivity_result_t,sizeof(cywee_inactivity_result_t));
}else if((int)sensorEVT->fData[0] == 31){
break;
case IDX_ALGO_ABSOLUTE_STATIC:
CWM_OS_dbgPrintf("IDX_ALGO_ABSOLUTE_STATIC\n");
- is_abs_static_state = 1;
+ if(uapi_dev_runtime_get_sleep_status())
+ {
+ uapi_get_timestampe_ss(&abs_static_timestampe);
+ if((abs_static_timestampe - asleep_timestampe) >= 60 * 90)
+ {
+ uapi_dev_runtime_set_absolute_static_status(1);
+ cywee_get_sleep_data();
+ }
+ else
+ {
+ cywee_inactivity_mode_change(INACTIVITY_MODE_NOTHING);
+ LOS_Msleep(50);
+ cywee_inactivity_mode_change(INACTIVITY_MODE_SLEEPING);
+ }
+ }
+
break;
case IDX_ALGO_SPV:
CWM_OS_dbgPrintf("IDX_ALGO_SPV\n");
}
#ifdef AP_ENABLE_DML_SDO_LISTEN
-void CWM_AP_dmlSensorDataOutput_listen(const dml_sensorData_t * pSdo) {
+//void CWM_AP_dmlSensorDataOutput_listen(const dml_sensorData_t * pSdo) {
+
+ // if (pSdo->validData & DML_SENSOR_DATA_VALID_DT)
+ // CWM_OS_dbgPrintf("==dt: %d us\n", pSdo->dt_us);
+
+ // if (pSdo->validData & DML_SENSOR_DATA_VALID_ACC)
+ // CWM_OS_dbgPrintf("==acc: x=%.3f, y=%.3f, z=%.3f\n", pSdo->acc_data[0], pSdo->acc_data[1], pSdo->acc_data[2]);
+//}
+
+/*增加DML sensor数据输出*/
+struct AccelerationData {
+ float dt;
+ float acc_x;
+ float acc_y;
+ float acc_z;
+};
+struct AccelerationData rawdata[25]; //自定义buffer,用来缓存sensor数据
+int AccdataCount = 0; //fifo长度
+
+void CWM_AP_dmlSensorDataOutput_listen(const dml_sensorData_t * pSdo)
+{
if (pSdo->validData & DML_SENSOR_DATA_VALID_DT)
- CWM_OS_dbgPrintf("==dt: %d us\n", pSdo->dt_us);
-
+ {
+ //CWM_OS_dbgPrintf("dt: %d us\n", pSdo->dt_us);
+ rawdata[AccdataCount].dt = pSdo->dt_us;
+ }
if (pSdo->validData & DML_SENSOR_DATA_VALID_ACC)
- CWM_OS_dbgPrintf("==acc: x=%.3f, y=%.3f, z=%.3f\n", pSdo->acc_data[0], pSdo->acc_data[1], pSdo->acc_data[2]);
+ {
+ //CWM_OS_dbgPrintf("acc: x=%.3f, y=%.3f, z=%.3f\n",pSdo->acc_data[0], pSdo->acc_data[1], pSdo->acc_data[2]);
+ rawdata[AccdataCount].acc_x = pSdo->acc_data[0];
+ rawdata[AccdataCount].acc_y = pSdo->acc_data[1];
+ rawdata[AccdataCount].acc_z = pSdo->acc_data[2];
+
+ gxyz_t.x = pSdo->acc_data[0];
+ gxyz_t.y = pSdo->acc_data[1];
+ gxyz_t.z = pSdo->acc_data[2];
+
+ if(get_acc_swtich)
+ {
+ if(num_falg==25)
+ {
+ left_falg++;
+ right_falg++;
+ right_falg=right_falg%25;
+ left_falg=left_falg%25;
+ gxyz_t_queue[right_falg].x= pSdo->acc_data[0];
+ gxyz_t_queue[right_falg].y= pSdo->acc_data[1];
+ gxyz_t_queue[right_falg].z= pSdo->acc_data[2];
+ }
+ else
+ {
+ //left_falg++;
+ right_falg++;
+ right_falg=right_falg%25;
+ //left_falg=left_falg%16;
+ num_falg++;
+ gxyz_t_queue[right_falg].x= pSdo->acc_data[0];
+ gxyz_t_queue[right_falg].y= pSdo->acc_data[1];
+ gxyz_t_queue[right_falg].z= pSdo->acc_data[2];
+ //CWM_OS_dbgPrintf("write: x=%d, y=%d, z=%d\n", gxyz_t_queue[right_falg].x ,gxyz_t_queue[right_falg].y ,gxyz_t_queue[right_falg].z);
+
+ }
+ }
+
+ AccdataCount++;
+ AccdataCount = AccdataCount % 25;
+ }
}
+
#endif
int cywee_main_dml(void)
memset(&scl, 0, sizeof(scl));
scl.iData[0] = 1;
+#ifdef AP_ENABLE_DML_SDO_LISTEN
+ scl.iData[2] = 4+16; //分离式DML
+#else
scl.iData[1] = 18; //00000000000000000000000000010010 高位在前
- // CWM_SettingControl(SCL_DML_DEBUG, &scl);
+#endif
+ //CWM_SettingControl(SCL_DML_DEBUG, &scl);
//设置acc gyro 相关参数
memset(&scl, 0, sizeof(scl));
memset(&scl, 0, sizeof(scl));
scl.iData[0] = 1;
scl.iData[1] = 1;
+#ifdef AP_ENABLE_DML_SDO_LISTEN
+ scl.iData[3] = 3;
+#endif
CWM_SettingControl(SCL_DML_DRV_INIT, &scl);
CWM_OS_dbgPrintf("DML device=%d\n", scl.iData[2]);
CWM_Sensor_Enable(IDX_ALGO_INACTIVITY_OUTPUT);
// CWM_Sensor_Enable(IDX_ALGO_SEDENTARY);
// CWM_Sensor_Enable(IDX_ALGO_SLEEP);
+#ifndef AP_ENABLE_DML_SDO_LISTEN
CWM_Sensor_Enable(IDX_ACCEL);
+#endif
//CWM_OS_dbgPrintf("[DBG] %s %d\n", __func__,__LINE__);
// CWM_Sensor_Enable(IDX_GYRO);
CWM_Sensor_Enable(IDX_ALGO_NO_MOTION);
return 0;
}
+#ifdef AP_ENABLE_DML_SDO_LISTEN
+
+int cwm_lib_process(void) //运行算法
+{
+ int i,ret;
+ CWM_Dml_process(); //分离式DML,获取sensor数据输出
+
+ CWM_CustomSensorInput_Fifo_Start(CUSTOM_ACC,CWM_OS_GetTimeNs(), 40 * 1000000);
+ for (uint16_t i=0; i<AccdataCount; i++)
+ {
+ memset(&csd, 0, sizeof(csd));
+ csd.sensorType = CUSTOM_ACC;
+ csd.fData[0] = rawdata[i].acc_x;
+ csd.fData[1] = rawdata[i].acc_y;
+ csd.fData[2] = rawdata[i].acc_z;
+ CWM_CustomSensorInput(&csd);
+ }
+ CWM_CustomSensorInput_Fifo_End(CUSTOM_ACC);
+ ret = CWM_process();
+ if (ret < 0) {
+ CWM_OS_dbgPrintf("FATAL ERROR! ret=%d\n", ret);
+ }
+ return 0;
+}
+
+#endif
+
void cywee_int_handler(void)
{
if(cywee_switch == 1)
+ {
+#ifdef AP_ENABLE_DML_SDO_LISTEN
+ cwm_lib_process();
+#else
CWM_Dml_process();
+#endif
+ }
+
}
uint8_t lock_status;//密码锁状态
uint8_t motion_recognition_status;//运动识别开关状态
uint8_t sleep_mode_flag; // sleep mode flag
+ uint8_t absolute_static_state; // 绝对静止状态
} runtime_status_t;
uint8_t uapi_sleep_mode_flag_get(void)
{
return g_runtime.sleep_mode_flag;
+}
+
+/*设置绝对静止状态*/
+void uapi_dev_runtime_set_absolute_static_status(uint8_t status)
+{
+ g_runtime.absolute_static_state = status;
+}
+
+uint8_t uapi_dev_runtime_get_absolute_static_status(void)
+{
+ return g_runtime.absolute_static_state;
}
\ No newline at end of file
void uapi_sleep_mode_flag_set(uint8_t flag);
uint8_t uapi_sleep_mode_flag_get(void);
+void uapi_dev_runtime_set_absolute_static_status(uint8_t status);
+uint8_t uapi_dev_runtime_get_absolute_static_status(void);
+
#ifdef __cplusplus
#if __cplusplus
}
#endif
}
-void uapi_analysis_sleep_data(char * path)
+void uapi_analysis_sleep_data(char * timepath , char *statuspath)
{
uint16_t datelen = 0;
uint8_t sleep_data[256] = {0};
char timestampe_str[10] = {0};
char status_str[10] = {0};
- uapi_get_file_data(path,sleep_data,&datelen);
+ uapi_get_file_data(timepath,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_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);
+ 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);
+ uapi_get_TIME_STR(wake_up_time,wake_up_time_str, '.', ':',DATE_H_M);
- PRINT("path : %s \n",path);
PRINT("入睡时间 : %s \n",asleep_time_str);
PRINT("出睡时间 : %s \n",wake_up_time_str);
PRINT("总时长 : %d 分钟\n",total_time);
PRINT("浅睡时长 : %d 分钟\n",total_mild_sleep_time);
PRINT("快速眼动时长 : %d 分钟\n",total_rem_sleep_time);
PRINT("清醒时长 : %d 分钟\n",total_wake_time);
- datelen -= 19;
- index = 19;
+
+ 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;
+ }
+
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);
+ 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)
strcpy(status_str,"结束睡眠");
break;
case 6:
- strcpy(status_str,"入睡(平躺60分钟触发)");
+ strcpy(status_str,"入睡通知");
break;
case 7:
strcpy(status_str,"出睡最后一笔输出");
void uapi_get_sleep_date_on_log(char *time)
{
- char *str = "user/userdata/sleep/%s";
- DIR *dir;
- struct dirent *entry;
- char filePath[64];
- char directoryPath[64] = {0};
+ char *timestr = "user/userdata/sleep/%s/sleep_time.bin";
+ char *statusstr = "user/userdata/sleep/%s/sleep_status.bin";
- sprintf(directoryPath,str,time);
+ char timefilePath[64] = {0};
+ char statusfilePath[64] = {0};
- dir = opendir(directoryPath);
- if (dir == NULL)
- {
- PRINT("open directory failed %s\n",directoryPath);
- return;
- }
+ sprintf(timefilePath,timestr,time);
+ sprintf(statusfilePath,statusstr,time);
+
+ uapi_analysis_sleep_data(timefilePath,statusfilePath);
- while ((entry = readdir(dir)) != NULL)
- {
- if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0)
- {
- snprintf(filePath, sizeof(filePath), "%s/%s", directoryPath, entry->d_name);
- uapi_analysis_sleep_data(filePath);
- }
- }
- closedir(dir);
}
extern void save_file_main(void);