系统:增加系统nextday日志的记录
authorCaisking <3449750381@qq.com>
Thu, 17 Oct 2024 09:53:28 +0000 (17:53 +0800)
committerCaisking <3449750381@qq.com>
Thu, 17 Oct 2024 09:53:28 +0000 (17:53 +0800)
code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp
code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h
code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModelC.h
code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp
code/sdk/application/wearable/service/msg_center/include/notify/debug_output_notification/debug_output_notification.h
code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp
code/sdk/application/wearable/service/msg_center/src/notify/debug_output_notification/debug_output_notification.cpp
code/sdk/drivers/peripheral/utils/custom_cmd_service.c
code/sdk/drivers/peripheral/utils/custom_utils.h

index f6ac1c7..4a88ed3 100644 (file)
@@ -579,6 +579,8 @@ namespace OHOS
         SystemLogModel::GetInstance()->loadLog();
         // 再存储日志
         SystemLogModel::GetInstance()->saveLog(systemlog);
+        // 读取nextday日志
+        SystemLogModel::GetInstance()->load_nextday_log();
     }
 
     void NativeLauncher::InitAllNativeSlices(void)
index 73fd26b..b063fab 100644 (file)
@@ -1,51 +1,56 @@
-#ifndef SystemLog_MODEL_H
-#define SystemLog_MODEL_H
-
-#include <cstdint>
-#include <deque>
-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<SystemLogData> &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<SystemLogData> logData; // 用于存储日志数据
-};
-} // namespace OHOS
-
-#endif // SystemLog_MODEL_H
\ No newline at end of file
+#ifndef SYSTEM_LOG_MODEL_H  
+#define SYSTEM_LOG_MODEL_H  
+
+#include <cstddef>
+#include <cstdint>  
+#include <deque>  
+#include <string>  
+#include <memory>  
+
+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<SystemLogData> &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<uint32_t> &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<SystemLogData> logData;          // 存储日志数据  
+    std::deque<uint32_t> nextday_log;           // 存储nextday时间戳  
+};  
+} // namespace OHOS  
+
+#endif // SYSTEM_LOG_MODEL_H
\ No newline at end of file
index 48dd636..48a9e15 100644 (file)
@@ -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
index a78b27c..6602fcd 100644 (file)
 #include <ctime>
 #include <deque>
 #include <fstream>
+#include <iomanip>
 #include <iostream>
 #include <sstream>
+#include <stdexcept>
 #include <string>
 #include <sys/statfs.h>
 #include <sys/time.h>
@@ -22,6 +24,7 @@
 #include <vector>
 
 #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<uint32_t> &SystemLogModel::get_nextday_log() const {
+  return nextday_log; // 返回日志记录的常量引用
+}
+//获取日志大小
+size_t SystemLogModel::get_nextday_log_size() const {
+  return nextday_log.size();
+}
+
+} // namespace OHOS
index 7995ef5..821a4d3 100644 (file)
@@ -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();
index cdfac10..11c08bf 100644 (file)
@@ -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
 }
index 12a9d49..134d2c3 100644 (file)
@@ -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;
index c312ca5..6c76163 100644 (file)
@@ -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;
index 67a51a2..0b517d7 100644 (file)
@@ -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,