update 电单车协议

This commit is contained in:
Guoqs
2024-08-14 15:37:41 +08:00
parent 93cd197cb3
commit b517ffe496
2 changed files with 1 additions and 49 deletions

View File

@@ -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<Object> 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<Object> 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);
// }
}

View File

@@ -128,6 +128,7 @@ public class StartAndLengthFieldFrameDecoder extends ByteToMessageDecoder {
// 读取 data 数据
ByteBuf frame = buffer.retainedSlice(beginReader, HEADER_LENGTH_DNY + length + 2);
buffer.readerIndex(beginReader + HEADER_LENGTH_DNY + length + 2);
log.info("decodeDnyMessage:{}", frame.toString());
out.add(frame);
}