mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 03:25:12 +08:00
update 电单车协议
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user