package com.mes.util.ytnetty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class QmCurUtil { public static final Logger log = LoggerFactory.getLogger(QmCurUtil.class); public final String step; // 0=待机 4=充气 1=排气 65535=结束 public final String temperature; // 温度等扩展字段 public final String pressureValue; // 压力值 public final String leakValue; // 泄漏值 public QmCurUtil(String msg) { // 新协议:RS,65535,0,0,4.7,0.0,0.0,0.0,0.0, (整包 hex 实为 ASCII CSV) String ascii = new String(YtUtil.hexStringToByteArray(msg)); if (ascii.indexOf(',') >= 0) { String[] parts = ascii.split(",", -1); this.step = part(parts, 1); this.pressureValue = part(parts, 4); this.leakValue = part(parts, 5); this.temperature = part(parts, 6); return; } // 旧协议:定长二进制字段 this.step = new String(YtUtil.hexStringToByteArray(msg.substring(4, 6))); this.temperature = new String(YtUtil.hexStringToByteArray(msg.substring(36, 42))); this.leakValue = new String(YtUtil.hexStringToByteArray(msg.substring(28, 34))); this.pressureValue = new String(YtUtil.hexStringToByteArray(msg.substring(20, 26))); } private static String part(String[] parts, int index) { if (parts == null || index < 0 || index >= parts.length) { return ""; } return parts[index] == null ? "" : parts[index].trim(); } /** * 开启本轮:仅充气/保压/测试等中间步。 * 不含 0/1/9/65535,避免上一轮结束后设备停在结束态,扫新码被立刻当成新一轮并提交旧结果。 */ public boolean isRunningStep() { return step != null && !step.isEmpty() && !isEndStep(); } /** 读最终结果的结束步(含新协议 65535) */ public boolean isEndStep() { return "65535".equals(step) || "1".equals(step) || "9".equals(step) || "0".equals(step); } @Override public String toString() { return "QmCurUtil{" + "step='" + step + '\'' + ", temperature='" + temperature + '\'' + ", pressureValue='" + pressureValue + '\'' + ", leakValue='" + leakValue + '\'' + '}'; } }