|
@@ -9,8 +9,10 @@ import com.zd.laboratory.domain.LabHardware;
|
|
|
import com.zd.laboratory.domain.vo.LabHardwareVO;
|
|
import com.zd.laboratory.domain.vo.LabHardwareVO;
|
|
|
import com.zd.laboratory.mapper.LabAbnormalMapper;
|
|
import com.zd.laboratory.mapper.LabAbnormalMapper;
|
|
|
import com.zd.laboratory.mapper.LabHardwareMapper;
|
|
import com.zd.laboratory.mapper.LabHardwareMapper;
|
|
|
|
|
+import com.zd.laboratory.socket.constant.JXCTPacket;
|
|
|
import com.zd.laboratory.socket.constant.SocketTypes;
|
|
import com.zd.laboratory.socket.constant.SocketTypes;
|
|
|
import com.zd.laboratory.socket.runner.TCPServer;
|
|
import com.zd.laboratory.socket.runner.TCPServer;
|
|
|
|
|
+import com.zd.laboratory.socket.service.BaseRouter;
|
|
|
import com.zd.laboratory.utils.CRCCHECK;
|
|
import com.zd.laboratory.utils.CRCCHECK;
|
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
import io.netty.channel.ChannelHandlerContext;
|
|
|
import io.netty.channel.ChannelInboundHandler;
|
|
import io.netty.channel.ChannelInboundHandler;
|
|
@@ -29,20 +31,20 @@ import java.util.concurrent.TimeUnit;
|
|
|
public class NettyServerHandler implements ChannelInboundHandler {
|
|
public class NettyServerHandler implements ChannelInboundHandler {
|
|
|
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
|
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
|
|
|
/**
|
|
/**
|
|
|
- * 读取客户端发送的消息
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ * 读取客户端发送的消息
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
public void channelRead(ChannelHandlerContext channelHandlerContext, Object o) throws Exception {
|
|
public void channelRead(ChannelHandlerContext channelHandlerContext, Object o) throws Exception {
|
|
|
byte[] msg = (byte[]) o;
|
|
byte[] msg = (byte[]) o;
|
|
|
String data = TCPServer.bytesToHexString(msg).toUpperCase();
|
|
String data = TCPServer.bytesToHexString(msg).toUpperCase();
|
|
|
log.info("netty服务端接受消息为:" + data);
|
|
log.info("netty服务端接受消息为:" + data);
|
|
|
- if(data.equals("6862")){
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
- // 采集器规范定义 hex发送 结构 31 11 01 01 后两位递增方式增加
|
|
|
|
|
- String relayCode = data.substring(0, 8);
|
|
|
|
|
|
|
|
|
|
- if(relayCode.startsWith(SocketTypes.SZZQ_PREFIX)){
|
|
|
|
|
|
|
+ if(data.startsWith(SocketTypes.RELAY_PREFIX.replaceAll(" ", "").toUpperCase())){
|
|
|
|
|
+
|
|
|
|
|
+ analyticRelayData(data, channelHandlerContext);
|
|
|
|
|
+ }else if(data.startsWith(SocketTypes.SZZQ_PREFIX)){
|
|
|
|
|
+ // 采集器规范定义 hex发送 结构 31 11 01 01 后两位递增方式增加
|
|
|
|
|
+ String relayCode = data.substring(0, 8);
|
|
|
// 将通道加入ChannelMap
|
|
// 将通道加入ChannelMap
|
|
|
if(relayCode.length() == data.length()){
|
|
if(relayCode.length() == data.length()){
|
|
|
ChannelMap.getChannelMap().put(data, channelHandlerContext);
|
|
ChannelMap.getChannelMap().put(data, channelHandlerContext);
|
|
@@ -66,15 +68,26 @@ public class NettyServerHandler implements ChannelInboundHandler {
|
|
|
redisService.setCacheObject(relayCode + ":" + bit, status, 3 * 60L, TimeUnit.SECONDS);
|
|
redisService.setCacheObject(relayCode + ":" + bit, status, 3 * 60L, TimeUnit.SECONDS);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ private void analyticRelayData(String data, ChannelHandlerContext channelHandlerContext) {
|
|
|
|
|
+ JXCTPacket packet = new JXCTPacket(data);
|
|
|
|
|
+ BaseRouter baseRouter = BaseRouter.routerMap.get(packet.order);
|
|
|
|
|
+ if (baseRouter == null) {
|
|
|
|
|
+ log.info("netty继电器上报不识别指令:" + packet.order);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ log.info("netty继电器状态上报:" + packet.toString());
|
|
|
|
|
+ ChannelMap.getChannelMap().put(packet.deviceNumber, channelHandlerContext);
|
|
|
|
|
+ baseRouter.routePacket(packet);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * @description: 读取消息后开始的操作
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ * @description: 读取消息后开始的操作
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
public void channelReadComplete(ChannelHandlerContext channelHandlerContext) throws Exception {
|
|
public void channelReadComplete(ChannelHandlerContext channelHandlerContext) throws Exception {
|
|
|
|
|
|
|
@@ -93,8 +106,8 @@ public class NettyServerHandler implements ChannelInboundHandler {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * @description: 异常发生时
|
|
|
|
|
- */
|
|
|
|
|
|
|
+ * @description: 异常发生时
|
|
|
|
|
+ */
|
|
|
@Override
|
|
@Override
|
|
|
public void exceptionCaught(ChannelHandlerContext channelHandlerContext, Throwable throwable) throws Exception {
|
|
public void exceptionCaught(ChannelHandlerContext channelHandlerContext, Throwable throwable) throws Exception {
|
|
|
throwable.printStackTrace();
|
|
throwable.printStackTrace();
|