系统:增加 uartAT指令 接受开关
authorCaisking <3449750381@qq.com>
Mon, 4 Nov 2024 11:59:09 +0000 (19:59 +0800)
committerCaisking <3449750381@qq.com>
Mon, 4 Nov 2024 11:59:09 +0000 (19:59 +0800)
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/notify/debug_output_notification/debug_output_notification.cpp
code/sdk/drivers/peripheral/config/include/ConfigModel.h
code/sdk/drivers/peripheral/utils/custom_utils.c

index aa32dcb..11ce5b1 100644 (file)
@@ -107,8 +107,11 @@ public:
     bool load_popup_windows_log();                                           // 加载popup_windows日志
     const std::deque<popup_windows_log_data> &get_popup_windows_log() const; // 获取popup_windows日志记录(常量引用)
     size_t get_popup_windows_log_size() const;                               // 获取日志大小
-    void clear_popup_windows_log();                                          // 清空popup_windows日志记录
-    
+    void clear_popup_windows_log(); // 清空popup_windows日志记录
+    /* ---------------------------------- 串口控制 ---------------------------------- */
+    void init_uart();
+    void set_uart_status(bool status);
+    bool get_uart_status();
 
 private:  
     SystemLogModel() = default; // 私有构造函数
@@ -119,8 +122,11 @@ private:
     SystemLogModel &operator=(const SystemLogModel &) = delete;  
 
     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<nextday_log_data> nextday_log;           // 存储nextday时间戳
+    std::deque<popup_windows_log_data>
+        popup_windows_log; // 存储popup_windows时间戳
+
+    bool uart_status{false};
 };  
 } // namespace OHOS  
 
index 2eb82eb..cbcbc4b 100644 (file)
@@ -16,7 +16,7 @@ void start_report_nextday_log_start(void);
 void start_report_nextday_log_end(void);
 void nextday_clear_popup_windows_log(void);
 void save_popup_windows_log_c(int type);
-
+void system_init_uart(void);
 
 #ifdef __cplusplus
 #if __cplusplus
index 68a3a2c..31db528 100644 (file)
@@ -26,6 +26,7 @@
 #include <sys/time.h>
 #include <thread>
 #include <vector>
+#include "ConfigModel.h"
 
 #define SYSTEM_LOG_PATH "/user/system/"
 #define SYSTEM_LOG_FILE_PATH "/user/system/system_log.txt"
@@ -80,6 +81,11 @@ void save_popup_windows_log_c(int type)
 {
   OHOS::SystemLogModel::GetInstance()->save_popup_windows_log_type(type);
 }
+//进行开机配置uart
+void system_init_uart(void)
+{
+  OHOS::SystemLogModel::GetInstance()->init_uart();
+}
 }
 
 namespace OHOS {
@@ -414,4 +420,20 @@ void SystemLogModel::clear_popup_windows_log() {
   outFile << "";
   outFile.close();
 }
+/*串口控制*/
+void SystemLogModel::init_uart() {
+  //读取configmodle
+  uart_status = ConfigModel::GetInstance()->get_configData_bool(
+      ConfigModel::CONFIGMODEL_ITEM_URAT_AT_CONTROL_STATUS);
+  uapi_custom_set_uart_rx_enable_flag(uart_status);
+}
+//设置串口状态
+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);
+}
+//获取串口状态
+bool SystemLogModel::get_uart_status() { return uart_status;}
 } // namespace OHOS
index 24b95ea..3be8b49 100644 (file)
@@ -45,6 +45,7 @@ namespace OHOS
         std::string get_heart_rate(void);
         std::string get_popup_windows_log(void);
         std::string get_system_screen_time(void);
+        std::string get_uart_at_status(void);
 
       private:
         DebugOutputViewEventListener();
index 3914017..0f73037 100644 (file)
@@ -14,6 +14,7 @@
 #include "components/ui_label_button.h"
 #include "components/ui_label_ext.h"
 #include "components/ui_scroll_view.h"
+#include "components/ui_toggle_button.h"
 #include "custom_runtime.h"
 #include "custom_utils.h"
 #include "graphic_service.h"
@@ -115,6 +116,7 @@ namespace OHOS
     DebugOutputAdapter *debugOutputAdapter{nullptr};
     UILabel *debugOutputLabel{nullptr};
     UILabelButton *debugOutputLabelButton{nullptr};
+    UIToggleButton* toggleButton = nullptr;
     UILabelButton *debugOutputbleServiceLabelButton{nullptr};
     static constexpr const char *DEBUGOUTPUTLABELBUTTON = "debugOutputLabelButton";
     static constexpr const char *DEBUGOUTPUTBLESERVICELABELBUTTON = "debugOutputbleServiceLabelButton";
@@ -145,6 +147,8 @@ namespace OHOS
         debugOutputItemInfo[index++] = {index, "popup_windows_log"};
         //当前系统亮屏时长
         debugOutputItemInfo[index++] = {index, "current_screen_time"};
+        //串口状态服务
+        debugOutputItemInfo[index++] = {index, "uart_service_status"};
         usedLen = index;
         /* -------------------------------- Add data -------------------------------- */
         for (uint8_t i = 0; i < usedLen; i++)
@@ -554,6 +558,13 @@ namespace OHOS
         str<<"["<<std::to_string(uapi_dev_runtime_get_screen_always_on_status())<<"]\n";
         return str.str();
     }
