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++)
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<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(); // 返回完整结果
}
+ 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_log_data> 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();
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;