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
#include <fstream>
#include <ctime>
#include <cstdint>
+#include <string>
#define HEART_MAX_POINTS 360
#define MSG_SAVE_TEST 0
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]; // 存储心率值,检测时间戳?使用结构体?
<< "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);