From: luozheng <1732036298@qq.com> Date: Sat, 19 Oct 2024 08:04:13 +0000 (+0800) Subject: Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0... X-Git-Tag: release_V1.2.70_20241020_135402~5^2~6 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=a9853e2126959fb7fce64006685c0e4baffcfc1a;p=mirrors%2FFD230.git Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 --- a9853e2126959fb7fce64006685c0e4baffcfc1a diff --cc code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h index 7d4eaefe0,8c3317107..8eec1dd59 --- 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 @@@ -1,8 -1,8 +1,8 @@@ /* * @Author: luozheng 1732036298@qq.com * @Date: 2024-10-02 14:12:12 - * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-10-08 16:29:19 + * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-10-18 18:45:48 ++ * @LastEditTime: 2024-10-19 15:52:33 * @FilePath: /FD230/code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification.h */ #ifndef DEBUG_OUTPUT_NOTIFICATION_H @@@ -42,7 -42,7 +42,8 @@@ namespace OHO std::string get_sleep_time(void); std::string get_free_memory(void); std::string get_nextday_log(void); + std::string get_heart_rate(void); + std::string get_popup_windows_log(void); private: DebugOutputViewEventListener(); diff --cc code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp index 299c9969b,bd20513e3..1bccc65a0 --- 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 @@@ -76,24 -85,24 +85,26 @@@ namespace OHO void DebugOutputViewEventListener::InitDebugOutputItem() { int index = 0; - debugOutputItemInfo[index++] = {0, "exit"}; // 标题:设置() - debugOutputItemInfo[index++] = {1, "bt_ble_connectstat"}; - debugOutputItemInfo[index++] = {2, "cat1_runtime_status_t"}; - debugOutputItemInfo[index++] = {3, "runtime_status_t"}; - //系统日志 - debugOutputItemInfo[index++] = {4, "system_log"}; - //电池服务 - debugOutputItemInfo[index++] = {5, "battery_service"}; - //死机文件列表 - debugOutputItemInfo[index++] = {6, "shutdown_file_list"}; - //睡眠数据 - debugOutputItemInfo[index++] = {7, "sleep_time"}; - //系统空闲内存 - debugOutputItemInfo[index++] = {8, "system_free_memory"}; + debugOutputItemInfo[index++] = {index, "exit"}; // 标题:设置() + debugOutputItemInfo[index++] = {index, "bt_ble_connectstat"}; + debugOutputItemInfo[index++] = {index, "cat1_runtime_status_t"}; + debugOutputItemInfo[index++] = {index, "runtime_status_t"}; + // 系统日志 + debugOutputItemInfo[index++] = {index, "system_log"}; + // 电池服务 + debugOutputItemInfo[index++] = {index, "battery_service"}; + // 死机文件列表 + debugOutputItemInfo[index++] = {index, "shutdown_file_list"}; + // 睡眠数据 + debugOutputItemInfo[index++] = {index, "sleep_time"}; + // 系统空闲内存 + debugOutputItemInfo[index++] = {index, "system_free_memory"}; // nextday执行日志 - debugOutputItemInfo[index++] = {9, "nextday_log"}; - // 读取心率 - debugOutputItemInfo[index++] = {10, "heart_rate"}; + debugOutputItemInfo[index++] = {index, "nextday_log"}; ++ // 读取心率 ++ debugOutputItemInfo[index++] = {index, "heart_rate"}; + // 弹窗日志 + debugOutputItemInfo[index++] = {index, "popup_windows_log"}; usedLen = index; /* -------------------------------- Add data -------------------------------- */ for (uint8_t i = 0; i < usedLen; i++) @@@ -370,86 -376,108 +381,162 @@@ return result; } - //获取nextday执行日志 - std::string DebugOutputViewEventListener::get_nextday_log() { - std::ostringstream result; - result << "nextday_log:\n"; // 添加标题 - - auto logModel = SystemLogModel::GetInstance(); - const auto& nextday_logs = logModel->get_nextday_log(); - - // 遍历日志并拼接到结果字符串 - for (const auto &log : nextday_logs) { - // 格式化时间 - char labelTime[20]; - std::string timestr; - - // 调用时间格式化函数 - if (uapi_get_TIME_STR(log, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC) { - timestr = "--"; // 如果获取时间失败,使用默认值 - } else { - timestr = labelTime; // 成功获取时间 - } - - result << "[" << timestr << "] "; // 使用格式化后的时间拼接日志记录 - } + std::string DebugOutputViewEventListener::get_nextday_log() + { + std::ostringstream result; + result << "nextday_log:\n"; // 添加标题 + + auto logModel = SystemLogModel::GetInstance(); + const auto &nextday_logs = logModel->get_nextday_log(); + + // 遍历日志并拼接到结果字符串 + for (const auto &log : nextday_logs) + { + // 格式化时间 + char labelTime[20]; + std::string timestr; + // 调用时间格式化函数 + if (uapi_get_TIME_STR(log, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC) + { + timestr = "--"; // 如果获取时间失败,使用默认值 + } + else + { + timestr = labelTime; // 成功获取时间 + } + + 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(); // 返回完整结果 } + std::string DebugOutputViewEventListener::get_popup_windows_log(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_popup_windows_log"); + // 获取系统日志实例 + auto logModel = SystemLogModel::GetInstance(); + uint8_t logSize = logModel->get_popup_windows_log_size(); + if (logSize == 0) + { + return "目前没有日志"; + } + + std::deque popup_windows_logs = logModel->get_popup_windows_log(); + std::ostringstream str; + + for (int i = 0; i < logSize; i++) + { + // 处理日志类型 + switch (popup_windows_logs[i].type) + { + case popup_windows_type::MOTION_RECOGNITION: + str << "运动识别:"; + break; + case popup_windows_type::DRINK_WATER_REMINDER: + str << "喝水提醒:"; + break; + case popup_windows_type::SEDENTARY_REMINDER: + str << "久坐提醒:"; + break; + default: + str << "UNKNOWN:"; + break; + } + str << "\n"; + // 格式化时间 + char labelTime[20]; + std::string timestr; + if (uapi_get_TIME_STR(popup_windows_logs[i].timestamp, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC) + { + timestr = "--"; + } + else + { + timestr = labelTime; + } + str << "[" << timestr << "] " << "\n"; // 拼接日志内容 + } + return str.str(); // 返回拼接后的字符串 + } + bool DebugOutputViewEventListener::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) { std::string viewId = view.GetViewId(); @@@ -515,8 -543,8 +602,11 @@@ str = get_nextday_log(); break; case 10: - str = get_popup_windows_log(); + str = get_heart_rate(); + break; ++ case 11: ++ str = get_heart_rate(); + break; default: str = "--"; break;