From: xue <2144439972@qq.com> Date: Sat, 11 Apr 2026 02:25:51 +0000 (+0800) Subject: 1.优化.gsensor门限判断,超限时打印具体不匹配数据 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=4fed61632e4a23e1b3d50833641c1457ab8631c6;p=mirrors%2Ffactory_tool.git 1.优化.gsensor门限判断,超限时打印具体不匹配数据 2.优化广播蓝牙保存机制,直接判断文本框里的广播蓝牙 --- diff --git a/mainwindow.cpp b/mainwindow.cpp index 4239790..27f475c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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= yx) { + ui->recvTextEdit->append(QString(">>> G-sensor参数警告: Y 的 min(%1) ≥ max(%2),不存在满足 min= zx) { + ui->recvTextEdit->append(QString(">>> G-sensor参数警告: Z 的 min(%1) ≥ max(%2),不存在满足 min 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秒内所有XYZ采样均在阈值范围", 3000); + ui->statusbar->showMessage("G-sensor测试通过:10秒内各采样瞬时XYZ均满足已配置开区间", 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; diff --git a/mainwindow.h b/mainwindow.h index cc16ffa..20185bb 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -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<值 - 供测试用常广播的经典蓝牙设备地址。可为空,为空时,扫描到3个以上设备为通过。 + 填写与日志一致的6 段 MAC(如 1C:1D:2B:68:82:68),非设备名称。程序以当前界面为准,无需先保存配置。留空且未填 RSSI 时:扫到≥3 个设备且最大 RSSI≥-90即通过。 Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter @@ -399,14 +399,14 @@ background-color: #F57C00; - G-sensor XYZ变化标准(10秒,留空表示不校验): + G-sensor 瞬时XYZ范围: - ΔX: + X: @@ -480,7 +480,7 @@ background-color: #F57C00; - ΔY: + Y: @@ -554,7 +554,7 @@ background-color: #F57C00; - ΔZ: + Z: