修改压力的存储
authorCaisking <Casiking@zhihuishixun.com>
Mon, 9 Mar 2026 10:02:01 +0000 (18:02 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Mon, 9 Mar 2026 10:02:01 +0000 (18:02 +0800)
code/sdk/application/wearable/fd272/nativeapp/nativeui/stress/src/stressTestModel.cpp
code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/TraingCardPresenter.cpp

index 7452169..83346cf 100644 (file)
@@ -172,20 +172,21 @@ namespace OHOS
         // 获取日期字符串(格式:YYYY_MM_DD)
         std::string dateStr = GetDaysAgoDateString();
 
-        // 构建文件路径
+        // 构建文件路径(以 .bin 为后缀进行存储)
         char filePath[256] = {0};
-        snprintf(filePath, sizeof(filePath), "%s%s.txt", STRESS_TEST_HISTORY_DIR, dateStr.c_str());
+        snprintf(filePath, sizeof(filePath), "%s%s.bin", STRESS_TEST_HISTORY_DIR, dateStr.c_str());
 
-        // 追加模式打开文件
-        FILE *fp = fopen(filePath, "a+");
+        // 二进制追加模式打开文件
+        FILE *fp = fopen(filePath, "ab");
         if (fp == nullptr)
         {
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "打开历史记录文件失败: %s", filePath);
             return;
         }
 
-        // 写入格式:时间戳(秒) + 结果值,每行一条记录
-        fprintf(fp, "%u %u\n", timestamp, value);
+        // 二进制写入:每条记录为 uint32_t 时间戳 + uint16_t 结果值
+        fwrite(&timestamp, sizeof(uint32_t), 1, fp);
+        fwrite(&value, sizeof(uint16_t), 1, fp);
         fclose(fp);
 
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "保存历史记录: date=%s, timestamp=%u, value=%u",
@@ -200,9 +201,9 @@ namespace OHOS
             return -1;
         }
 
-        // 构建文件路径
+        // 构建文件路径(以 .bin 为后缀进行读取)
         char filePath[256];
-        snprintf(filePath, sizeof(filePath), "%s%s.txt", STRESS_TEST_HISTORY_DIR, dateStr);
+        snprintf(filePath, sizeof(filePath), "%s%s.bin", STRESS_TEST_HISTORY_DIR, dateStr);
 
         // 先检查文件是否存在
         if (access(filePath, F_OK) == -1) {
@@ -210,7 +211,7 @@ namespace OHOS
             return -1;
         }
 
-        FILE *fp = fopen(filePath, "r");
+        FILE *fp = fopen(filePath, "rb");
         if (fp == nullptr)
         {
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "打开日期文件失败: %s, 错误: %s", filePath, strerror(errno));
@@ -222,8 +223,9 @@ namespace OHOS
         uint32_t timestamp = 0;
         uint16_t value = 0;
 
-        // 读取所有记录并计算平均值
-        while (fscanf(fp, "%u %u", &timestamp, &value) == 2)
+        // 二进制读取:每条记录为 uint32_t 时间戳 + uint16_t 结果值
+        while (fread(&timestamp, sizeof(uint32_t), 1, fp) == 1 &&
+               fread(&value, sizeof(uint16_t), 1, fp) == 1)
         {
             if (value > 0 && value <= 100) // 有效性检查
             {
index e3f1aa6..6601ed4 100644 (file)
@@ -344,14 +344,14 @@ bool TraingCardPresenter::OnDragEnd(UIView &view, const DragEvent &event) {
  void TraingCardPresenter::updataview(void) {\r
    // 如果未开启训练,直接退出\r
    if (TraingModel::GetInstance()->GetSportState() == ExerciseState::General) {\r
-     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,\r
+     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,\r
                    "TraingModel::GetInstance()->GetSportState() == "\r
                    "ExerciseState::General ");\r
      return;\r
    }\r
  \r
    if (TraingCardView::GetInstance() == nullptr) {\r
-     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "view_ == nullptr");\r
+     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "view_ == nullptr");\r
      return;\r
    }\r
  \r