Merge #1110 into sdk602patch0626 from refs/changes/1110/head 1111/target/1
author彭磊 <1624952103@qq.com>
Sat, 5 Oct 2024 08:28:27 +0000 (08:28 +0000)
committersnickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
Sat, 5 Oct 2024 08:28:27 +0000 (08:28 +0000)
修改小睡数据合并成一个文件

* refs/changes/1110/head: (2 commits squashed)

  - 修改小睡数据合并成一个文件

  - 修改小睡数据存入一个文件(默认关闭 待协议调通)

Signed-off-by: aliyun6865282430 <1624952103@qq.com>
Reviewed-by: snickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
Merged-by: snickersun@163.com <accounts_62b90f7fcf51ade33b6f628e@mail.teambition.com>
link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/1110
code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h
code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp

index b9a2bb5..82e65a6 100644 (file)
@@ -2,7 +2,7 @@
  * @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/"
@@ -70,6 +76,7 @@ namespace OHOS
 #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);
index a1bd3a6..0df910b 100644 (file)
@@ -2,7 +2,7 @@
  * @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:
@@ -94,6 +94,28 @@ namespace OHOS
   }
 
   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)
   {
@@ -126,15 +148,22 @@ namespace OHOS
     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);
@@ -200,6 +229,7 @@ namespace OHOS
     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)
@@ -528,7 +558,8 @@ namespace OHOS
       return false;
     }
 
-    // 读取睡眠类型
+#ifndef NAPTEST
+    //读取睡眠类型
     uint8_t sleep_type;
     fread(&sleep_type, 1, 1, fp);
 
@@ -538,7 +569,10 @@ namespace OHOS
       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);