update 电单车协议

This commit is contained in:
Guoqs
2024-09-18 11:41:26 +08:00
parent d0332d5fd0
commit cd4973a183
36 changed files with 702 additions and 1619 deletions

View File

@@ -1,28 +0,0 @@
package com.jsowell.netty.decoder;
import com.jsowell.pile.domain.ebike.AbsEBikeMessage;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
@Slf4j
public class MessageDecode extends ByteToMessageDecoder {
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
// 检查是否有足够的字节可以读取
if (in.readableBytes() < 14) { // 最小长度包头3 + 长度2 + 物理ID4 + 消息ID2 + 命令1 + 校验2
return;
}
// 读取所有可读字节
byte[] bytes = new byte[in.readableBytes()];
in.readBytes(bytes);
// 解析字节数组
AbsEBikeMessage message = AbsEBikeMessage.parseMessage(bytes);
out.add(message);
}
}

View File

@@ -129,6 +129,8 @@ public class StartAndLengthFieldFrameDecoder extends ByteToMessageDecoder {
// 读取 data 数据
ByteBuf frame = buffer.retainedSlice(beginReader, HEADER_LENGTH_DNY + length + 2);
buffer.readerIndex(beginReader + HEADER_LENGTH_DNY + length + 2);
out.add(frame);
}