Sfoglia il codice sorgente

feat: 配置加载优化
1. 对于不同的使用场景增加了不同的配置功能
2. 优化了启动时的日志

kindring 3 giorni fa
parent
commit
f575340c90
3 ha cambiato i file con 206 aggiunte e 36 eliminazioni
  1. 8 0
      bird_tool/Config.cs
  2. 1 3
      bird_tool/SerialManager.cs
  3. 197 33
      bird_tool/bird_tool.cs

+ 8 - 0
bird_tool/Config.cs

@@ -24,6 +24,10 @@ namespace Bird_tool
     }
     public class AppConfig
     {
+        // 是否启用硬件测试功能, 该功能涉及到部分配置码所以需要根据配置文件调整
+        public bool enable_hw_test { get; set; } = true;
+        // 测试工具密码, 用于给部分客户时隐藏硬件测试功能
+        public string test_tool_passwd { get; set; } = "szhfy";
         public bool enable_local_server { get; set; } = true;
         public string api_address { get; set; } = "hofuniot.cn";
         public int web_port = 8080;
@@ -33,6 +37,10 @@ namespace Bird_tool
         // 是否加载excel文件
         public bool enable_excel_load { get; set; } = true;
         
+        // 工具针对的设备类型 lw:乐微  fy:梵悦
+        public string c_dev_key { get; set; } = "lw";
+        
+
         public string excel_path { get; set; } = "test.xlsx";
         // excel 表格中主键的列名
         public string excel_primary_key { get; set; } = "uuid";

+ 1 - 3
bird_tool/SerialManager.cs

@@ -11,7 +11,6 @@ namespace Bird_tool
         public delegate void LogHandler(string message, LogLevel level);
         public delegate void LogShowHandler(string message);
         public event LogHandler OnLog;
-        public event LogShowHandler OnLogShow;
 
         public delegate void DisconnectHandler(bool isError);
         public delegate void ConnectHandler();
@@ -180,8 +179,7 @@ namespace Bird_tool
                 }
             }
         }
-
-        int i = 0;
+        
         private void ParseText(string line)
         {
             // 调用外部注册的事件处理器

+ 197 - 33
bird_tool/bird_tool.cs

@@ -41,6 +41,13 @@ namespace Bird_tool
         TestSingle
     }
 
