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++] = {index, "nextday_log"};
+ // 弹窗日志
+ debugOutputItemInfo[index++] = {index, "popup_windows_log"};
usedLen = index;
/* -------------------------------- Add data -------------------------------- */
for (uint8_t i = 0; i < usedLen; i++)
char *buf_btaddr = (char *)malloc(32);
if (buf_btaddr == NULL)
return "";
- memset_s(buf_btaddr,32,0,32);
+ memset_s(buf_btaddr, 32, 0, 32);
uint8_t ret = uapi_get_btaddr((uint8_t *)buf_btaddr, &len);
std::string str = std::string(buf_btaddr);
printf("%s | %s \n", buf_btaddr, str.c_str());
return (str);
}
- static std::string getCurrentWatchadvdata()
+ static std::string getCurrentWatchadvdata()
{
uint32_t len = 64;
char *buf_advdata = (char *)malloc(len);
if (buf_advdata == NULL)
return "";
- memset_s(buf_advdata,64,0,64);
+ memset_s(buf_advdata, 64, 0, 64);
get_adv_data(buf_advdata);
-
std::string str = std::string(buf_advdata);
printf("%s | %s \n", buf_advdata, str.c_str());
return (str);
}
-
-
std::string DebugOutputViewEventListener::get_bt_runtime_status_t(void)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_bt_runtime_status_t");
result += "bt_earphone_connectstat:" + std::to_string(uapi_dev_runtime_get_earphone_connect_stat()) + " ";
result += "android_app_connected:" + std::to_string(get_ble_pair()) + " ";
result += "localAddress:" + (getCurrentWatchMacAddress()) + " ";
-result += "advdata:" + (getCurrentWatchadvdata()) + " ";
+ result += "advdata:" + (getCurrentWatchadvdata()) + " ";
result += "ble广播状态:" + std::to_string(get_ble_adv_status());
// 蓝牙ble广播开关,基础信息如,地址,广播状态
result += "lock_flag_training:" + std::to_string(uapi_dev_runtime_get_train_storage_status()) + " ";
result += "lock_flag_heartrate:" + std::to_string(uapi_dev_runtime_get_heartrate_storage_status()) + " ";
result += "lock_flag_blood:" + std::to_string(uapi_dev_runtime_get_bloodoxygen_storage_status()) + " ";
- result += "lock_flag_sleep:" + std::to_string(uapi_dev_runtime_get_sleep_storage_status()) + " ";;
- result += "nap_monitoring_status:" + std::to_string(uapi_dev_runtime_get_nap_monitoring_status()) + " ";;
- result += "nap_status:" + std::to_string(uapi_dev_runtime_get_nap_status()) + " ";;
- result += "sleep_monitoring_status:" + std::to_string(uapi_dev_runtime_get_sleep_monitoring_status()) + " ";;
- result += "sleep_status:" + std::to_string(uapi_dev_runtime_get_sleep_status()) + " ";;
- result += "lock_flag_goal:" + std::to_string(uapi_dev_runtime_get_goal_storage_status()) + " ";;
- result += "respiratory_training_status:" + std::to_string(uapi_dev_runtime_get_respiratory_training_status()) + " ";;
- result += "heartrate_detect_status:" + std::to_string(uapi_dev_runtime_get_heartrate_detect_status()) + " ";;
- result += "factory_test_status:" + std::to_string(uapi_dev_runtime_get_factory_test_status_flag()) + " ";;
- result += "screen_always_on_status:" + std::to_string(uapi_dev_runtime_get_screen_always_on_status()) + " ";;
+ result += "lock_flag_sleep:" + std::to_string(uapi_dev_runtime_get_sleep_storage_status()) + " ";
+ result += "nap_monitoring_status:" + std::to_string(uapi_dev_runtime_get_nap_monitoring_status()) + " ";
+ result += "nap_status:" + std::to_string(uapi_dev_runtime_get_nap_status()) + " ";
+ result += "sleep_monitoring_status:" + std::to_string(uapi_dev_runtime_get_sleep_monitoring_status()) + " ";
+ result += "sleep_status:" + std::to_string(uapi_dev_runtime_get_sleep_status()) + " ";
+ result += "lock_flag_goal:" + std::to_string(uapi_dev_runtime_get_goal_storage_status()) + " ";
+ result += "respiratory_training_status:" + std::to_string(uapi_dev_runtime_get_respiratory_training_status()) + " ";
+ result += "heartrate_detect_status:" + std::to_string(uapi_dev_runtime_get_heartrate_detect_status()) + " ";
+ result += "factory_test_status:" + std::to_string(uapi_dev_runtime_get_factory_test_status_flag()) + " ";
+ result += "screen_always_on_status:" + std::to_string(uapi_dev_runtime_get_screen_always_on_status()) + " ";
return result;
}
// 日志服务
- std::string DebugOutputViewEventListener::get_system_log()
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_system_log");
-
- // 获取系统日志实例
- auto logModel = SystemLogModel::GetInstance();
- uint8_t logSize = logModel->getLogSize();
- if (logSize == 0)
- {
- return "目前没有日志";
- }
-
- std::deque<SystemLogData> systemlogs = logModel->getLogData();
- std::ostringstream str;
-
- for (int i = 0; i < logSize; i++)
- {
- // 处理日志类型
- switch (systemlogs[i].type)
- {
- case SystemLogType::POWER_ON:
- str << "开机:";
- break;
- case SystemLogType::POWER_OFF:
- str << "关机:";
- break;
- case SystemLogType::RESTART:
- str << "重启:";
- break;
- case SystemLogType::FACTORY_RESET:
- str << "恢复出厂设置:";
- break;
- case SystemLogType::SOFTWARE_UPDATE:
- str << "软件更新:";
- break;
- default:
- str << "UNKNOWN:";
- break;
- }
-
- // 格式化时间
- char labelTime[20];
- std::string timestr;
- if (uapi_get_TIME_STR(systemlogs[i].timestamp, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC)
- {
- timestr = "--";
- }
- else
- {
- timestr = labelTime;
- }
-
- str << "[" << timestr << "] "<< "\n"; // 拼接日志内容
- }
+ std::string DebugOutputViewEventListener::get_system_log()
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_system_log");
+
+ // 获取系统日志实例
+ auto logModel = SystemLogModel::GetInstance();
+ uint8_t logSize = logModel->getLogSize();
+ if (logSize == 0)
+ {
+ return "目前没有日志";
+ }
+
+ std::deque<SystemLogData> systemlogs = logModel->getLogData();
+ std::ostringstream str;
+
+ for (int i = 0; i < logSize; i++)
+ {
+ // 处理日志类型
+ switch (systemlogs[i].type)
+ {
+ case SystemLogType::POWER_ON:
+ str << "开机:";
+ break;
+ case SystemLogType::POWER_OFF:
+ str << "关机:";
+ break;
+ case SystemLogType::RESTART:
+ str << "重启:";
+ break;
+ case SystemLogType::FACTORY_RESET:
+ str << "恢复出厂设置:";
+ break;
+ case SystemLogType::SOFTWARE_UPDATE:
+ str << "软件更新:";
+ break;
+ default:
+ str << "UNKNOWN:";
+ break;
+ }
+
+ // 格式化时间
+ char labelTime[20];
+ std::string timestr;
+ if (uapi_get_TIME_STR(systemlogs[i].timestamp, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC)
+ {
+ timestr = "--";
+ }
+ else
+ {
+ timestr = labelTime;
+ }
+
+ str << "[" << timestr << "] " << "\n"; // 拼接日志内容
+ }
return str.str(); // 返回拼接后的字符串
}
-
+
// 获取电池相关信息
- std::string DebugOutputViewEventListener::get_battery_info() {
- // 获取电池温度
- float bat_temp = 0.0f;
- batteryservice_get_battery_temp(&bat_temp);
-
- // 获取 PCB 温度
- float pcb_temp = 0.0f;
- batteryservice_get_pcb_temp(&pcb_temp);
-
- // 获取电量
- float voltage = 0.0f;
- uint8_t percent = batteryservice_get_voltage(&voltage);
-
- // 获取充电状态
- bool isCharging = get_charge_stat();
-
- // 拼接字符串,并简化为保留两位小数
- std::ostringstream oss;
- oss << std::fixed
- << std::setprecision(2) // 设置为固定小数位,保留两位小数
- << "Bat Temp: " << bat_temp << " °C\n"
- << "PCB Temp: " << pcb_temp << " °C\n"
- << "Voltage: " << voltage << " V\n"
- << "Percent: " << static_cast<int>(percent)
- << " %\n"
- << "Charge: " << (isCharging ? "Yes" : "No");
-
- return oss.str();
+ std::string DebugOutputViewEventListener::get_battery_info()
+ {
+ // 获取电池温度
+ float bat_temp = 0.0f;
+ batteryservice_get_battery_temp(&bat_temp);
+
+ // 获取 PCB 温度
+ float pcb_temp = 0.0f;
+ batteryservice_get_pcb_temp(&pcb_temp);
+
+ // 获取电量
+ float voltage = 0.0f;
+ uint8_t percent = batteryservice_get_voltage(&voltage);
+
+ // 获取充电状态
+ bool isCharging = get_charge_stat();
+
+ // 拼接字符串,并简化为保留两位小数
+ std::ostringstream oss;
+ oss << std::fixed
+ << std::setprecision(2) // 设置为固定小数位,保留两位小数
+ << "Bat Temp: " << bat_temp << " °C\n"
+ << "PCB Temp: " << pcb_temp << " °C\n"
+ << "Voltage: " << voltage << " V\n"
+ << "Percent: " << static_cast<int>(percent)
+ << " %\n"
+ << "Charge: " << (isCharging ? "Yes" : "No");
+
+ return oss.str();
}
- //获取死机列表
- static const char *SHUTDOWN_PATH = "/user/tar";
- std::string DebugOutputViewEventListener::get_shutdown_info() {
- std::ostringstream oss;
+ // 获取死机列表
+ static const char *SHUTDOWN_PATH = "/user/tar";
+ std::string DebugOutputViewEventListener::get_shutdown_info()
+ {
+ std::ostringstream oss;
- // 打开目录
- DIR *dir = opendir(SHUTDOWN_PATH);
- if (dir == nullptr) {
- return "死机目录不存在: " + std::string(strerror(errno));
- }
+ // 打开目录
+ DIR *dir = opendir(SHUTDOWN_PATH);
+ if (dir == nullptr)
+ {
+ return "死机目录不存在: " + std::string(strerror(errno));
+ }
- struct dirent *entry;
- while ((entry = readdir(dir)) != nullptr) {
- // 跳过. 和 ..
- if (entry->d_name[0] != '.') {
- oss << entry->d_name << "\n"; // 逐行添加
- }
- }
+ struct dirent *entry;
+ while ((entry = readdir(dir)) != nullptr)
+ {
+ // 跳过. 和 ..
+ if (entry->d_name[0] != '.')
+ {
+ oss << entry->d_name << "\n"; // 逐行添加
+ }
+ }
- closedir(dir); // 关闭目录
+ closedir(dir); // 关闭目录
- if (oss.str().empty()) {
- return "无死机文件";
- }
+ if (oss.str().empty())
+ {
+ return "无死机文件";
+ }
- return oss.str(); // 返回以换行符分隔的文件名字符串
+ return oss.str(); // 返回以换行符分隔的文件名字符串
}
- //获取睡眠时间戳
+ // 获取睡眠时间戳
std::string DebugOutputViewEventListener::get_sleep_time(void)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DebugOutputViewEventListener::get_sleep_time");
do_custom_fileoperate_service_check_msg(
- CUSTOM_FILEOPERATE_MSG_TYPE_SLEEPDATA_READ, nullptr, 0);
+ CUSTOM_FILEOPERATE_MSG_TYPE_SLEEPDATA_READ, nullptr, 0);
LOS_Msleep(100);
std::string result = "asleep_time:" + get_sleep_asleep_time_str() + " ";
result += "wake_time:" + get_sleep_wake_time_str() + " ";
return result;
}
- //获取系统free内存
+ // 获取系统free内存
std::string DebugOutputViewEventListener::get_free_memory()
{
auto logModel = SystemLogModel::GetInstance();
return result;
}
+ 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;
- 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();
+ // 调用时间格式化函数
+ if (uapi_get_TIME_STR(log, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC)
+ {
+ timestr = "--"; // 如果获取时间失败,使用默认值
+ }
+ else
+ {
+ timestr = labelTime; // 成功获取时间
+ }
+
+ result << "[" << timestr << "] "; // 使用格式化后的时间拼接日志记录
+ }
+
+ 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)
{
// if (BluetoothModel::GetInstance()->GetAdvStartState() == false) // 如果广播是关的就去开启广播
// BleAdvStart();
-
+
svr_ble_adv_start();
return true;
}
case 9:
str = get_nextday_log();
break;
+ case 10:
+ str = get_popup_windows_log();
+ break;
default:
str = "--";
break;
- }
+ }
- GraphicService::GetInstance()->PostGraphicEvent(std::bind(
- &DebugOutputViewEventListener::UpdateView, &DebugOutputViewEventListener::GetInstance(),str));
+ GraphicService::GetInstance()->PostGraphicEvent(std::bind(
+ &DebugOutputViewEventListener::UpdateView, &DebugOutputViewEventListener::GetInstance(), str));
return true;
}
-
- //获取视图
- void DebugOutputViewEventListener::UpdateView(std::string str)
+ // 获取视图
+ void DebugOutputViewEventListener::UpdateView(std::string str)
{
- if(debugOutputLabel != nullptr)
+ if (debugOutputLabel != nullptr)
{
debugOutputLabel->SetText(str.c_str());
}