ソースを参照

feat: sd卡格式化功能
1. 增加sd卡格式化入口

kindring 1 週間 前
コミット
f822ab4bb9
3 ファイル変更151 行追加15 行削除
  1. 11 10
      bird_tool/TestEngine.cs
  2. 24 1
      bird_tool/bird_tool.Designer.cs
  3. 116 4
      bird_tool/bird_tool.cs

+ 11 - 10
bird_tool/TestEngine.cs

@@ -407,14 +407,14 @@ namespace Bird_tool
                 // 取消所有任务
                 _cts.Cancel();
                 // 清空任务队列
-                OnLog?.Invoke($"_cts.Cancel();", LogLevel.error);
+                OnLog?.Invoke($"_cts.Cancel();", LogLevel.debug);
                 // 等待队列处理完成(如果需要)
                 if (waitForCompletion && _queueProcessor != null && !_queueProcessor.IsCompleted)
                 {
-                    OnLog?.Invoke($"_queueProcessor", LogLevel.error);
+                    OnLog?.Invoke($"_queueProcessor", LogLevel.debug);
                     await _queueProcessor;
                 }
-                OnLog?.Invoke($"_queueProcessor ok", LogLevel.error);
+                OnLog?.Invoke($"_queueProcessor ok", LogLevel.debug);
             }
             catch (Exception ex)
             {
@@ -428,7 +428,7 @@ namespace Bird_tool
                     _serialManager.Disconnect();
                     _serialManager.OnLineReceived -= HandleResponse;
                 }
-                OnLog?.Invoke($"_serialManager", LogLevel.error);
+                OnLog?.Invoke($"_serialManager clean", LogLevel.debug);
 
                 // 重置上下文但保留配置
                 if (_context != null)
@@ -438,19 +438,20 @@ namespace Bird_tool
                     _context.Report = new TestReport();
                 }
 
-                OnLog?.Invoke($"Dispose", LogLevel.debug);
+                OnLog?.Invoke($"_cts?.Dispose(); ", LogLevel.debug);
                 // 重新创建资源
                 _cts?.Dispose();
                 _cts = new CancellationTokenSource();
-                OnLog?.Invoke($"StartQueueProcessor", LogLevel.debug);
-                // 重新启动队列处理器
                 
-                OnLog?.Invoke($"停止任务完成", LogLevel.debug);
+                
+                
                 if (testEnd && isStart)
                 {
                     OnTestEnd?.Invoke(false);
                 }
                 isStart = false;
+                OnLog?.Invoke($"资源重置", LogLevel.info);
+                // 重新启动队列处理器
                 StartQueueProcessor();
 
             }
@@ -516,7 +517,7 @@ namespace Bird_tool
                 step.JumpCount = 0;
             }
         }
-        public bool StartTest()
+        public bool StartTest(bool mkResult = true)
         {
             lock (_lock)
             {
@@ -524,7 +525,7 @@ namespace Bird_tool
                 {
                     return false;
                 }
-                enableMakeResult = true;
+                enableMakeResult = mkResult;
                 return StartTestWithSteps(_step_map); ;
             }
         }

+ 24 - 1
bird_tool/bird_tool.Designer.cs

@@ -39,6 +39,7 @@ namespace Bird_tool
             this.el_btn_refresh = new System.Windows.Forms.Button();
             this.el_btn_conn = new System.Windows.Forms.Button();
             this.el_btn_hw_test = new System.Windows.Forms.Button();
+            this.el_btn_sd_test = new System.Windows.Forms.Button();
             this.el_btn_config = new System.Windows.Forms.Button();
             this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel();
             this.tableLayoutPanel.SuspendLayout();
@@ -120,6 +121,24 @@ namespace Bird_tool
             this.el_btn_config.Text = "出货配置";
             this.el_btn_config.UseVisualStyleBackColor = false;
             this.el_btn_config.Click += new System.EventHandler(this.Evt_conn_click);
