Przeglądaj źródła

manhole报文判断修复

zengy 2 tygodni temu
rodzic
commit
2ba0d0426f

+ 1 - 1
manhole-service/src/main/java/com/zksy/manhole/config/NettyServerThread.java

@@ -85,7 +85,7 @@ public class NettyServerThread {
 	}
 
     public void configurePipeline(io.netty.channel.ChannelPipeline pipeline, EventExecutorGroup business) {
-				pipeline.addLast(new ReadTimeoutHandler(10));// 超时时间,10s内没有从通道(Channel)读取到任何数据
+				pipeline.addLast(new ReadTimeoutHandler(3600));// 1小时内没有从通道(Channel)读取到任何数据则断开
 				pipeline.addLast(new DeviceFrameDecoder(DeviceFrameDecoder.Protocol.MANHOLE));
 				pipeline.addLast(business, messageHandler);
     }

+ 2 - 2
manhole-service/src/main/java/com/zksy/manhole/utils/MessageHandler.java

@@ -46,8 +46,8 @@ public class MessageHandler extends ChannelInboundHandlerAdapter {
 			logger.info("接收到 {} 字节的数据,来自: {}", msgByteBuf.readableBytes(), ctx.channel().remoteAddress());
 			byte[] msgBytes = new byte[msgByteBuf.readableBytes()];
 			msgByteBuf.readBytes(msgBytes);
-			if (msgBytes.length != 72) {
-				throw new InvalidMessageException("井盖报文长度应为72字节");
+			if (msgBytes.length != 74) {
+				throw new InvalidMessageException("井盖报文长度应为74字节");
 			}
 			String result = printHexBinary(msgBytes);
 			String msgString = result.replaceAll("\\s", "");

+ 3 - 3
zk-common/src/main/java/com/zksy/common/netty/DeviceFrameDecoder.java

@@ -34,9 +34,9 @@ public final class DeviceFrameDecoder extends ByteToMessageDecoder {
                 for (int i = 0; i < length; i++) xor ^= in.getUnsignedByte(start + i);
                 if (xor != 0) { in.skipBytes(1); continue; }
             } else if (protocol == Protocol.MANHOLE) {
-                // 当前井盖解析器:35字节参数 + 20字节SIM + 15字节IMEI + CRC16。
-                length = 72;
-                if (crc(in, start, 70) != in.getUnsignedShortLE(start + 70)) { in.skipBytes(1); continue; }
+                // 井盖帧:前72字节参与CRC16,最后2字节为小端CRC,整帧74字节。
+                length = 74;
+                if (crc(in, start, 72) != in.getUnsignedShortLE(start + 72)) { in.skipBytes(1); continue; }
             } else if (protocol == Protocol.GAS) {
                 // 协议:7E + 2 字节长度(帧类型→校验07)+ 数据 + 校验07 + 校验16,总长 = 长度字段 + 4。
                 // 数据项数量随设备上报内容变化(5 项无经纬度、7 项含经纬度),帧长不能写死。