|
|
|
@ -55,6 +55,9 @@ public class DeviceRunner implements CommandLineRunner { |
|
|
|
private ResourceDao resourceDao; |
|
|
|
|
|
|
|
private static final long CHECK_INTERVAL = 2000;// 毫秒 |
|
|
|
private static final long MIN_SMALL_CUT_INTERVAL_NANOS = TimeUnit.SECONDS.toNanos(15); |
|
|
|
// 按设备记录最近一次接受的小卷分切信号时间,使用单调时钟计算间隔。 |
|
|
|
private final Map<String, Long> lastSmallCutSignalTimes = new HashMap<>(); |
|
|
|
|
|
|
|
@Override |
|
|
|
public void run(String... args) throws Exception { |
|
|
|
@ -288,6 +291,28 @@ public class DeviceRunner implements CommandLineRunner { |
|
|
|
Integer smallCutSignal = collectUtil.readHoldingRegister(ip, port, smallCutSignalAddr); |
|
|
|
logger.info("小卷分切信号:{}", smallCutSignal); |
|
|
|
|
|
|
|
if (Objects.equals(smallCutSignal, 1)) { |
|
|
|
String deviceKey = ip + ":" + port; |
|
|
|
long elapsedNanos = Long.MAX_VALUE; |
|
|
|
synchronized (lastSmallCutSignalTimes) { |
|
|
|
long now = System.nanoTime(); |
|
|
|
Long lastSignalTime = lastSmallCutSignalTimes.get(deviceKey); |
|
|
|
if (lastSignalTime != null) { |
|
|
|
elapsedNanos = now - lastSignalTime; |
|
|
|
} |
|
|
|
if (elapsedNanos >= MIN_SMALL_CUT_INTERVAL_NANOS) { |
|
|
|
lastSmallCutSignalTimes.put(deviceKey, now); |
|
|
|
} |
|
|
|
} |
|
|
|
if (elapsedNanos < MIN_SMALL_CUT_INTERVAL_NANOS) { |
|
|
|
// 重复信号仍需清零,避免留到时间窗口结束后再次录入。 |
|
|
|
collectUtil.writeHoldingRegister(ip, port, smallCutSignalAddr, 0); |
|
|
|
logger.info("设备{}小卷分切信号距上次接受信号仅{}毫秒,小于15秒,已清零并跳过处理", |
|
|
|
deviceKey, TimeUnit.NANOSECONDS.toMillis(elapsedNanos)); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 如果获取到小卷分切信号为 1,则读取寄存器地址 199 和 200 的值(32位浮点数,低字在前) |
|
|
|
Integer lowWord = null; // 寄存器201:低16位 |
|
|
|
Integer highWord = null; // 寄存器200:高16位 |
|
|
|
|