1.优化.gsensor门限判断,超限时打印具体不匹配数据
authorxue <2144439972@qq.com>
Sat, 11 Apr 2026 02:25:51 +0000 (10:25 +0800)
committerxue <2144439972@qq.com>
Sat, 11 Apr 2026 02:25:51 +0000 (10:25 +0800)
2.优化广播蓝牙保存机制,直接判断文本框里的广播蓝牙

mainwindow.cpp
mainwindow.h
mainwindow.ui

index 4239790..27f475c 100644 (file)
@@ -3291,6 +3291,37 @@ void MainWindow::performGsensorTest()
         gSensorIntervalTimer->stop();
     }
 
+    // min/max 用 QString::toDouble,负 min、正 max 与全负/全正区间均按数值比较,无需单独分支
+    {
+        auto parseG = [](const QString& s, bool& ok) -> double {
+            QString t = s.trimmed();
+            if (t.isEmpty()) {
+                ok = false;
+                return 0.0;
+            }
+            return t.toDouble(&ok);
+        };
+        bool oxm = false, oxx = false, oym = false, oyx = false, ozm = false, ozx = false;
+        const double xm = parseG(ui->gsensorDeltaXMinLineEdit->text(), oxm);
+        const double xx = parseG(ui->gsensorDeltaXMaxLineEdit->text(), oxx);
+        const double ym = parseG(ui->gsensorDeltaYMinLineEdit->text(), oym);
+        const double yx = parseG(ui->gsensorDeltaYMaxLineEdit->text(), oyx);
+        const double zm = parseG(ui->gsensorDeltaZMinLineEdit->text(), ozm);
+        const double zx = parseG(ui->gsensorDeltaZMaxLineEdit->text(), ozx);
+        if (oxm && oxx && xm >= xx) {
+            ui->recvTextEdit->append(QString(">>> G-sensor参数警告: X 的 min(%1) ≥ max(%2),不存在满足 min<X<max 的值")
+                                         .arg(xm, 0, 'g', 8).arg(xx, 0, 'g', 8));
+        }
+        if (oym && oyx && ym >= yx) {
+            ui->recvTextEdit->append(QString(">>> G-sensor参数警告: Y 的 min(%1) ≥ max(%2),不存在满足 min<Y<max 的值")
+                                         .arg(ym, 0, 'g', 8).arg(yx, 0, 'g', 8));
+        }
+        if (ozm && ozx && zm >= zx) {
+            ui->recvTextEdit->append(QString(">>> G-sensor参数警告: Z 的 min(%1) ≥ max(%2),不存在满足 min<Z<max 的值")
+                                         .arg(zm, 0, 'g', 8).arg(zx, 0, 'g', 8));
+        }
+    }
+
     // 1) 延迟一点后开始打印XYZ
     QTimer::singleShot(300, this, [this]() {
         if (!isProductionTestRunning || currentTestStep != TEST_GSENSOR) {
@@ -3359,7 +3390,7 @@ void MainWindow::checkGsensorTestResult(const QString& data)
                 gSensorLastY = y;
                 gSensorLastZ = z;
 
-                // 每条采样都要满足阈值范围
+                // 瞬时 XYZ(如 XYZ:X=0.00,Y=0.19,Z=-9.92):开区间 min < 值 < max;min 可为负、max 可为正,与其它组合同为 double 比较
                 auto parseDoubleOrInvalid = [](const QString& s, bool& ok) -> double {
                     QString t = s.trimmed();
                     if (t.isEmpty()) {
@@ -3377,16 +3408,37 @@ void MainWindow::checkGsensorTestResult(const QString& data)
                 double zMax = parseDoubleOrInvalid(ui->gsensorDeltaZMaxLineEdit->text(), okZMax);
 
                 bool samplePass = true;
-                if (okXMin && x < xMin) samplePass = false;
-                if (okXMax && x > xMax) samplePass = false;
-                if (okYMin && y < yMin) samplePass = false;
-                if (okYMax && y > yMax) samplePass = false;
-                if (okZMin && z < zMin) samplePass = false;
-                if (okZMax && z > zMax) samplePass = false;
+                QStringList overMsgs;
+                if (okXMin && !(x > xMin)) {
+                    samplePass = false;
+                    overMsgs << QString("X=%1 未满足 X>%2").arg(x, 0, 'f', 3).arg(xMin, 0, 'f', 3);
+                }
+                if (okXMax && !(x < xMax)) {
+                    samplePass = false;
+                    overMsgs << QString("X=%1 未满足 X<%2").arg(x, 0, 'f', 3).arg(xMax, 0, 'f', 3);
+                }
+                if (okYMin && !(y > yMin)) {
+                    samplePass = false;
+                    overMsgs << QString("Y=%1 未满足 Y>%2").arg(y, 0, 'f', 3).arg(yMin, 0, 'f', 3);
+                }
+                if (okYMax && !(y < yMax)) {
+                    samplePass = false;
+                    overMsgs << QString("Y=%1 未满足 Y<%2").arg(y, 0, 'f', 3).arg(yMax, 0, 'f', 3);
+                }
+                if (okZMin && !(z > zMin)) {
+                    samplePass = false;
+                    overMsgs << QString("Z=%1 未满足 Z>%2").arg(z, 0, 'f', 3).arg(zMin, 0, 'f', 3);
+                }
+                if (okZMax && !(z < zMax)) {
+                    samplePass = false;
+                    overMsgs << QString("Z=%1 未满足 Z<%2").arg(z, 0, 'f', 3).arg(zMax, 0, 'f', 3);
+                }
 
                 if (!samplePass) {
                     gSensorAllSamplesInRange = false;
-                    ui->recvTextEdit->append(">>> G-sensor采样超限");
+                    ui->recvTextEdit->append(QString(">>> G-sensor采样超限: %1 (本帧 XYZ=%2,%3,%4)")
+                                                   .arg(overMsgs.join("; "))
+                                                   .arg(x, 0, 'f', 3).arg(y, 0, 'f', 3).arg(z, 0, 'f', 3));
                 }
             }
         }
@@ -3418,7 +3470,7 @@ void MainWindow::onGsensorIntervalTimeout()
     });
 }
 
