From 2bb09b4bf845048763c2b6fc7d672bee3dad3f80 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Thu, 17 Oct 2024 17:53:28 +0800 Subject: [PATCH] =?utf8?q?=E7=B3=BB=E7=BB=9F=EF=BC=9A=E5=A2=9E=E5=8A=A0?= =?utf8?q?=E7=B3=BB=E7=BB=9Fnextday=E6=97=A5=E5=BF=97=E7=9A=84=E8=AE=B0?= =?utf8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativelauncher/src/NativeLauncher.cpp | 2 + .../nativeui/system/include/SystemLogModel.h | 107 +++++++++--------- .../nativeui/system/include/SystemLogModelC.h | 2 + .../nativeui/system/src/SystemLogModel.cpp | 62 +++++++++- .../debug_output_notification.h | 1 + .../msg_center/src/msg_center_customer.cpp | 9 +- .../debug_output_notification.cpp | 32 ++++++ .../peripheral/utils/custom_cmd_service.c | 5 + .../drivers/peripheral/utils/custom_utils.h | 2 + 9 files changed, 168 insertions(+), 54 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index f6ac1c799..4a88ed348 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -579,6 +579,8 @@ namespace OHOS SystemLogModel::GetInstance()->loadLog(); // 再存储日志 SystemLogModel::GetInstance()->saveLog(systemlog); + // 读取nextday日志 + SystemLogModel::GetInstance()->load_nextday_log(); } void NativeLauncher::InitAllNativeSlices(void) diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h index 73fd26bc8..b063fabab 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h @@ -1,51 +1,56 @@ -#ifndef SystemLog_MODEL_H -#define SystemLog_MODEL_H - -#include -#include -namespace OHOS { -enum class SystemLogType { - POWER_ON = 0, // 开机 - POWER_OFF, // 关机 - RESTART, // 重启 - FACTORY_RESET, // 恢复出厂设置 - SOFTWARE_UPDATE, // 更新 -}; - -struct SystemLogData { - SystemLogType type; // 类型 - uint32_t timestamp; // 时间戳 -}; - -class SystemLogModel { -public: - static SystemLogModel *GetInstance(void); - - // 最多存储50条(超过了删除老的) - bool saveLog(SystemLogData data); - - // 加载数据 - bool loadLog(); - - // 获取日志记录 - const std::deque &getLogData() const; // 返回 deque 的常量引用 - - size_t getLogSize() const; // 返回日志数量 - - uint32_t GetCurrentTime(); - - std::string get_system_mem_info(); - -private: - SystemLogModel() = default; - ~SystemLogModel() {} - - // 不允许拷贝和赋值 - SystemLogModel(const SystemLogModel &) = delete; - SystemLogModel &operator=(const SystemLogModel &) = delete; - - std::deque logData; // 用于存储日志数据 -}; -} // namespace OHOS - -#endif // SystemLog_MODEL_H \ No newline at end of file +#ifndef SYSTEM_LOG_MODEL_H +#define SYSTEM_LOG_MODEL_H + +#include +#include +#include +#include +#include + +namespace OHOS { + +enum class SystemLogType { + POWER_ON = 0, // 开机 + POWER_OFF, // 关机 + RESTART, // 重启 + FACTORY_RESET, // 恢复出厂设置 + SOFTWARE_UPDATE, // 更新 +}; + +struct SystemLogData { + SystemLogType type; // 日志类型 + uint32_t timestamp; // 时间戳 +}; + +class SystemLogModel { +public: + // 获取单例实例 + static SystemLogModel *GetInstance(void); + + /* ---------------------------------- 系统日志 ---------------------------------- */ + bool saveLog(SystemLogData data); // 保存日志 + bool loadLog(); // 加载日志 + const std::deque &getLogData() const; // 获取日志记录(常量引用) + size_t getLogSize() const; // 获取日志数量 + uint32_t GetCurrentTime(); // 获取当前时间 + /* ---------------------------------- 系统内存 ---------------------------------- */ + std::string get_system_mem_info(); // 获取系统内存信息 + /* ------------------------------- nextday日志记录 ------------------------------ */ + bool save_nextday_log(uint32_t timestamp); // 保存nextday日志 + bool load_nextday_log(); // 加载nextday日志 + const std::deque &get_nextday_log() const; // 获取nextday日志记录(常量引用) + size_t get_nextday_log_size() const;//获取日志大小 +private: + SystemLogModel() = default; // 私有构造函数 + ~SystemLogModel() = default; // 默认析构函数 + + // 禁止拷贝和赋值 + SystemLogModel(const SystemLogModel &) = delete; + SystemLogModel &operator=(const SystemLogModel &) = delete; + + std::deque logData; // 存储日志数据 + std::deque nextday_log; // 存储nextday时间戳 +}; +} // namespace OHOS + +#endif // SYSTEM_LOG_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModelC.h b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModelC.h index 48dd636b5..48a9e15ca 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModelC.h +++ b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModelC.h @@ -12,6 +12,8 @@ void start_report_log(void); void stop_report_log(void); void resume_report_log(void); void update_version_report_log(void); +void start_report_nextday_log(void); + #ifdef __cplusplus #if __cplusplus diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp index a78b27cb4..6602fcd8e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp @@ -13,8 +13,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -22,6 +24,7 @@ #include #define SYSTEM_LOG_FILE_PATH "/system/system_log.txt" +#define SYSTEM_LOG_FILE_PATH_NEXTDAY "/system/system_log_nextday.txt" extern "C" { // 通用日志记录功能 @@ -47,6 +50,12 @@ void resume_report_log(void) { report_log(OHOS::SystemLogType::FACTORY_RESET); } void update_version_report_log(void) { report_log(OHOS::SystemLogType::SOFTWARE_UPDATE); } + +//保存nextday日志 +void start_report_nextday_log(void) { + uint32_t timestamp = OHOS::SystemLogModel::GetInstance()->GetCurrentTime(); + OHOS::SystemLogModel::GetInstance()->save_nextday_log(timestamp); +} } namespace OHOS { @@ -166,4 +175,55 @@ std::string SystemLogModel::get_system_mem_info() { return result.str().empty() ? "No volumes found or accessible." : result.str(); } -} // namespace OHOS \ No newline at end of file + +// nextday相关 +bool SystemLogModel::save_nextday_log(uint32_t timestamp) { + // 检查容量,最多存储7条日志 + if (nextday_log.size() >= 7) { + nextday_log.pop_front(); // 超出限制,删除最旧的日志 + } + + // 保存新日志 + nextday_log.push_back(timestamp); + + // 将日志写入文件 + std::ofstream outFile(SYSTEM_LOG_FILE_PATH_NEXTDAY, std::ios::trunc); + if (!outFile) { + return false; // 文件打开失败 + } + + outFile << timestamp << std::endl; // 写入时间戳 + outFile.close(); + + return true; +} + +bool SystemLogModel::load_nextday_log() { + nextday_log.clear(); // 清空当前的日志 + std::ifstream inFile(SYSTEM_LOG_FILE_PATH_NEXTDAY); + if (!inFile) { + return false; // 无法打开文件 + } + + std::string line; + while (std::getline(inFile, line)) { + std::istringstream ss(line); + uint32_t timestamp; + if (ss >> timestamp) { + nextday_log.push_back(timestamp); // 读取时间戳并存储 + } + } + + inFile.close(); + return true; +} + +const std::deque &SystemLogModel::get_nextday_log() const { + return nextday_log; // 返回日志记录的常量引用 +} +//获取日志大小 +size_t SystemLogModel::get_nextday_log_size() const { + return nextday_log.size(); +} + +} // namespace OHOS diff --git 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 index 7995ef5cb..821a4d392 100644 --- 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 @@ -41,6 +41,7 @@ namespace OHOS std::string get_shutdown_info(void); std::string get_sleep_time(void); std::string get_free_memory(void); + std::string get_nextday_log(void); private: DebugOutputViewEventListener(); diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp index cdfac10fd..11c08bf7b 100644 --- a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp @@ -72,6 +72,7 @@ #include "respiratorytraining/include/RespiratoryTrainingModel.h" #include "main/include/PullUpDownView.h" #include "player/include/PlayersModelC.h" +#include "system/include/SystemLogModelC.h" #include "ui_service.h" #define DIALDATASET 1 @@ -585,7 +586,6 @@ void MsgCenterNotifyNextDayProc(const Topic topic, Request *req) /* ---------------------------------- 健康数据相关 ---------------------------------- */ // 清空当日的心率血氧数据 HealthService::GetInstance()->CleanHealthData(); - RespiratoryTrainingModel::GetInstance().ClearTotalRespiratoryTrainingTime(); // 通知UI更新 GraphicService::GetInstance()->PostGraphicEvent( std::bind(&OHOS::HeartModel::CleanAllData, OHOS::HeartModel::GetInstance())); @@ -597,8 +597,13 @@ void MsgCenterNotifyNextDayProc(const Topic topic, Request *req) { set_Is_shouw_falg(1,i); } - do_cywee_service_check_msg(CYWEE_SERVICE_CMD_RESET_DAILY_DATA, NULL); + /* ---------------------------------- 呼吸训练相关 ---------------------------------- */ + RespiratoryTrainingModel::GetInstance().ClearTotalRespiratoryTrainingTime(); + + // 存储nextday执行日志 + start_report_nextday_log(); + printf("******nextday is end******\r\n"); #endif } diff --git 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 index 12a9d4943..134d2c358 100644 --- 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 @@ -90,6 +90,8 @@ namespace OHOS debugOutputItemInfo[index++] = {7, "sleep_time"}; //系统空闲内存 debugOutputItemInfo[index++] = {8, "system_free_memory"}; + // nextday执行日志 + debugOutputItemInfo[index++] = {9, "nextday_log"}; usedLen = index; /* -------------------------------- Add data -------------------------------- */ for (uint8_t i = 0; i < usedLen; i++) @@ -363,6 +365,33 @@ result += "advdata:" + (getCurrentWatchadvdata()) + " "; 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; + + // 调用时间格式化函数 + if (uapi_get_TIME_STR(log, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC) { + timestr = "--"; // 如果获取时间失败,使用默认值 + } else { + timestr = labelTime; // 成功获取时间 + } + + result << "[" << timestr << "] "; // 使用格式化后的时间拼接日志记录 + } + + return result.str(); + } + bool DebugOutputViewEventListener::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) { std::string viewId = view.GetViewId(); @@ -424,6 +453,9 @@ result += "advdata:" + (getCurrentWatchadvdata()) + " "; case 8: str = get_free_memory(); break; + case 9: + str = get_nextday_log(); + break; default: str = "--"; break; diff --git a/code/sdk/drivers/peripheral/utils/custom_cmd_service.c b/code/sdk/drivers/peripheral/utils/custom_cmd_service.c index c312ca557..6c761634d 100644 --- a/code/sdk/drivers/peripheral/utils/custom_cmd_service.c +++ b/code/sdk/drivers/peripheral/utils/custom_cmd_service.c @@ -41,6 +41,8 @@ #include "safemodemanager/include/SafeModeManagerModelC.h" +#include "alarmclocktimerconfig/include/AlarmClockTimerConfig.h" + typedef struct { uint8_t cmd; @@ -267,6 +269,9 @@ static void custom_cmd_service_check_task(void const *arg) case CUSTOM_CMD_MSG_DOWNLOAD_RES: repair_file_start(); break; + case CUSTOM_CMD_MSG_TIMECALL_BACK: + custom_timer_callback(); + break; default: PRINT("Unknown CUSTOM_CMD_MSG cmd 0x%02X \r\n", mail.cmd); break; diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index 67a51a20d..0b517d75b 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -219,6 +219,8 @@ uint32_t uapi_calendar_store_date(void); #define CUSTOM_CMD_MSG_DOWNLOAD_RES 0x0E #define CUSTOM_CMD_MSG_TYPE_TOUCH_RESUME 0x0F + +#define CUSTOM_CMD_MSG_TIMECALL_BACK 0x10 typedef enum { BR_HFP_CONNECT=1, BR_HFP_DISCONNECT, -- 2.17.1