+    // 设备类型
+    public enum DeviceType
+    {
+        FANYUE_DEVICE,
+        LEWEI_DEVICE
+    }
+
     public partial class bird_tool : Form
     {
         private SerialManager _serialManager = new SerialManager();//定义串口
@@ -52,31 +59,27 @@ namespace Bird_tool
 
         // 是否加载了配置
         private AppConfig appConfig = ConfigManager.LoadConfig();
-        private bool flag_load_config = false;
-        // 是否选择串口
-        private bool flag_selected_serial = false;
+        
         private static LogLevel show_log_level = LogLevel.info;
         private static StringBuilder logBuilder = new StringBuilder();
 
         private static ExcelDataManager m_excel_manager;
         private string m_config_uuid = "";
-        
 
+        private bool SetWifi = false;
+        private bool allow_hw_test = false;
         private bool result_success = false;
         private string result_msg = "";
         private TestMode m_test_mode = TestMode.none;
+        private DeviceType m_device_type = DeviceType.LEWEI_DEVICE;
 
-        private string AppConfigPath = "";
-
-        private bool SetWifi = false;
+        private string test_tool_passwd = "szhfy";
         private string wifi_ssid = "";
         private string wifi_password = "";
         private string wifi_act = "hfyswj100";
         private string sd_act = "hfyswj188";
         private string debug_passwd = "hfyswj100";
-
-        private string excel_path = "test.xlsx";
-        private string excel_primary_key = "uuid";
+        
 
         private string hw_test_csv_path = "TestReport/report.csv";
         private string config_csv_path = "ConfigReport/report.csv";
@@ -301,11 +304,46 @@ namespace Bird_tool
             
             _uart_ui_change(false);
             SerialPort_Load();
-            
-            _imageSharpnessServer = new ImageSharpnessServer("*", appConfig.web_port);
-            _ip_ui_change();
+
+            // 判断是什么厂商的设备配置模式
+            if (appConfig.c_dev_key == "fy")
+            {
+                m_device_type = DeviceType.FANYUE_DEVICE;
+                Log($"梵悦观鸟器配置工具启动中");
+            }
+            else
+            {
+                m_device_type = DeviceType.LEWEI_DEVICE;
+                Log($"观鸟器配置工具启动中");
+            }
+
+            // 判断是否显示硬件测试按钮
+            if (appConfig.enable_hw_test)
+            {
+                if (test_tool_passwd == appConfig.test_tool_passwd)
+                {
+                    allow_hw_test = true;
+                }
+                else
+                {
+                    Log($"无法启用硬件配置功能! 工具密码错误", LogLevel.error);
+                    allow_hw_test = false;
+                }
+            }
+            else
+            {
+                Log($"不启用硬件配置功能! 可在配置文件中进行调整");
+                allow_hw_test = false;
+            }
+            // 控制ui界面用于是否显示硬件测试按钮
+            ui_show_hw(allow_hw_test);
+
+
+
             if (appConfig.enable_local_server)
             {
+                _imageSharpnessServer = new ImageSharpnessServer("*", appConfig.web_port);
+                _ip_ui_change();
                 if (_imageSharpnessServer.Start())
                 {
                     Log_show($"网络服务已经启动, localhost:{appConfig.web_port}");
@@ -315,6 +353,11 @@ namespace Bird_tool
                     Log_show($"网络服务启动失败, 请用管理员模式启动或者更换端口");
                 }
             }
+
+            
+            
+
+
             //_serialManager.OnLineReceived += _handle_received_line;
             _serialManager.OnDisconnect += (isError) =>
             {
@@ -334,6 +377,8 @@ namespace Bird_tool
             
             if (appConfig.enable_excel_load)
             {
+                Log($"启用excel文件,尝试加载excel文件中 {appConfig.excel_path}");
+
                 m_excel_manager = new ExcelDataManager(appConfig);
                 m_excel_manager.OnLog += Log;
                 m_excel_manager.OnLogShow += Log_show;
@@ -343,24 +388,22 @@ namespace Bird_tool
                     Log_show("excel 文件加载失败, 将禁用ecxel相关功能");
                 }
             }
+            else
+            {
+                Log($"不使用excel加载, 仅使用基础检测功能");
+                Log($"如果需要使用excel配置功能, 请在配置文件{ConfigManager.getConfigPath()}中进行配置");
+            }
         }
         private void load_app_config()
         {
-            Log($"加载配置文件 {ConfigManager.getConfigPath()}");
+            Log($"观鸟器启动中, 正在加载配置文件 {ConfigManager.getConfigPath()}");
             appConfig = ConfigManager.LoadConfig();
+
             wifi_ssid = appConfig.wifi_ssid;
             wifi_password = appConfig.wifi_passwd;
             txt_ssid.Text = wifi_ssid;
             txt_password.Text = wifi_password;
-            if (appConfig.enable_excel_load)
-            {
-                Log($"启用excel文件,尝试加载excel文件中 {appConfig.excel_path}");
-            }
-            else
-            {
-                Log($"不使用excel加载, 仅使用基础检测功能");
-                Log($"如果需要使用excel配置功能, 请在配置文件{ConfigManager.getConfigPath()}中进行配置");
-            }
+            
         }
 
         private void SerialPort_Load()
@@ -704,6 +747,10 @@ namespace Bird_tool
         {
             this.el_btn_sd_test.Visible = isShow;
         }
