关闭产测相关判断
authorxue <2144439972@qq.com>
Sat, 25 Apr 2026 03:58:05 +0000 (11:58 +0800)
committerxue <2144439972@qq.com>
Sat, 25 Apr 2026 03:58:05 +0000 (11:58 +0800)
mainwindow.cpp
mainwindow.h

index a97a573..29965f2 100644 (file)
@@ -1,4 +1,4 @@
-#include "mainwindow.h"
+#include "mainwindow.h"
 #include "ui_mainwindow.h"
 #include "config_manager.h"
 #include <QMessageBox>
@@ -136,7 +136,6 @@ MainWindow::MainWindow(QWidget *parent)
     configManager.loadConfig();
     // 初始化开机检测相关变量
     bootDetected = false;
-    factoryModeChecked = false;
     versionInfoFetched = false;
     // 初始化版本信息获取相关变量
     versionCommandQueue.clear();
@@ -572,11 +571,6 @@ void MainWindow::readSerialData()
             }
         }
         
-        // 产测模式检测(在检测到开机后执行)
-        if (bootDetected && !factoryModeChecked && !isProductionTestRunning) {
-            checkFactoryMode(line);
-        }
-
         // 产测已开始:等待开机完成关键字后再进入 PMADDVOTE(与空闲时的 checkBootDetection 使用同一关键字列表)
         if (isProductionTestRunning && currentTestStep == TEST_WAIT_BOOT) {
             tryAdvanceProductionAfterBootKeywords(line);
@@ -610,47 +604,6 @@ void MainWindow::readSerialData()
             parseWstpPrintData(line);
         }
         
