增加gps状态日志记录
authorCaisking <Casiking@zhihuishixun.com>
Tue, 1 Jul 2025 09:34:27 +0000 (17:34 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Tue, 1 Jul 2025 09:34:27 +0000 (17:34 +0800)
code/sdk/application/wearable/fd230app/nativeui/system/include/SystemLogModel.h
code/sdk/application/wearable/fd230app/nativeui/system/src/SystemLogModel.cpp

index 0368b7f..222b852 100644 (file)
@@ -77,6 +77,18 @@ struct popup_windows_log_data {
     popup_windows_type type; // 弹窗类型
     uint32_t timestamp;      // 时间戳
 };
+
+//GPS状态变化日志记录
+enum class gps_status_type {
+    //定位成功
+    GPS_SUCCESS = 0,
+    //定位失败
+    GPS_FAILED,
+};
+struct gps_status_log_data {
+    gps_status_type type; // GPS状态类型
+    uint32_t timestamp;   // 时间戳
+};
 class SystemLogModel {  
 public:  
     // 获取单例实例  
@@ -112,6 +124,11 @@ public:
     void init_uart();
     void set_uart_status(bool status);
     bool get_uart_status();
+    /* ---------------------------------- GPS状态日志记录 ------------------------------ */
+    bool save_gps_status_log_type(bool status);
+    bool save_gps_status_log(gps_status_log_data data); // 保存GPS状态变化日志
+    const std::deque<gps_status_log_data> &get_gps_status_log() const; // 获取GPS状态变化日志(常量引用)
+    size_t get_gps_status_log_size() const; // 获取GPS状态变化日志大小
 
 private:  
     SystemLogModel() = default; // 私有构造函数
@@ -124,6 +141,7 @@ private:
     std::deque<SystemLogData> logData;          // 存储日志数据  
     std::deque<nextday_log_data> nextday_log;           // 存储nextday时间戳
     std::deque<popup_windows_log_data> popup_windows_log; // 存储popup_windows时间戳
+    std::deque<gps_status_log_data> gps_status_log; // 存储GPS状态变化日志时间戳
 
     bool uart_status{false};
 };  
index 5718159..36fc33a 100644 (file)
@@ -1,5 +1,7 @@
 #include "system/include/SystemLogModel.h"
+#include "ConfigModel.h"
 #include "cmsis_os.h"
+#include "custom_save_runtime.h"
 #include "custom_utils.h"
 #include "graphic_service.h"
 #include "iostream"
@@ -26,8 +28,6 @@
 #include <sys/time.h>
 #include <thread>
 #include <vector>
-#include "ConfigModel.h"
-#include "custom_save_runtime.h"
 #define SYSTEM_LOG_PATH "/user/system/"
 #define SYSTEM_LOG_FILE_PATH "/user/system/system_log.txt"
 #define SYSTEM_LOG_FILE_PATH_NEXTDAY "/user/system/system_log_nextday.txt"
@@ -41,7 +41,6 @@ void report_log(OHOS::SystemLogType type) {
   systemlog.type = type;
   uapi_save_runtime_log_Time();
 
-
   // 存储日志
   OHOS::SystemLogModel::GetInstance()->saveLog(systemlog);
 }
@@ -79,13 +78,11 @@ void start_report_nextday_log_end(void) {
 void nextday_clear_popup_windows_log(void) {
   // OHOS::SystemLogModel::GetInstance()->clear_popup_windows_log();
 }
-void save_popup_windows_log_c(int type)
-{
+void save_popup_windows_log_c(int type) {
   OHOS::SystemLogModel::GetInstance()->save_popup_windows_log_type(type);
 }
 //进行开机配置uart
-void system_init_uart(void)
-{
+void system_init_uart(void) {
   OHOS::SystemLogModel::GetInstance()->init_uart();
 }
 }
@@ -109,25 +106,24 @@ uint32_t SystemLogModel::GetCurrentTime() {
 bool SystemLogModel::saveLog(SystemLogData data) {
 
   //记录开机,关机,重启,ota升级,恢复出厂事件
-  switch (data.type)
-  {
+  switch (data.type) {
   case SystemLogType::POWER_ON:
-      uapi_save_runtime_log(RUNTIME_LOG_POWER_ON);//TOOD*
-      break;
+    uapi_save_runtime_log(RUNTIME_LOG_POWER_ON); // TOOD*
+    break;
   case SystemLogType::POWER_OFF:
-      uapi_save_runtime_log(RUNTIME_LOG_POWER_OFF);//TOOD*
-      break;
+    uapi_save_runtime_log(RUNTIME_LOG_POWER_OFF); // TOOD*
+    break;
   case SystemLogType::RESTART:
-      uapi_save_runtime_log(RUNTIME_LOG_REBOOT);//TOOD*
-      break;
+    uapi_save_runtime_log(RUNTIME_LOG_REBOOT); // TOOD*
+    break;
   case SystemLogType::FACTORY_RESET:
-      uapi_save_runtime_log(RUNTIME_LOG_FACTORY_RESET);//TOOD*
-      break;
+    uapi_save_runtime_log(RUNTIME_LOG_FACTORY_RESET); // TOOD*
+    break;
   case SystemLogType::SOFTWARE_UPDATE:
-      uapi_save_runtime_log(RUNTIME_LOG_OTA);//TOOD*
-      break;
+    uapi_save_runtime_log(RUNTIME_LOG_OTA); // TOOD*
+    break;
   default:
-      break;
+    break;
   }
 
   // 将新日志添加到日志数据
@@ -293,8 +289,38 @@ bool SystemLogModel::canSyncFile(std::string path, uint32_t path_max_size,
 
   return (usedSpace + download_size) <= path_max_size;
 }
-// nextday相关
+/////////////////////////////////////////////////////////////////////
+// gps状态日志记录
+bool SystemLogModel::save_gps_status_log(gps_status_log_data data) {
+  // 保存新日志
+  gps_status_log.push_back(data);
+  //不需要存储到文件,只在内存中记录
+  return true;
+}
+size_t SystemLogModel::get_gps_status_log_size() const {
+  return gps_status_log.size();
+}
+
+const std::deque<gps_status_log_data> &
+SystemLogModel::get_gps_status_log() const {
+  return gps_status_log;
+}
+bool SystemLogModel::save_gps_status_log_type(bool status) {
+  gps_status_log_data data;
+  uint32_t timestamp = SystemLogModel::GetInstance()->GetCurrentTime();
+  if (status) {
+    data.type = gps_status_type::GPS_SUCCESS;
+  } else {
+    data.type = gps_status_type::GPS_FAILED;
+  }
+  data.timestamp = timestamp;
+  save_gps_status_log(data);
+  
+  return true;
+}
+///////////////////////////////////////////////////////////////
 
+// nextday相关
 bool SystemLogModel::save_nextday_log(nextday_log_data data) {
   // 检查容量,最多存储7条日志
   if (nextday_log.size() >= 7) {
@@ -384,25 +410,23 @@ bool SystemLogModel::save_popup_windows_log(popup_windows_log_data data) {
   return true;
 }
 
-void SystemLogModel::save_popup_windows_log_type(int type)
-{
-    popup_windows_log_data data;
-    data.timestamp = GetCurrentTime();
-    switch(type)
-    {
-      case 0:
-        data.type = popup_windows_type::MOTION_RECOGNITION;
-        break;
-      case 1:
-        data.type = popup_windows_type::DRINK_WATER_REMINDER;
-        break;
-      case 2:
-        data.type = popup_windows_type::SEDENTARY_REMINDER;
-        break;
-      default:
-        break;
-    }
-    save_popup_windows_log(data);
+void SystemLogModel::save_popup_windows_log_type(int type) {
+  popup_windows_log_data data;
+  data.timestamp = GetCurrentTime();
+  switch (type) {
+  case 0:
+    data.type = popup_windows_type::MOTION_RECOGNITION;
+    break;
+  case 1:
+    data.type = popup_windows_type::DRINK_WATER_REMINDER;
+    break;
+  case 2:
+    data.type = popup_windows_type::SEDENTARY_REMINDER;
+    break;
+  default:
+    break;
+  }
+  save_popup_windows_log(data);
 }
 bool SystemLogModel::load_popup_windows_log() {
   std::ifstream inFile(SYSTEM_LOG_FILE_PATH_POPUP_WINDOWS);
@@ -418,8 +442,7 @@ bool SystemLogModel::load_popup_windows_log() {
     popup_windows_log_data data;
     int typeInt;
     if (ss >> typeInt >> data.timestamp) {
-      switch(typeInt)
-      {
+      switch (typeInt) {
       case 0:
         data.type = popup_windows_type::MOTION_RECOGNITION;
         break;
@@ -446,7 +469,8 @@ SystemLogModel::get_popup_windows_log() const {
 }
 // 获取日志大小
 size_t SystemLogModel::get_popup_windows_log_size() const {
-  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"log size:%d",popup_windows_log.size());
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "log size:%d",
+                popup_windows_log.size());
   return popup_windows_log.size();
 }
 
@@ -476,8 +500,8 @@ void SystemLogModel::set_uart_status(bool status) {
   uart_status = status;
   uapi_custom_set_uart_rx_enable_flag(uart_status);
   ConfigModel::GetInstance()->set_condigData_Bool(
-      ConfigModel::CONFIGMODEL_ITEM_URAT_AT_CONTROL_STATUS,uart_status);
+      ConfigModel::CONFIGMODEL_ITEM_URAT_AT_CONTROL_STATUS, uart_status);
 }
 //获取串口状态
-bool SystemLogModel::get_uart_status() { return uart_status;}
+bool SystemLogModel::get_uart_status() { return uart_status; }
 } // namespace OHOS