|
@@ -14,6 +14,10 @@ import java.util.TimerTask;
|
|
|
public class WorkTimer {
|
|
public class WorkTimer {
|
|
|
private static final Logger log = LoggerFactory.getLogger(WorkTimer.class);
|
|
private static final Logger log = LoggerFactory.getLogger(WorkTimer.class);
|
|
|
|
|
|
|
|
|
|
+ /** 非 OK 状态需连续确认次数,避免 20→21 等过渡码被立刻判 NG */
|
|
|
|
|
+ private static final int NG_CONFIRM_NEEDED = 2;
|
|
|
|
|
+ private static int ngConfirmCount = 0;
|
|
|
|
|
+ private static int pendingNgStatusCode = -1;
|
|
|
|
|
|
|
|
private static Timer stopTimer = null;
|
|
private static Timer stopTimer = null;
|
|
|
private static Timer workTimer = null;
|
|
private static Timer workTimer = null;
|
|
@@ -25,6 +29,7 @@ public class WorkTimer {
|
|
|
if(workTimer != null){
|
|
if(workTimer != null){
|
|
|
workTimer = null;
|
|
workTimer = null;
|
|
|
}
|
|
}
|
|
|
|
|
+ resetEndConfirm();
|
|
|
workTimer = new Timer();
|
|
workTimer = new Timer();
|
|
|
workTimer.schedule(new WorkTimerTask(), 1000, 2000);
|
|
workTimer.schedule(new WorkTimerTask(), 1000, 2000);
|
|
|
}
|
|
}
|
|
@@ -34,6 +39,13 @@ public class WorkTimer {
|
|
|
workTimer.cancel();
|
|
workTimer.cancel();
|
|
|
workTimer = null;
|
|
workTimer = null;
|
|
|
}
|
|
}
|
|
|
|
|
+ resetEndConfirm();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 扫下一件 / 复位时清空结束确认状态 */
|
|
|
|
|
+ public static void resetEndConfirm() {
|
|
|
|
|
+ ngConfirmCount = 0;
|
|
|
|
|
+ pendingNgStatusCode = -1;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 发送禁止运行的定时任务
|
|
// 发送禁止运行的定时任务
|
|
@@ -61,9 +73,11 @@ public class WorkTimer {
|
|
|
final ATEQ.MeasureResult measureResult = ATEQ.readMeasureResult();
|
|
final ATEQ.MeasureResult measureResult = ATEQ.readMeasureResult();
|
|
|
log.info(measureResult.toString());
|
|
log.info(measureResult.toString());
|
|
|
|
|
|
|
|
|
|
+ // 先在定时线程判定是否真正结束(OK 立刻结束;疑似 NG 需连续确认)
|
|
|
|
|
+ final boolean isEnd = resolveTestEnd(measureResult);
|
|
|
|
|
+
|
|
|
// 测完提交前:若稳压/测试时长为空,再读一次程序参数
|
|
// 测完提交前:若稳压/测试时长为空,再读一次程序参数
|
|
|
- boolean willEnd = !measureResult.isTesting && MesClient.mesStartFlag == 1;
|
|
|
|
|
- if (willEnd) {
|
|
|
|
|
|
|
+ if (isEnd) {
|
|
|
if ((MesClient.curStabilizeTime == null || MesClient.curStabilizeTime.trim().isEmpty())
|
|
if ((MesClient.curStabilizeTime == null || MesClient.curStabilizeTime.trim().isEmpty())
|
|
|
|| (MesClient.curTestDuration == null || MesClient.curTestDuration.trim().isEmpty())) {
|
|
|| (MesClient.curTestDuration == null || MesClient.curTestDuration.trim().isEmpty())) {
|
|
|
log.info("提交前补读稳压时长/测试时长");
|
|
log.info("提交前补读稳压时长/测试时长");
|
|
@@ -75,13 +89,11 @@ public class WorkTimer {
|
|
|
@Override
|
|
@Override
|
|
|
public void run() {
|
|
public void run() {
|
|
|
try {
|
|
try {
|
|
|
- boolean isEnd = false;
|
|
|
|
|
if (measureResult.isTesting) {
|
|
if (measureResult.isTesting) {
|
|
|
- MesClient.mesStartFlag = 1;
|
|
|
|
|
MesClient.setMenuStatus("测试中", 0);
|
|
MesClient.setMenuStatus("测试中", 0);
|
|
|
- } else if (MesClient.mesStartFlag == 1) {
|
|
|
|
|
- // 曾进入测试中,状态变为非00,表示测试结束
|
|
|
|
|
- isEnd = true;
|
|
|
|
|
|
|
+ } else if (MesClient.mesStartFlag == 1 && !isEnd && !measureResult.isPass) {
|
|
|
|
|
+ MesClient.setMenuStatus(
|
|
|
|
|
+ String.format("结果确认中(0x%02X)...", measureResult.statusCode), 0);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
String pressureText = formatValue(measureResult.pressureValue, measureResult.pressureUnit);
|
|
String pressureText = formatValue(measureResult.pressureValue, measureResult.pressureUnit);
|
|
@@ -161,6 +173,45 @@ public class WorkTimer {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 判定测试是否结束:
|
|
|
|
|
+ * - 0x00:测试中
|
|
|
|
|
+ * - 0x21:OK,立即结束
|
|
|
|
|
+ * - 其他非 00:疑似 NG,需连续 {@link #NG_CONFIRM_NEEDED} 次相同状态才结束,
|
|
|
|
|
+ * 期间若变为 0x21 则按 OK 结束,避免过渡码误判
|
|
|
|
|
+ */
|
|
|
|
|
+ private static boolean resolveTestEnd(ATEQ.MeasureResult measureResult) {
|
|
|
|
|
+ if (measureResult.isTesting) {
|
|
|
|
|
+ MesClient.mesStartFlag = 1;
|
|
|
|
|
+ resetEndConfirm();
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (MesClient.mesStartFlag != 1) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (measureResult.isPass) {
|
|
|
|
|
+ log.info("状态码 0x21,判定 OK");
|
|
|
|
|
+ resetEndConfirm();
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 疑似 NG:连续确认
|
|
|
|
|
+ if (pendingNgStatusCode != measureResult.statusCode) {
|
|
|
|
|
+ pendingNgStatusCode = measureResult.statusCode;
|
|
|
|
|
+ ngConfirmCount = 1;
|
|
|
|
|
+ log.info("疑似 NG 状态 0x{},等待确认 {}/{}",
|
|
|
|
|
+ String.format("%02X", measureResult.statusCode), ngConfirmCount, NG_CONFIRM_NEEDED);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ ngConfirmCount++;
|
|
|
|
|
+ log.info("疑似 NG 状态 0x{},确认 {}/{}",
|
|
|
|
|
+ String.format("%02X", measureResult.statusCode), ngConfirmCount, NG_CONFIRM_NEEDED);
|
|
|
|
|
+ if (ngConfirmCount >= NG_CONFIRM_NEEDED) {
|
|
|
|
|
+ resetEndConfirm();
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private static String formatValue(Double value, String unit) {
|
|
private static String formatValue(Double value, String unit) {
|
|
|
if (value == null) {
|
|
if (value == null) {
|
|
|
return "";
|
|
return "";
|