mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
update
This commit is contained in:
@@ -66,34 +66,37 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
|
||||
* 有客户端发消息会触发此函数
|
||||
*/
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
public void channelRead(ChannelHandlerContext ctx, Object message) throws Exception {
|
||||
// log.info("加载客户端报文=== channelId:" + ctx.channel().id() + ", msg:" + msg);
|
||||
// 下面可以解析数据,保存数据,生成返回报文,将需要返回报文写入write函数
|
||||
byte[] arr = (byte[]) msg;
|
||||
byte[] msg = (byte[]) message;
|
||||
|
||||
// 获取帧类型
|
||||
String frameType = YKCUtils.frameType2Str(BytesUtil.copyBytes(arr, 5, 1));
|
||||
String frameType = YKCUtils.frameType2Str(BytesUtil.copyBytes(msg, 5, 1));
|
||||
// 获取序列号域
|
||||
int serialNumber = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(arr, 2, 2));
|
||||
int serialNumber = BytesUtil.bytesToIntLittle(BytesUtil.copyBytes(msg, 2, 2));
|
||||
// 获取channel
|
||||
Channel channel = ctx.channel();
|
||||
|
||||
// new
|
||||
String hexString = DatatypeConverter.printHexBinary(arr);
|
||||
String hexString = DatatypeConverter.printHexBinary(msg);
|
||||
|
||||
// 心跳包0x03日志太多,造成日志文件过大,改为不打印
|
||||
if (!CollectionUtils.containsAny(notPrintFrameTypeList, frameType)) {
|
||||
log.info("【<<<<<平台收到消息<<<<<】channel:{}, 帧类型:{}, 帧名称:{}, 序列号域:{}, 报文:{}, new报文:{}",
|
||||
ctx.channel().id(), frameType, YKCFrameTypeCode.getFrameTypeStr(frameType), serialNumber,
|
||||
BytesUtil.binary(arr, 16), hexString);
|
||||
channel.id(), frameType, YKCFrameTypeCode.getFrameTypeStr(frameType), serialNumber,
|
||||
BytesUtil.binary(msg, 16), hexString);
|
||||
}
|
||||
|
||||
// 处理数据
|
||||
byte[] response = ykcService.process(arr, ctx.channel());
|
||||
byte[] response = ykcService.process(msg, channel);
|
||||
if (Objects.nonNull(response)) {
|
||||
// 响应客户端
|
||||
ByteBuf buffer = ctx.alloc().buffer().writeBytes(response);
|
||||
this.channelWrite(ctx.channel().id(), buffer);
|
||||
this.channelWrite(channel.id(), buffer);
|
||||
if (!CollectionUtils.containsAny(notPrintFrameTypeList, frameType)) {
|
||||
log.info("【>>>>>平台响应消息>>>>>】channel:{}, 帧类型:{}, 帧名称:{}, 序列号域:{}, response:{}",
|
||||
ctx.channel().id(), frameType, YKCFrameTypeCode.getFrameTypeStr(frameType), serialNumber,
|
||||
channel.id(), frameType, YKCFrameTypeCode.getFrameTypeStr(frameType), serialNumber,
|
||||
BytesUtil.binary(response, 16));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user