|
@@ -1,8 +1,12 @@
|
|
|
package com.hb.proj.gather.protocol;
|
|
|
|
|
|
+import java.util.concurrent.Future;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
+import com.hb.proj.gather.scheduler.TaskFutureCode;
|
|
|
import com.hb.proj.gather.utils.ByteUtils;
|
|
|
import com.hb.proj.gather.utils.Crc16Utils;
|
|
|
|
|
@@ -28,6 +32,24 @@ public class ZLOpdProtHandler extends ChannelInboundHandlerAdapter {
|
|
|
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
|
|
logger.info("有设备连接上:{}",ctx.channel().remoteAddress());
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ //判断通道的状态标记是否为关闭状态(多次发指令未响应,主动关闭)
|
|
|
+ private boolean isChannelCloseTag(String serial) {
|
|
|
+ Integer futureRst=TaskFutureCode.SUCCESS;
|
|
|
+ try {
|
|
|
+ Future<Integer> chnTskFuture=ChannelGroupMgr.getFuture(serial);
|
|
|
+ if(chnTskFuture!=null && !chnTskFuture.isCancelled()) {
|
|
|
+ futureRst=chnTskFuture.get(1, TimeUnit.SECONDS);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception e) {
|
|
|
+ logger.error("获取通道{}状态标志出错:{}",serial,e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return futureRst!=null && futureRst==TaskFutureCode.CLOSED;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -68,6 +90,13 @@ public class ZLOpdProtHandler extends ChannelInboundHandlerAdapter {
|
|
|
|
|
|
logger.info("收到心跳:{}",hexmsg);
|
|
|
|
|
|
+ if(isChannelCloseTag(serial)) {
|
|
|
+ logger.info("通道{}被标记为关闭,但还收到心跳,准备强制关闭,并移除标记",serial);
|
|
|
+ ChannelGroupMgr.resetChannel(serial);
|
|
|
+ ctx.channel().unsafe().closeForcibly();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
else if(byteCount>2 && isWriteBackMsg){ //(动液面设备设置指令返回消息不规范(按原指令返回),不做crc校验)
|
|
|
if(!ByteUtils.isValidWriteBackMsg(cmd)) { //针对部分设备在电流图,电功率图采集时非正常返回处理(两次返回,第1次,返回原指令(去掉了地址号),第2次才正常返回)
|