From: Caisking <3449750381@qq.com> Date: Fri, 29 Nov 2024 13:05:52 +0000 (+0800) Subject: 心率:优化心率数据的debug界面 X-Git-Tag: fd230_release_V1.3.102~18 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=4952a8a9348fcda873167e5ed15facee3801d39d;p=mirrors%2FFD230.git 心率:优化心率数据的debug界面 --- 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);