+
+            this.el_btn_sd_test.Anchor = System.Windows.Forms.AnchorStyles.None;
+            this.el_btn_sd_test.BackColor = System.Drawing.SystemColors.Control;
+            this.el_btn_sd_test.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+            this.el_btn_sd_test.Cursor = System.Windows.Forms.Cursors.No;
+            this.el_btn_sd_test.Enabled = false;
+            this.el_btn_sd_test.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
+            this.el_btn_sd_test.Font = new System.Drawing.Font("宋体", 16F);
+            this.el_btn_sd_test.ForeColor = System.Drawing.SystemColors.GrayText;
+            this.el_btn_sd_test.Location = new System.Drawing.Point(25, 308);
+            this.el_btn_sd_test.Margin = new System.Windows.Forms.Padding(2);
+            this.el_btn_sd_test.Name = "el_btn_sd_test";
+            this.el_btn_sd_test.Size = new System.Drawing.Size(160, 50);
+            this.el_btn_sd_test.TabIndex = 1;
+            this.el_btn_sd_test.Text = "sd卡格式化";
+            this.el_btn_sd_test.UseVisualStyleBackColor = false;
+            this.el_btn_sd_test.Click += new System.EventHandler(this.Evt_sd_click);
+
             // 
             // tableLayoutPanel
             // 
@@ -128,7 +147,10 @@ namespace Bird_tool
             this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle());
             this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
             this.tableLayoutPanel.Controls.Add(this.el_btn_hw_test, 0, 1);
+            // 出货配置入口
             this.tableLayoutPanel.Controls.Add(this.el_btn_config, 2, 1);
+            // 不允许外部人员进行格式化
+            //this.tableLayoutPanel.Controls.Add(this.el_btn_sd_test, 0, 2);
             this.tableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
             this.tableLayoutPanel.Location = new System.Drawing.Point(0, 0);
             this.tableLayoutPanel.Name = "tableLayoutPanel";
@@ -281,7 +303,8 @@ namespace Bird_tool
         // 选择项目按钮
         private System.Windows.Forms.Button el_btn_hw_test;
         private System.Windows.Forms.Button el_btn_config;
-        
+        private System.Windows.Forms.Button el_btn_sd_test;
+
         // 测试进度面板
         private ProgressPanel progressPanel;
 

+ 116 - 4
bird_tool/bird_tool.cs

@@ -30,6 +30,7 @@ namespace Bird_tool
     {
         none,
         hw_test,
+        sd_test,
         config
     }
 
@@ -59,6 +60,7 @@ namespace Bird_tool
 
         private bool result_success = false;
         private string result_msg = "";
+        private TestMode m_test_mode = TestMode.none;
 
         private bool SetWifi = false;
         private string wifi_ssid = "";
@@ -458,6 +460,18 @@ namespace Bird_tool
             checkWifi();
             hw_test();
         }
+        private void Evt_sd_click(object sender, EventArgs e)
+        {
+            if (!_serialManager.IsOpen())
+            {
+                MessageBox.Show("请先打开串口");
+                _serialManager.Disconnect();
+                System.Threading.Thread.Sleep(100);
+                _uart_ui_change(false);
+                return;
+            }
+            sd_test();
+        }
 
         private void Evt_set_wifi(object sender, EventArgs e)
         {
@@ -490,6 +504,7 @@ namespace Bird_tool
         private void _SetTestButtonsEnabled(bool enabled)
         {
             el_btn_hw_test.Enabled = enabled;
+            el_btn_sd_test.Enabled = enabled;
             el_btn_config.Enabled = enabled;
 
             // 可选:添加视觉反馈
@@ -505,6 +520,11 @@ namespace Bird_tool
                 el_btn_config.FlatStyle = FlatStyle.Standard;
                 el_btn_config.Cursor = Cursors.Default;
 
+                el_btn_sd_test.BackColor = SystemColors.Control;  // 标准按钮背景色
+                el_btn_sd_test.ForeColor = SystemColors.ControlText;  // 标准文本色
+                el_btn_sd_test.FlatStyle = FlatStyle.Standard;  // 恢复原始样式
+                el_btn_sd_test.Cursor = Cursors.Default;
+
             }
             else
             {
@@ -518,6 +538,11 @@ namespace Bird_tool
                 el_btn_config.ForeColor = SystemColors.GrayText;
                 el_btn_config.FlatStyle = FlatStyle.Flat;
                 el_btn_config.Cursor = Cursors.No;
+
+                el_btn_sd_test.BackColor = SystemColors.Control;  // 保持背景色
+                el_btn_sd_test.ForeColor = SystemColors.GrayText;  // 标准禁用文本色
+                el_btn_sd_test.FlatStyle = FlatStyle.Flat;  // 扁平化样式增强禁用感
+                el_btn_sd_test.Cursor = Cursors.No;
             }
         }
 
@@ -798,7 +823,9 @@ namespace Bird_tool
 
         private void config_test()
         {
-
+            Log_show("无法创建测试表");
+            StopTest(false);
+            return;
         }
 
         // device mac
