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) {
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()) {
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));
}
}
}
});
}
-// 结束G-sensor判定:要求每条采样都在阈值范围内
+// 结束G-sensor判定:每条采样的瞬时 X/Y/Z 对已配置边界满足严格开区间 min < 值 < max
void MainWindow::finalizeGsensorTest()
{
if (!isProductionTestRunning || currentTestStep != TEST_GSENSOR) {
}
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);
}
}
}
+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()
{
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) {
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;
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;