diff --git a/src/main/java/com/zhgd/netty/tcp/handler/TcpNettyHandler.java b/src/main/java/com/zhgd/netty/tcp/handler/TcpNettyHandler.java index 940944c0b..fff432cb5 100644 --- a/src/main/java/com/zhgd/netty/tcp/handler/TcpNettyHandler.java +++ b/src/main/java/com/zhgd/netty/tcp/handler/TcpNettyHandler.java @@ -31,35 +31,32 @@ public class TcpNettyHandler extends SimpleChannelInboundHandler { @Override public void channelRead0(ChannelHandlerContext ctx, Object msg) { byte[] bytes = readBytes(msg); - //字符串判断 String str = getString(bytes); str = str.trim(); - log.info("channelRead0 str >>> \r\n {} ", str); + log.info("tcp接收数据 >>> {} ", str); if (StringUtils.startsWith(str, HighFormworkSupport.TCP_DATA_PREFIX) && StringUtils.endsWith(str, HighFormworkSupport.TCP_DATA_END)) { + log.info("高支模接收数据 >>> {} ", str); //接收高支模数据保存到mysql中 try { highFormworkSupportService.saveTcpData(str); } catch (Exception e) { - log.error("error:接收高支模数据保存到mysql中exception: >>> \r\n ", e); + log.error("error:接收高支模数据保存到mysql中exception: >>> ", e); } finally { highFormworkSupportResponseOk(ctx); } - return; - } - //有毒气体 - if (StringUtils.startsWith(str, "##")) { + } else if (StringUtils.startsWith(str, "##")) { + log.info("有毒气体接收数据 >>> {} ", str); + //有毒气体 poisonousGasDevCurrentDataService.addDataFromTcpFor212Protocol(str); - return; - } - - //16进制判断 - String hexString = readToHexString(bytes); - log.info("channelRead0 hexString >>> \r\n {} ", hexString); - if (StringUtils.startsWith(hexString, "7E")) { - //有害气体 - poisonousGasDevCurrentDataService.addDataFromTcp(hexString.trim()); - return; + } else { + //16进制判断 + String hexString = readToHexString(bytes); + log.info("tcp接收数据(16进制转字符串) >>> {} ", hexString); + if (StringUtils.startsWith(hexString, "7E")) { + //有害气体 + poisonousGasDevCurrentDataService.addDataFromTcp(hexString.trim()); + } } }