-        // 检测FACTORY TEST MODE状态(wstp_print格式)
-        if (line.contains("FACTORY TEST MODE:", Qt::CaseInsensitive)) {
-            qDebug() << "检测到FACTORY TEST MODE信息:" << line.trimmed();
-            appendToLogFile(QString("检测到FACTORY TEST MODE信息: %1\n").arg(line.trimmed()));
-            
-            if (line.contains("FACTORY TEST MODE: ENABLED", Qt::CaseInsensitive)) {
-                // 产测模式已开启
-                ui->factoryModeLineEdit->setText("是");
-                ui->factoryModeLineEdit->setStyleSheet("background-color: #ffcccc;"); // 红底
-                qDebug() << "产测模式: 已开启";
-                appendToLogFile(QString("=== 产测模式状态: 已开启 ===\n"));
-                
-                // 仅在非产测流程中自动拉版本;产测时串口可能出现该行,避免与当前测试 AT 并发(如 G-sensor)
-                if (!isProductionTestRunning && !factoryModeChecked) {
-                    factoryModeChecked = true;
-                    QTimer::singleShot(1000, this, [this]() {
-                        if (!isProductionTestRunning && !versionInfoFetched) {
-                            startVersionInfoFetch();
-                        }
-                    });
-                }
-            } else if (line.contains("FACTORY TEST MODE: DISABLED", Qt::CaseInsensitive)) {
-                // 产测模式已关闭
-                ui->factoryModeLineEdit->setText("否");
-                ui->factoryModeLineEdit->setStyleSheet("background-color: #ccffcc;"); // 绿底
-                qDebug() << "产测模式: 已关闭";
-                appendToLogFile(QString("=== 产测模式状态: 已关闭 ===\n"));
-                
-                if (!isProductionTestRunning && !factoryModeChecked) {
-                    factoryModeChecked = true;
-                    QTimer::singleShot(1000, this, [this]() {
-                        if (!isProductionTestRunning && !versionInfoFetched) {
-                            startVersionInfoFetch();
-                        }
-                    });
-                }
-            }
-        }
-        
-        // 4G/PPP 相关解析已移除
-        
         // 检测工厂模式进入确认(用于产测;兼容 facotry/factory 拼写,大小写不敏感)
         if (line.contains("enter or exit facotry mode", Qt::CaseInsensitive) ||
             line.contains("enter or exit factory mode", Qt::CaseInsensitive)) {
@@ -2449,7 +2402,6 @@ void MainWindow::beginProductionTestSession()
 
     // 重置开机检测状态
     bootDetected = false;
-    factoryModeChecked = false;
     versionInfoFetched = false;
 
     // 清空设备信息
@@ -2597,8 +2549,20 @@ void MainWindow::beginAudioTestAttempt()
 
     audioTestAwaitingMicLevel = true;
 
+    // 仅使用音量数值(如 2.0)。若误填整句 AT^AUDIOTEST=7 2.0 或多余 AT^,与下方前缀拼接会变成 AT^AT^...,固件报 cannot find cmd handle
     QString volumeStr = ui->audioVolumeLineEdit->text().trimmed();
-    if (volumeStr.isEmpty()) volumeStr = "2.0";
+    if (volumeStr.isEmpty()) {
+        volumeStr = QStringLiteral("2.0");
+    } else {
+        while (volumeStr.startsWith(QLatin1String("AT^"), Qt::CaseInsensitive)) {
+            volumeStr = volumeStr.mid(3).trimmed();
+        }
+        volumeStr.remove(QRegExp("^AUDIOTEST\\s*=\\s*7\\s+", Qt::CaseInsensitive));
+        volumeStr = volumeStr.trimmed();
+        if (volumeStr.isEmpty()) {
+            volumeStr = QStringLiteral("2.0");
+        }
+    }
 
     QTimer::singleShot(200, this, [this, volumeStr]() {
         if (!isProductionTestRunning || currentTestStep != TEST_AUDIO || !serial || !serial->isOpen()) {
@@ -4449,141 +4413,18 @@ void MainWindow::checkBootDetection(const QString& data)
             
             bootDetected = true;
             
-            // 延迟1秒后自动发送产测模式检测指令(无论是否有日志,都要检测)
+            // 延迟1秒后自动拉版本信息(不再发 AT^FACTORY? / 解析 FACTORY TEST MODE)
             QTimer::singleShot(1000, this, [this]() {
-                if (!factoryModeChecked && serial->isOpen()) {
-                    QString cmd = configManager.getFactoryModeCheckCommand();
-                    if (!cmd.isEmpty()) {
-                        // 如果是查询指令,确保使用 ? 参数
-                        if (!cmd.contains("?") && !cmd.contains("=")) {
-                            cmd = cmd + "?";
-                        }
-                        serial->write((cmd + "\r\n").toUtf8());
-                        qDebug() << "检测到开机,自动发送产测模式检测指令:" << cmd;
-                        appendToLogFile(QString("=== 检测到开机,自动发送产测模式检测指令: %1 ===\n").arg(cmd));
-                    } else {
-                        qDebug() << "产测模式检测指令为空,跳过检测";
-                        appendToLogFile(QString("=== 产测模式检测指令为空,跳过检测 ===\n"));
-                        // 如果指令为空,直接标记为已检测,并开始获取版本信息
-                        factoryModeChecked = true;
-                        QTimer::singleShot(1000, this, [this]() {
-                            if (!versionInfoFetched) {
-                                startVersionInfoFetch();
-                            }
-                        });
-                    }
-                } else {
-                    if (!serial->isOpen()) {
-                        qDebug() << "串口未打开,无法发送产测模式检测指令";
-                    } else {
-                        qDebug() << "产测模式已检测过,跳过发送检测指令";
-                    }
-                }
-            });
-            
-            break;
-        }
-    }
-}
-
-// 检测产测模式
-void MainWindow::checkFactoryMode(const QString& data)
-{
-    if (factoryModeChecked) {
-        return; // 已经检测过,不再重复检测
-    }
-    
-    QStringList keywords = configManager.getFactoryModeKeywords();
-    bool found = false;
-    for (const QString& keyword : keywords) {
-        if (data.contains(keyword, Qt::CaseInsensitive)) {
-            qDebug() << "检测到产测模式关键字:" << keyword;
-            appendToLogFile(QString("=== 检测到产测模式: %1 ===\n").arg(keyword));
-            
-            factoryModeChecked = true;
-            found = true;
-            
-            // 解析产测模式状态并更新UI
-            if (data.contains("FACTORY TEST MODE: ENABLED", Qt::CaseInsensitive)) {
-                ui->factoryModeLineEdit->setText("是");
-                ui->factoryModeLineEdit->setStyleSheet("background-color: #ffcccc;"); // 红底
-                qDebug() << "产测模式: 已开启";
-            } else if (data.contains("FACTORY TEST MODE: DISABLED", Qt::CaseInsensitive)) {
-                ui->factoryModeLineEdit->setText("否");
-                ui->factoryModeLineEdit->setStyleSheet("background-color: #ccffcc;"); // 绿底
-                qDebug() << "产测模式: 已关闭";
-            }
-            
-            // 延迟1秒后开始获取版本信息
-            QTimer::singleShot(1000, this, [this]() {
-                if (!versionInfoFetched) {
+                if (!isProductionTestRunning && serial->isOpen() && !versionInfoFetched) {
                     startVersionInfoFetch();
+                } else if (!serial->isOpen()) {
+                    qDebug() << "串口未打开,跳过自动获取版本信息";
                 }
             });
             
             break;
         }
     }
-    
-    // 如果没有检测到产测模式关键字,但收到了产测模式检测指令的响应(可能是OK或ERROR)
-    // 解析 AT^FACTORY 或 AT^FACTORY? 的响应
-    if (!found) {
-        // 检查是否是 AT^FACTORY 相关指令的响应
-        // AT^FACTORY? 的响应可能是:+FACTORY: 1 或 +FACTORY: 0
-        QRegExp factoryResponsePattern("\\+FACTORY:\\s*(\\d+)", Qt::CaseInsensitive);
-        if (factoryResponsePattern.indexIn(data) != -1) {
-            int factoryValue = factoryResponsePattern.cap(1).toInt();
-            qDebug() << "解析到产测模式响应值:" << factoryValue;
-            appendToLogFile(QString("=== 产测模式检测响应: %1 ===\n").arg(factoryValue));
-            
-            factoryModeChecked = true;
-            
-            // 更新UI
-            if (factoryValue == 1) {
-                ui->factoryModeLineEdit->setText("是");
-                ui->factoryModeLineEdit->setStyleSheet("background-color: #ffcccc;"); // 红底
-                qDebug() << "产测模式: 已开启 (响应值=1)";
-            } else {
-                ui->factoryModeLineEdit->setText("否");
-                ui->factoryModeLineEdit->setStyleSheet("background-color: #ccffcc;"); // 绿底
-                qDebug() << "产测模式: 已关闭 (响应值=0)";
-            }
-            
-            // 延迟1秒后开始获取版本信息
-            QTimer::singleShot(1000, this, [this]() {
-                if (!versionInfoFetched) {
-                    startVersionInfoFetch();
-                }
-            });
-        }
-        // 如果响应是OK,可能是 AT^FACTORY 的确认响应(进入产测模式)
-        else if (data.contains("OK", Qt::CaseInsensitive) && 
-                 (data.contains("FACTORY", Qt::CaseInsensitive) || 
-                  data.contains("AT^FACTORY", Qt::CaseInsensitive))) {
-            qDebug() << "产测模式检测指令返回OK,认为已进入产测模式";
-            appendToLogFile(QString("=== 产测模式检测指令返回OK,认为已进入产测模式 ===\n"));
-            
-            factoryModeChecked = true;
-            
-            // 更新UI(假设OK表示已开启)
-            ui->factoryModeLineEdit->setText("是");
-            ui->factoryModeLineEdit->setStyleSheet("background-color: #ffcccc;"); // 红底
-            
-            // 延迟1秒后开始获取版本信息
-            QTimer::singleShot(1000, this, [this]() {
-                if (!versionInfoFetched) {
-                    startVersionInfoFetch();
-                }
-            });
-        }
-        // 记录其他响应用于调试
-        else if (data.contains("ERROR", Qt::CaseInsensitive) ||
-                 data.contains("+CME ERROR", Qt::CaseInsensitive) ||
-                 data.contains("OK", Qt::CaseInsensitive)) {
-            qDebug() << "产测模式检测指令响应:" << data.trimmed();
-            appendToLogFile(QString("产测模式检测指令响应: %1\n").arg(data.trimmed()));
-        }
-    }
 }
 
 // 开始获取版本信息
index 9bb4747..9c67733 100644 (file)
@@ -61,7 +61,7 @@ private slots:
     void onLcdTestTimer();                  // LCD测试定时器
     void onMotorTestTimer();                // 马达测试定时器
     void onTestTimeout();                   // 通用测试超时处理
-    void checkFactoryModeResult(const QString& data); // 检查工厂模式进入结果
+    void checkFactoryModeResult(const QString& data); // 检查 fac:enter or exit factory mode 确认(备用流程)
     QString getRsrqGrade(double rsrq); // 获取RSRQ信号质量评级
     QString getRsrpGrade(double rsrp); // 获取RSRP信号覆盖强度评级
     QString getOverallSignalAssessment(double rsrp, double rsrq); // 获取整体信号评估
@@ -191,7 +191,6 @@ private:
     
     // 开机检测相关变量
     bool bootDetected;                  // 是否已检测到开机
-    bool factoryModeChecked;            // 是否已检测产测模式
     bool versionInfoFetched;           // 是否已获取版本信息
     
     // 版本信息获取相关变量
@@ -230,7 +229,6 @@ private:
     
     // 开机检测和版本信息获取相关函数
     void checkBootDetection(const QString& data);        // 检测设备开机
-    void checkFactoryMode(const QString& data);          // 检测产测模式
     void startVersionInfoFetch();                        // 开始获取版本信息
     void sendNextVersionCommand();                       // 发送下一个版本信息指令
     void onVersionCommandTimeout();                      // 版本信息指令超时处理