tcp打印日志修改

This commit is contained in:
guoshengxiong 2024-05-22 15:47:05 +08:00
parent d7a3343e7d
commit 03c7733fae

View File

@ -31,35 +31,32 @@ public class TcpNettyHandler extends SimpleChannelInboundHandler<Object> {
@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());
}
}
}