+        private void ui_show_hw(bool isShow)
+        {
+            this.el_btn_hw_test.Visible = isShow;
+        }
         private void ui_hide_start_panpel()
         {
             tableLayoutPanel.Visible = false;
@@ -739,7 +786,6 @@ namespace Bird_tool
         // device mac
         private void hw_test()
         {
-            
             var steps = CreateTestSteps();
             if (!_testExecutor.InitTest(steps))
             {
@@ -791,7 +837,7 @@ namespace Bird_tool
 
             Log($"[{DateTime.Now}] 格式化sd卡");
         }
-        private string ask_query_id()
+        private string ask_query_id(string id_text = "uuid")
         {
             string deviceId = "";
             while (true) // 使用循环代替递归
@@ -802,15 +848,18 @@ namespace Bird_tool
                     return "";
                 }
 
-                using (var idDialog = new IdInputDialog("请输入uuid"))
+                using (var idDialog = new IdInputDialog($"请输入{id_text}"))
                 {
                     if (idDialog.ShowDialog() == DialogResult.OK)
                     {
                         deviceId = idDialog.EnteredId;
                         var row = m_excel_manager.GetRowByKey(deviceId);
+                        string error_msg = $"{id_text}异常, 请重新输入或者检查excel文件";
                         if (row == null)
                         {
-                            StopTest(false, "uuid异常, 请重新输入或者检查excel文件");
+                            StopTest(false, error_msg);
+                            progressPanel.Message = error_msg;
+                            progressPanel.ShowTestResult(false, error_msg, LoadCancelledImage());
                             return "";
                         }
 
@@ -851,9 +900,19 @@ namespace Bird_tool
             // 
             if (m_test_mode == TestMode.config)
             {
-                if (!initConfigTest())
+                bool tmp_flag = false;
+                // 判断设备模式
+                if (m_device_type == DeviceType.FANYUE_DEVICE)
+                {
+                    tmp_flag = initConfigTest_by_fanyue();
+                }
+                else if(m_device_type == DeviceType.LEWEI_DEVICE)
                 {
-                    Log("涂鸦uuid输入错误!!", LogLevel.error);
+                    tmp_flag = initConfigTest_by_lewei();
+                }
+                if (!tmp_flag)
+                {
+                    Log("设备id输入错误!!", LogLevel.error);
                     //Log_show("无法初始化涂鸦相关命令");
                     return;
                 }
@@ -1012,6 +1071,28 @@ namespace Bird_tool
             {
                 // 按钮长按功能测试
                 ///**
+               new TestStepConfig
+                {
+                    GroupId = "btn_long",
+                    GroupName = "按钮测试",
+                    Name = "重置按钮",
+                    Tips = "请按下重置按钮",
+                    Command = "",
+                    SuccessText = "OS start",
+                    Timeout = 30000,
+                    MaxRetries = 3,
+                },
+               new TestStepConfig
+                {
+                    GroupId = "btn_long",
+                    GroupName = "等待主控启动",
+                    Name = "重置按钮",
+                    Tips = "等待主控连接",
+                    Command = "",
+                    SuccessText = "<=OK cmd:16",
+                    Timeout = 30000,
+                    MaxRetries = 3,
+                },
                 new TestStepConfig
                 {
                     GroupId = "btn_long",
@@ -1464,9 +1545,9 @@ namespace Bird_tool
             };
         }
 
-        private bool initConfigTest()
+        private bool initConfigTest_by_fanyue()
         {
-            string uuid = ask_query_id();
+            string uuid = ask_query_id("uuid");
             if (string.IsNullOrEmpty(uuid))
             {
                 return false;
@@ -1584,6 +1665,74 @@ namespace Bird_tool
                 MaxRetries = 2,
             });
 
+            ret_steps.Add(new TestStepConfig
+            {
+                GroupId = "device_config",
+                Name = "配置上传地址",
+                Tips = "配置上传地址水印...",
+                Command = "AT+SEND=1, at+campara=6\\,\"http://robinsnote.shop/web/assets/add\"\r\n",
+                SuccessPattern = "<=OK cmd:20",
+                Timeout = 6000,
+                DelayBefore = 500,
+                MaxRetries = 2,
+            });
+
+            ret_steps.Add(new TestStepConfig
+            {
+                GroupId = "device_config",
+                Name = "配置视频后缀",
+                Tips = "配置视频文件后缀...",
+                Command = "AT+SEND=1, at+campara=5\\,\"mp4\"\r\n",
+                SuccessPattern = "<=OK cmd:20",
+                Timeout = 6000,
+                DelayBefore = 500,
+                MaxRetries = 2,
+            });
+
+            ret_steps.Add(new TestStepConfig
+            {
+                GroupId = "device_config",
+                Name = "配置视频编码",
+                Tips = "配置视频编码为265...",
+                Command = "AT+SEND=1, at+campara=23\\,0\\,0\r\n",
+                SuccessPattern = "<=OK cmd:20",
+                Timeout = 6000,
+                DelayBefore = 500,
+                MaxRetries = 2,
+            });
+            ret_steps.Add(new TestStepConfig
+            {
+                GroupId = "device_config",
+                Name = "配置音频编码",
+                Tips = "配置音频编码为pcmu...",
+                Command = "AT+SEND=1, at+campara=20\\,2\r\n",
+                SuccessPattern = "<=OK cmd:20",
+                Timeout = 6000,
+                DelayBefore = 500,
+                MaxRetries = 2,
+            });
+            ret_steps.Add(new TestStepConfig
+            {
+                GroupId = "device_config",
+                Name = "保存配置",
+                Tips = "保存设备配置中",
+                Command = "AT+SEND=1, at+camscont\r\n",
+                SuccessPattern = "<=OK cmd:20",
+                Timeout = 6000,
+                DelayBefore = 500,
+                MaxRetries = 2,
+            });
+            ret_steps.Add(new TestStepConfig
+            {
+                GroupId = "device_config",
+                Name = "配置日志等级",
+                Tips = "配置设备日志等级...",
+                Command = "AT+SEND=1, AT+FACTORY=2\\,0\r\n",
+                SuccessPattern = "<=OK cmd:20",
+                Timeout = 6000,
+                DelayBefore = 500,
+                MaxRetries = 2,
+            });
 
             if (!_testExecutor.InitTest(ret_steps))
             {
@@ -1604,6 +1753,21 @@ namespace Bird_tool
             return true;
         }
 
+        private bool initConfigTest_by_lewei()
+        {
+            string dev_id = ask_query_id("id");
+            if (string.IsNullOrEmpty(dev_id))
+            {
+                return false;
+            }
+            Log($"用户输入id: {dev_id}");
+            var (names, values) = m_excel_manager.GetVariableListByKey(dev_id);
+            m_config_uuid = dev_id;
+            List<TestStepConfig> ret_steps = new List<TestStepConfig>();
+            // 配置28项
+            return false;
+        }
+       
         private bool IsValidMac(string mac)
         {
             // 实现MAC地址验证逻辑
@@ -1870,7 +2034,7 @@ namespace Bird_tool
                 var prompt = new Form
                 {
                     Width = 450,
-                    Height = 250,
+                    Height = 270,
                     FormBorderStyle = FormBorderStyle.FixedDialog,
                     Text = "操作确认",
                     StartPosition = FormStartPosition.CenterParent,
@@ -1900,7 +2064,7 @@ namespace Bird_tool
                     Text = question,
                     Dock = DockStyle.Fill,
                     TextAlign = ContentAlignment.MiddleCenter,
-                    Font = new Font("Microsoft YaHei UI", 20, FontStyle.Regular),
+                    Font = new Font("Microsoft YaHei UI", 18, FontStyle.Regular),
                     AutoSize = false
                 };