diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/decoder/MessageDecode.java b/jsowell-netty/src/main/java/com/jsowell/netty/decoder/MessageDecode.java index 331d4143d..8afde12bb 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/decoder/MessageDecode.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/decoder/MessageDecode.java @@ -1,6 +1,5 @@ package com.jsowell.netty.decoder; -import com.alibaba.fastjson2.JSON; import com.jsowell.netty.domain.ChargingPileMessage; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; @@ -13,7 +12,6 @@ import java.util.List; public class MessageDecode extends ByteToMessageDecoder { @Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { - // log.info("MessageDecode.decode"); // 检查是否有足够的字节可以读取 if (in.readableBytes() < 14) { // 最小长度(包头3 + 长度2 + 物理ID4 + 消息ID2 + 命令1 + 校验2) return; @@ -27,51 +25,4 @@ public class MessageDecode extends ByteToMessageDecoder { ChargingPileMessage message = ChargingPileMessage.parseMessage(bytes); out.add(message); } - - - // @Override - // protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { - // // 检查是否至少有最小长度的字节可以读取 - // if (in.readableBytes() < 14) { // 最小长度(包头3 + 长度2 + 物理ID4 + 消息ID2 + 命令1 + 校验2) - // return; - // } - // - // // 标记读指针位置 - // in.markReaderIndex(); - // - // // 读取包头 - // byte[] headerBytes = new byte[3]; - // in.readBytes(headerBytes); - // String header = new String(headerBytes); - // - // // 读取长度 - // int length = in.readUnsignedShort(); - // - // // 检查剩余字节数是否足够读取整个包 - // if (in.readableBytes() < length - 5) { // 减去包头和长度本身占的字节数 - // in.resetReaderIndex(); - // return; - // } - // - // // 读取物理ID - // int physicalId = in.readInt(); - // - // // 读取消息ID - // int messageId = in.readUnsignedShort(); - // - // // 读取命令 - // byte command = in.readByte(); - // - // // 读取数据 - // byte[] data = new byte[length - 12]; // 减去固定字段的字节数 - // in.readBytes(data); - // - // // 读取校验 - // int checksum = in.readUnsignedShort(); - // - // // 创建ChargingPileMessage对象并添加到输出列表 - // ChargingPileMessage message = new ChargingPileMessage(header, length, physicalId, messageId, command, data, checksum); - // out.add(message); - // } - } \ No newline at end of file diff --git a/jsowell-netty/src/main/java/com/jsowell/netty/domain/ChargingPileMessage.java b/jsowell-netty/src/main/java/com/jsowell/netty/domain/ChargingPileMessage.java index d4080f199..87cc63171 100644 --- a/jsowell-netty/src/main/java/com/jsowell/netty/domain/ChargingPileMessage.java +++ b/jsowell-netty/src/main/java/com/jsowell/netty/domain/ChargingPileMessage.java @@ -22,7 +22,7 @@ public class ChargingPileMessage { private int length; // 长度 (2字节) private int physicalId; // 物理ID (4字节) private int messageId; // 消息ID (2字节) - private byte command; // 命令 (1字节) + private String command; // 命令 (1字节) private byte[] data; // 数据 (n字节) private int checksum; // 校验 (2字节) @@ -69,7 +69,7 @@ public class ChargingPileMessage { // 读取命令 byte command = messageBytes[11]; - message.setChecksum(command); + message.setCommand(BytesUtil.bcd2StrLittle(new byte[] {command})); // System.out.println("命令:" + BytesUtil.bcd2StrLittle(new byte[] {command})); // 读取数据 diff --git a/jsowell-ui/public/index.html b/jsowell-ui/public/index.html index 25bcdb197..9b180afdf 100644 --- a/jsowell-ui/public/index.html +++ b/jsowell-ui/public/index.html @@ -11,6 +11,7 @@ <%= webpackConfig.name %> +