@@ -812,6 +839,7 @@ namespace Bird_tool
                 StopTest(false);
                 return;
             }
+            m_test_mode = TestMode.hw_test;
             ui_show_test_panpel();
             progressPanel.ResetPanel();
 
@@ -829,6 +857,33 @@ namespace Bird_tool
             Log($"[{DateTime.Now}] 开始硬件测试");
         }
 
+        private void sd_test()
+        {
+
+            var steps = CreateSDSteps();
+            if (!_testExecutor.InitTest(steps))
+            {
+                Log_show("无法创建测试表");
+                StopTest(false);
+                return;
+            }
+            m_test_mode = TestMode.sd_test;
+            ui_show_test_panpel();
+            progressPanel.ResetPanel();
+
+            var groups = _testExecutor.GetGroupInfos();
+            foreach (var group in groups)
+            {
+                if (group.ShowStep)
+                {
+                    progressPanel.AddTestStep(group.RowKey, group.GroupName);
+                }
+            }
+            progressPanel.Message = "点击开始测试按钮进行测试";
+
+            Log($"[{DateTime.Now}] 格式化sd卡");
+        }
+
         private void StartTest(TestType testType, string groupId = null)
         {
             if (!_testExecutor.isInit)
@@ -853,9 +908,14 @@ namespace Bird_tool
             progressPanel.Message = "准备开始硬件测试...";
             progressPanel.startTest();
             bool start_flag = false;
+            bool makeResult = false;
+            if (m_test_mode == TestMode.hw_test)
+            {
+                makeResult = true;
+            }
             if (string.IsNullOrEmpty(groupId))
             {
-                start_flag = _testExecutor.StartTest();
+                start_flag = _testExecutor.StartTest(makeResult);
             }
             else
             {
@@ -869,7 +929,7 @@ namespace Bird_tool
                 }
                 else
                 {
-                    start_flag = _testExecutor.StartTest();
+                    start_flag = _testExecutor.StartTest(makeResult);
                 }
             }
 
@@ -1170,6 +1230,17 @@ namespace Bird_tool
                 },
                 // sd卡测试
                 new TestStepConfig
+                {
+                    GroupId = "sdLoad",
+                    ShowStep = false,
+                    Name = "配置sd卡密码",
+                    Tips = "自动配置sd卡",
+                    PrivateCammand = true,
+                    Action = ActionMode.SetVal,
+                    VariableNames = { "sdpasswd" },
+                    VariableValues = { sd_act },
+                },
+                new TestStepConfig
                 {
                     GroupId = "sdLoad",
                     Key = "sdLoad",
@@ -1194,6 +1265,7 @@ namespace Bird_tool
                     DelayBefore = 1000,
                     MaxJump = 5,
                 },
+                
 
                 // 音频测试
                 ///**
@@ -1363,11 +1435,51 @@ namespace Bird_tool
                 
                 // 上传测试
 
+            };
+        }
 
+        private List<TestStepConfig> CreateSDSteps()
+        {
+            return new List<TestStepConfig>
+            {
 
+                new TestStepConfig
+                {
+                    Name = "测试模式",
+                    Command = "AT+OSLP=1,0\r\n",
+                    Tips = "启用测试模式中",
+                    SuccessPattern = "Wakeup, unsleep:1 debug:0",
+                    FailurePattern = "ERROR|FAIL",
+                    Timeout = 4000,
+                    DelayBefore = 300,
+                },
+                new TestStepConfig
+                {
+                    GroupId = "sdLoad",
+                    ShowStep = false,
+                    Name = "配置sd卡密码",
+                    Tips = "自动配置sd卡",
+                    PrivateCammand = true,
+                    Action = ActionMode.SetVal,
+                    VariableNames = { "sdpasswd" },
+                    VariableValues = { sd_act },
+                },
+                new TestStepConfig
+                {
+                    GroupId = "sdLoad",
+                    GroupName = "SD卡格式化",
+                    Name = "SD卡格式化",
+                    Command = "AT+SEND=1,AT_SDHCI=2\\,\"{{sdpasswd}}\"?\r\n",
+                    Tips = "尝试格式化SD卡中",
+                    PrivateCammand = true,
+                    SuccessPattern = "Verify err:0",
+                    RetryFromKey = "sdLoad",
+                    Timeout = 60000,
+                    DelayBefore = 1000,
+                    MaxJump = 5,
+                },
             };
         }
-        
         private bool IsValidMac(string mac)
         {
             // 实现MAC地址验证逻辑