From: Caisking Date: Mon, 9 Mar 2026 10:02:01 +0000 (+0800) Subject: 修改压力的存储 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=ee00e0e720e64971958bf16214183935050d12c6;p=mirrors%2FFD230.git 修改压力的存储 --- diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/stress/src/stressTestModel.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/stress/src/stressTestModel.cpp index 7452169a0..83346cfe5 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/stress/src/stressTestModel.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/stress/src/stressTestModel.cpp @@ -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(×tamp, 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", ×tamp, &value) == 2) + // 二进制读取:每条记录为 uint32_t 时间戳 + uint16_t 结果值 + while (fread(×tamp, sizeof(uint32_t), 1, fp) == 1 && + fread(&value, sizeof(uint16_t), 1, fp) == 1) { if (value > 0 && value <= 100) // 有效性检查 { diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/TraingCardPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/TraingCardPresenter.cpp index e3f1aa68d..6601ed471 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/TraingCardPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/TraingCardPresenter.cpp @@ -344,14 +344,14 @@ bool TraingCardPresenter::OnDragEnd(UIView &view, const DragEvent &event) { void TraingCardPresenter::updataview(void) { // 如果未开启训练,直接退出 if (TraingModel::GetInstance()->GetSportState() == ExerciseState::General) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TraingModel::GetInstance()->GetSportState() == " "ExerciseState::General "); return; } if (TraingCardView::GetInstance() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "view_ == nullptr"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "view_ == nullptr"); return; }