-// 结束G-sensor判定:要求每条采样都在阈值范围内
+// 结束G-sensor判定:每条采样的瞬时 X/Y/Z 对已配置边界满足严格开区间 min < 值 < max
 void MainWindow::finalizeGsensorTest()
 {
     if (!isProductionTestRunning || currentTestStep != TEST_GSENSOR) {
@@ -3474,10 +3526,10 @@ void MainWindow::finalizeGsensorTest()
     }
 
     if (gSensorAllSamplesInRange) {
-        ui->statusbar->showMessage("G-sensor测试通过:10秒内æ\89\80æ\9c\89XYZé\87\87æ ·å\9d\87å\9c¨é\98\88å\80¼è\8c\83å\9b´", 3000);
+        ui->statusbar->showMessage("G-sensor测试通过:10秒内å\90\84é\87\87æ ·ç\9e¬æ\97¶XYZå\9d\87满足已é\85\8dç½®å¼\80å\8cºé\97´", 3000);
         updateTestStatus("gsensor", STATUS_SUCCESS);
     } else {
-        ui->statusbar->showMessage("G-sensor测试失败:存在超限采样", 3000);
+        ui->statusbar->showMessage("G-sensor测试失败:存在瞬时XYZ超出开区间(min,max)的采样(见日志)", 3000);
         updateTestStatus("gsensor", STATUS_FAILED);
     }
 
@@ -3559,6 +3611,20 @@ void MainWindow::checkLeaklightTestResult(const QString& data)
     }
 }
 
+void MainWindow::getBluetoothExpectFromUiOrConfig(QString& expectAddr, QString& expectRssiStr) const
+{
+    expectAddr = ui->bluetoothAddressLineEdit->text().trimmed().toUpper();
+    expectAddr.replace(QLatin1Char('-'), QLatin1Char(':'));
+    if (expectAddr.isEmpty()) {
+        expectAddr = configManager.getTestConfig("bluetoothAddress", "").trimmed().toUpper();
+        expectAddr.replace(QLatin1Char('-'), QLatin1Char(':'));
+    }
+    expectRssiStr = ui->bluetoothRSSILineEdit->text().trimmed();
+    if (expectRssiStr.isEmpty()) {
+        expectRssiStr = configManager.getTestConfig("bluetoothRSSI", "").trimmed();
+    }
+}
+
 // 执行蓝牙测试
 void MainWindow::performBluetoothTest()
 {
@@ -3588,8 +3654,9 @@ void MainWindow::performBluetoothTest()
     detectedBluetoothRSSI = -128;       // 初始化为很弱的值
     bluetoothMaxRssi = -128;
     
-    QString expectAddr = configManager.getTestConfig("bluetoothAddress", "").trimmed().toUpper();
-    QString expectRssiStr = configManager.getTestConfig("bluetoothRSSI", "").trimmed();
+    QString expectAddr;
+    QString expectRssiStr;
+    getBluetoothExpectFromUiOrConfig(expectAddr, expectRssiStr);
     bool hasTargetAddr = !expectAddr.isEmpty();
     bool hasRssiThresh = !expectRssiStr.isEmpty();
     if (hasTargetAddr && hasRssiThresh) {
@@ -3698,8 +3765,9 @@ void MainWindow::checkBluetoothTestResult(const QString& data)
             bluetoothMaxRssi = rssi;
         }
 
-        QString expectAddr = configManager.getTestConfig("bluetoothAddress", "").trimmed().toUpper();
-        QString expectRssiStr = configManager.getTestConfig("bluetoothRSSI", "").trimmed();
+        QString expectAddr;
+        QString expectRssiStr;
+        getBluetoothExpectFromUiOrConfig(expectAddr, expectRssiStr);
         bool hasTargetAddr = !expectAddr.isEmpty();
         bool hasRssiThresh = !expectRssiStr.isEmpty();
         int expectRssi = hasRssiThresh ? expectRssiStr.toInt() : 0;
@@ -3764,8 +3832,9 @@ void MainWindow::onBluetoothTestTimer()
         return;
     }
     
