* @Author: penglei 1624952103@qq.com
* @Date: 2024-06-26 19:36:48
* @LastEditors: penglei 1624952103@qq.com
- * @LastEditTime: 2024-10-04 15:37:02
+ * @LastEditTime: 2024-10-05 16:14:11
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h
* @Description:
*
// #include "sleep/include/SleepControlPresenter.h"
#include "string"
+// #define NAPTEST
+
+
#define SLEEP_TIME_PATH "user/userdata/sleep/%s/sleep_time.bin"
#define SLEEP_STATUS_PATH "user/userdata/sleep/%s/sleep_status.bin"
+#ifndef NAPTEST
#define NAP_PATH "user/userdata/sleep/%s/nap_%d.bin"
-
+#else
+#define NAP_PATH "user/userdata/sleep/%s/nap.bin"
+#endif
#define SLEEP_DIR_PATH "user/userdata/sleep/%s"
#define SLEEP_DATA_DIR "user/userdata/sleep/"
#pragma pack (pop)
bool save_nap_data(NAP_T *data);
+ uint8_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);
* @Author: penglei 1624952103@qq.com
* @Date: SLEPPNOTIFY24-06-26 19:36:48
* @LastEditors: penglei 1624952103@qq.com
- * @LastEditTime: 2024-10-04 17:01:22
+ * @LastEditTime: 2024-10-05 16:10:03
* @FilePath:
* /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp
* @Description:
}
static char nap_file_path[64] = {0};
+
+ //获取小睡数据长度(协议用)
+ uint8_t get_nap_data_size(void)
+ {
+ #ifdef NAPTEST
+ FILE *fp;
+ uint8_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;
+ #else
+ return 0;
+ #endif
+ }
bool save_nap_data(NAP_T *data)
{
sprintf_s(nap_file_path, 64, NAP_PATH, day, creationTime);
FILE *fp;
+#ifdef NAPTEST
+ fp = fopen(nap_file_path, "ab+"); //小睡数据全部存入一个文件
+#else
fp = fopen(nap_file_path, "wb+");
+#endif
if (fp == NULL)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "save_nap_sleep_data %s fopen fail ", nap_file_path);
return false;
}
- uint8_t sleep_type = 0;
+
+#ifndef NAPTEST
+ uint8_t sleep_type = 0; //不存睡眠类型 改用文件名判断
fwrite(&sleep_type, 1, 1, fp);
+#endif
uint32_t fall_asleep_timestamp = data->fall_asleep_timestamp;
fwrite(&fall_asleep_timestamp, 1, 4, fp);
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)
return false;
}
- // 读取睡眠类型
+#ifndef NAPTEST
+ //读取睡眠类型
uint8_t sleep_type;
fread(&sleep_type, 1, 1, fp);
fclose(fp);
return false;
}
-
+#else
+ if(get_nap_data_size() > 10) //存在多段小睡 UI显示最新的一次数据
+ fseek(fp, -10, SEEK_END);//移到最后一段数据
+#endif
// 入睡时间
uint32_t fall_asleep_timestamp;
fread(&fall_asleep_timestamp, 1, 4, fp);