#include "vibrator_service.h"
#include "wearable_log.h"
#include <array>
-
#include <cmsis_os2.h>
#include <cstdint>
#include <custom_runtime.h>
#include <cerrno>
#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 <iostream>
+#include <sstream>
+#include <vector>
+#include <dirent.h>
+#include <string>
+#include <cstring>
+#include <cstdint>
+
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++)
return result;
}
-
+ //获取nextday执行日志
std::string DebugOutputViewEventListener::get_nextday_log() {
std::ostringstream result;
result << "nextday_log:\n"; // 添加标题
result << "[" << timestr << "] "; // 使用格式化后的时间拼接日志记录
}
- return result.str();
+ return result.str();
+ }
+
+ // 定义心率数据文件夹的路径
+ static const char *HEART_DATA_PATH = "/user/userdata/health/heart";
+
+ // 函数:读取文件夹中的文件
+ std::vector<std::string> readDirectory(const char *path) {
+ std::vector<std::string> 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<std::string> 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)
case 9:
str = get_nextday_log();
break;
+ case 10:
+ str = get_heart_rate();
+ break;
default:
str = "--";
break;