From 4952a8a9348fcda873167e5ed15facee3801d39d Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Fri, 29 Nov 2024 21:05:52 +0800 Subject: [PATCH] =?utf8?q?=E5=BF=83=E7=8E=87=EF=BC=9A=E4=BC=98=E5=8C=96?= =?utf8?q?=E5=BF=83=E7=8E=87=E6=95=B0=E6=8D=AE=E7=9A=84debug=E7=95=8C?= =?utf8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../health_service/health_service.cpp | 43 +++++++++++++++++++ .../health_service/health_service.h | 5 +++ .../debug_output_notification.cpp | 7 ++- 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp index 629ae1d2a..5a7f32400 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp @@ -692,4 +692,47 @@ void HealthService::send_blood_save() { do_custom_fileoperate_service_check_msg( CUSTOM_FILEOPERATE_MSG_TYPE_BLOODXYGEN_SAVE, nullptr, 0); } + +std::string HealthService::formatTime(uint32_t time) { + char labelTime[20]; + if (uapi_get_TIME_STR(time, labelTime, '.', ':', DATE_Y_M_D_H_M) != + ERRCODE_SUCC) { + return "--"; // 默认值 + } else { + return labelTime; // 成功获取时间 + } +} +// 读取心率数据 +std::string HealthService::get_heart_data() { + std::string binFilePath = GetBinFilePath(HEALTH_TYPE_HEART); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "binFilePath %s", binFilePath.c_str()); + FILE *fp = fopen(binFilePath.c_str(), "rb"); // 以二进制读取模式打开文件 + if (fp == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "Failed to open binary file for reading"); + return "Error: Unable to open file \n"; // 返回错误信息 + } + + std::string result; + HeartRateData data; + + result += "file:" + binFilePath + "\n"; + + // 读取数据直到文件结束 + while (fread(&data, sizeof(HeartRateData), 1, fp) == 1) { + // 将数据格式化为字符串,拼接到结果中 + result += + formatTime(data.timestamp) + "," + std::to_string(data.Heart) + "\n"; + } + + if (ferror(fp)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "Error reading data from binary file"); + fclose(fp); + return "Error: Reading error \n"; // 返回读取错误信息 + } + + fclose(fp); // 关闭文件 + return result.empty() ? "No data found \n" : result; // 检查是否读取到数据 +} } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.h b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.h index 4ab119d10..f7df7d823 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.h +++ b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.h @@ -13,6 +13,7 @@ #include #include #include +#include #define HEART_MAX_POINTS 360 #define MSG_SAVE_TEST 0 @@ -100,6 +101,10 @@ namespace OHOS void send_heart_save(); void send_blood_save(); + std::string get_heart_data(); + std::string get_blood_data(); + std::string formatTime(uint32_t time); + private: static const int MAX_HOURS = 24; HeartRateData dailyHeartRates[MAX_HOURS]; // 存储心率值,检测时间戳?使用结构体? diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp index c6589d240..7fd0c5f6c 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp @@ -578,8 +578,13 @@ namespace OHOS << "Time: " << timestr << "\n"; result << "=====================\n"; + + // 3.读取文件里面的心率数据 + auto healthService = HealthService::GetInstance(); + result << healthService->get_heart_data(); + result << "=====================\n"; - // 3. 获取一天的心率列表 + // 4. 获取一天的心率列表 result << "Today's HeartRate list\n"; for (int serialIndex = 0; serialIndex < 24; ++serialIndex) { uint32_t heartRate = HealthService::GetInstance()->GetHourlyHeartRate(serialIndex); -- 2.17.1