+    //增加串口日志服务
+    std::string DebugOutputViewEventListener::get_uart_at_status() {
+        // 获取系统日志实例
+        auto logModel = SystemLogModel::GetInstance();
+        bool status = logModel->get_uart_status();
+        return std::string("uart_at_status:") + std::to_string(status);
+    }
     bool DebugOutputViewEventListener::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
     {
         std::string viewId = view.GetViewId();
@@ -571,6 +582,25 @@ namespace OHOS
         {
             viewIndex = GetCurViewIndex();
         }
+        //点击开启按键
+        else if (viewId == "uart_at_set") {
+          if (toggleButton) {
+            if (toggleButton->GetState() == false) {
+                // toggleButton->SetState(false);
+                SystemLogModel::GetInstance()->set_uart_status(false);
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"uart_at_set false");
+            }
+            else {
+                // toggleButton->SetState(true);
+                SystemLogModel::GetInstance()->set_uart_status(true);
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"uart_at_set true");
+            }
+          } else {
+             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"组件不存在");
+          }
+        //   viewIndex = GetCurViewIndex();
+          return true; //进行UI刷新
+        }
         else // 如果点击的是列表中的itemview
         {
             DebugOutputItemView *debugOutputItemView = static_cast<DebugOutputItemView *>(&view);
@@ -624,9 +654,17 @@ namespace OHOS
         case 11:
             str = get_popup_windows_log();
             break;
-         case 12:
+        case 12:
             str = get_system_screen_time();
             break;
+        case 13:
+            str = get_uart_at_status();
+            if (toggleButton) {
+              if (toggleButton->IsVisible() == false) {
+                toggleButton->SetVisible(true);
+                }
+              }
+            break;
         default:
             str = "--";
             break;
@@ -826,6 +864,28 @@ namespace OHOS
         }
         debugOutputLabelButton->SetOnClickListener(clickListener);
         DebugScrollView[1]->Add(debugOutputLabelButton);
+        /* -------------------------------------------------------------------------- */
+        if (toggleButton == nullptr) {
+            toggleButton = new UIToggleButton();
+        }
+        toggleButton->SetPosition(147, debugOutputLabel->GetY() + debugOutputLabel->GetHeight() + 20+120);         // widget's left position and top position
+        toggleButton->Resize(171, 121);          // widget's width and height
+        toggleButton->SetViewId("uart_at_set");// Set style
+        toggleButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
+
+        //获取状态
+        auto logModel = SystemLogModel::GetInstance();
+        bool status = logModel->get_uart_status();
+        toggleButton->SetState(status);
+        toggleButton->SetVisible(false); //设置不可见
+        UIView::OnClickListener *clickListener_ = static_cast<UIView::OnClickListener *>(&DebugOutputViewEventListener::GetInstance());
+        if (clickListener_ == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clickListener is new fail!!");
+            return nullptr;
+        }
+        toggleButton->SetOnClickListener(clickListener_);
+        DebugScrollView[1]->Add(toggleButton);
 
         return DebugScrollView[1];
     }
index f9183b9..f752a51 100644 (file)
@@ -151,6 +151,8 @@ namespace OHOS
             CONFIGMODEL_ITEM_SPORTS_GOAL_STANDUP_TIMES_TIME,    //运动目标站立次数
             CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION_TIME,    //运动燃脂达成时间
             CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE_TIME,    //运动目标距离
+            
+            CONFIGMODEL_ITEM_URAT_AT_CONTROL_STATUS,//串口控制状态
             CONFIGMODEL_ITEM_MAX,
 
            
@@ -414,6 +416,7 @@ namespace OHOS
             {ConfigDataType::DATATYPE_INT,     "goal_standup_times_time",         "1"    },// CONFIGMODEL_ITEM_SPORTS_GOAL_STANDUP_TIMES,    //运动目标站立次数 10
             {ConfigDataType::DATATYPE_INT,     "goal_duration_time",             "1"    },// CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION,    //运动目标时长   30(分钟)
             {ConfigDataType::DATATYPE_INT,     "goal_distance_time",             "1"   },// CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE,    //运动目标距离   8.0(km)
+            {ConfigDataType::DATATYPE_INT,     "urat_at_status",             "false"   },//CONFIGMODEL_ITEM_URAT_AT_CONTROL_STATUS // 串口AT 默认 关闭
 
         };
         ConfigModel();                                        // 私有构造函数,确保无法在外部实例化
index 2e6039e..833419c 100644 (file)
@@ -480,6 +480,8 @@ void startup_post_init_task(void)
 
     ota_updata_init();
 
+    system_init_uart();//配置uartat
+
     if ( cm_poweron_cat1_on_bootup_flag() )
     {
         PRINT("PowerOn Cat1 !\r\n");
@@ -1336,7 +1338,7 @@ void uapi_set4GCapability(bool isopen)
             uapi_dev_runtime_set_cat1_powerstat(1);
         }
         /*4G 开电有时有干扰进日志串口,因此关闭日志串口*/
-        uapi_custom_set_uart_rx_enable_flag(false);
+        // uapi_custom_set_uart_rx_enable_flag(false);
 
         #ifdef SUPPORT_TCPIP
             tcp_thread_id = tcp_get_thread_id();
@@ -1355,7 +1357,7 @@ void uapi_set4GCapability(bool isopen)
             uapi_dev_runtime_set_cat1_powerstat(0);
         }
         /*4G 开电有时有干扰进日志串口,因此关闭4G才开启日志串口*/
-        uapi_custom_set_uart_rx_enable_flag(true);
+        // uapi_custom_set_uart_rx_enable_flag(true);
             
         #ifdef SUPPORT_TCPIP
             tcp_thread_id = tcp_get_thread_id();