-    QString expectAddr = configManager.getTestConfig("bluetoothAddress", "").trimmed().toUpper();
-    QString expectRssiStr = configManager.getTestConfig("bluetoothRSSI", "").trimmed();
+    QString expectAddr;
+    QString expectRssiStr;
+    getBluetoothExpectFromUiOrConfig(expectAddr, expectRssiStr);
     bool hasTargetAddr = !expectAddr.isEmpty();
     bool hasRssiThresh = !expectRssiStr.isEmpty();
     int expectRssi = hasRssiThresh ? expectRssiStr.toInt() : 0;
index cc16ffa..20185bb 100644 (file)
@@ -238,8 +238,10 @@ private:
     // 测试项checkbox检查辅助函数
     bool isTestItemEnabled(const QString& testName) const;
     void skipToNextEnabledTest();  // 跳过当前测试项,推进到下一个启用的测试项
+    /// 蓝牙目标 MAC / RSSI:优先界面输入,空则读 settings(与产测是否已保存无关)
+    void getBluetoothExpectFromUiOrConfig(QString& expectAddr, QString& expectRssiStr) const;
 
-    // G-sensor XYZ变化计算:解析UI阈值并更新测试结果
+    // G-sensor:解析瞬时 XYZ 与 UI 开区间阈值并更新测试结果
     void finalizeGsensorTest();
 
     // G-sensor XYZ窗口采集状态
@@ -248,7 +250,7 @@ private:
     bool gSensorHasLast;              // 是否已记录末尾XYZ
     bool gSensorErrorDetected;        // 是否检测到错误/异常响应
     bool gSensorAnySample;            // 10秒窗口内是否采到至少一组XYZ
-    bool gSensorAllSamplesInRange;    // 10秒窗口内是否每组XYZ都在阈值范围内
+    bool gSensorAllSamplesInRange;    // 各采样瞬时X/Y/Z是否均满足已配置边界:min<值<max(开区间)
     double gSensorStartX;
     double gSensorStartY;
     double gSensorStartZ;
index 487cae4..c2729dd 100644 (file)
@@ -363,7 +363,7 @@ background-color: #F57C00;
            <string/>
           </property>
           <property name="statusTip">
-           <string>供测试用常广播的经典蓝牙设备地址。可为空,为空时,扫描到3个以上设备为通过。</string>
+           <string>填写与日志一致的6 段 MAC(如 1C:1D:2B:68:82:68),非设备名称。程序以当前界面为准,无需先保存配置。留空且未填 RSSI 时:扫到≥3 个设备且最大 RSSI≥-90即通过。</string>
           </property>
           <property name="alignment">
            <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
@@ -399,14 +399,14 @@ background-color: #F57C00;
         <item>
          <widget class="QLabel" name="gsensorDeltaStandardLabel">
           <property name="text">
-           <string>G-sensor XYZ变化标准(10秒,留空表示不校验):</string>
+           <string>G-sensor 瞬时XYZ范围:</string>
           </property>
          </widget>
         </item>
         <item>
          <widget class="QLabel" name="gsensorDeltaXRowLabel">
           <property name="text">
-           <string>ΔX:</string>
+           <string>X:</string>
           </property>
          </widget>
         </item>
@@ -480,7 +480,7 @@ background-color: #F57C00;
         <item>
          <widget class="QLabel" name="gsensorDeltaYRowLabel">
           <property name="text">
-           <string>ΔY:</string>
+           <string>Y:</string>
           </property>
          </widget>
         </item>
@@ -554,7 +554,7 @@ background-color: #F57C00;
         <item>
          <widget class="QLabel" name="gsensorDeltaZRowLabel">
           <property name="text">
-           <string>ΔZ:</string>
+           <string>Z:</string>
           </property>
          </widget>
         </item>