From 2df996b0e85a89609c8f962840b7f872602bee2e Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Fri, 18 Oct 2024 11:46:39 +0800 Subject: [PATCH] =?utf8?q?=E7=B3=BB=E7=BB=9F=EF=BC=9A=E5=A2=9E=E5=8A=A0?= =?utf8?q?=E5=BF=83=E7=8E=87=E6=95=B0=E6=8D=AE=E7=9A=84=E6=97=A5=E5=BF=97?= =?utf8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../debug_output_notification.h | 1 + .../debug_output_notification.cpp | 95 ++++++++++++++++++- 2 files changed, 93 insertions(+), 3 deletions(-) diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h b/code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h index 821a4d392..8c3317107 100644 --- a/code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h +++ b/code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h @@ -42,6 +42,7 @@ namespace OHOS std::string get_sleep_time(void); std::string get_free_memory(void); std::string get_nextday_log(void); + std::string get_heart_rate(void); private: DebugOutputViewEventListener(); 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 134d2c358..bd20513e3 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 @@ -27,7 +27,6 @@ #include "vibrator_service.h" #include "wearable_log.h" #include - #include #include #include @@ -46,7 +45,17 @@ #include #include "bleService.h" #include "sleep/include/SleepModel.h" +#include "heartrate/include/HeartModel.h" +#include "heart_blood/health_service/health_service.h" #include "BluetoothModel.h" +#include +#include +#include +#include +#include +#include +#include + namespace OHOS { @@ -92,6 +101,8 @@ namespace OHOS debugOutputItemInfo[index++] = {8, "system_free_memory"}; // nextday执行日志 debugOutputItemInfo[index++] = {9, "nextday_log"}; + // 读取心率 + debugOutputItemInfo[index++] = {10, "heart_rate"}; usedLen = index; /* -------------------------------- Add data -------------------------------- */ for (uint8_t i = 0; i < usedLen; i++) @@ -365,7 +376,7 @@ result += "advdata:" + (getCurrentWatchadvdata()) + " "; return result; } - + //获取nextday执行日志 std::string DebugOutputViewEventListener::get_nextday_log() { std::ostringstream result; result << "nextday_log:\n"; // 添加标题 @@ -389,7 +400,82 @@ result += "advdata:" + (getCurrentWatchadvdata()) + " "; result << "[" << timestr << "] "; // 使用格式化后的时间拼接日志记录 } - return result.str(); + return result.str(); + } + + // 定义心率数据文件夹的路径 + static const char *HEART_DATA_PATH = "/user/userdata/health/heart"; + + // 函数:读取文件夹中的文件 + std::vector readDirectory(const char *path) { + std::vector fileNames; // 存储读取的文件名 + struct dirent *entry; // 定义目录项 + + // 打开目录 + DIR *dir = opendir(path); + if (!dir) { + std::cerr << "Error opening directory: " << path << " - " << strerror(errno) << std::endl; + return fileNames; // 返回空列表 + } + + // 读取目录项 + while ((entry = readdir(dir)) != nullptr) { + // 跳过 . 和 .. + if (entry->d_name[0] != '.') { + fileNames.push_back(entry->d_name); // 存储文件名 + } + } + + // 关闭目录 + closedir(dir); + return fileNames; + } + + // 主要函数:获取心率 + std::string DebugOutputViewEventListener::get_heart_rate() { + std::ostringstream result; + + // 1. 读取文件并形成文件名字符串 + std::vector heartFiles = readDirectory(HEART_DATA_PATH); + if (heartFiles.empty()) { + result << "No heart rate files found in directory.\n"; + } else { + result << "Heart rate files:\n"; + for (const auto &file : heartFiles) { + result << file << "\n"; // 输出文件名 + } + } + + result << "=====================\n"; + + // 2. 获取模型里的数据(当前值与时间) + auto heartModel = HeartModel::GetInstance(); + uint32_t checkTime = heartModel->GetCheckTime(); + uint16_t currentHeartRate = heartModel->GetHeartdata(); + + // 格式化时间 + char labelTime[20]; + std::string timestr; + if (uapi_get_TIME_STR(checkTime, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC) { + timestr = "--"; // 默认值 + } else { + timestr = labelTime; // 成功获取时间 + } + + result << "CurrentHeart: " << currentHeartRate <<"\n" + << "CheckTime: " << timestr << "\n"; + + result << "=====================\n"; + + result << "Today's HeartRate list\n"; + // 3. 获取一天的心率列表 + for (int serialIndex = 0; serialIndex < 24; ++serialIndex) { + uint32_t heartRate = HealthService::GetInstance()->GetHourlyHeartRate(serialIndex); + result << "Hour " << serialIndex << ": " << heartRate << " bmp\n"; // 输出每小时的心率 + } + + result << "=====================\n"; + return result.str(); // 返回完整结果 } bool DebugOutputViewEventListener::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) @@ -456,6 +542,9 @@ result += "advdata:" + (getCurrentWatchadvdata()) + " "; case 9: str = get_nextday_log(); break; + case 10: + str = get_heart_rate(); + break; default: str = "--"; break; -- 2.17.1