From 165a6c76e8127bae7bdf16a9e9a4a24247f1dec4 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 8 Mar 2024 21:26:09 -0800 Subject: Fix Huabao frame encoder --- .../org/traccar/protocol/HuabaoFrameEncoder.java | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/protocol/HuabaoFrameEncoder.java b/src/main/java/org/traccar/protocol/HuabaoFrameEncoder.java index 808529a98..5e48a466a 100644 --- a/src/main/java/org/traccar/protocol/HuabaoFrameEncoder.java +++ b/src/main/java/org/traccar/protocol/HuabaoFrameEncoder.java @@ -24,20 +24,18 @@ public class HuabaoFrameEncoder extends MessageToByteEncoder { @Override protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) { + int startIndex = msg.readerIndex(); while (msg.isReadable()) { + int index = msg.readerIndex(); int b = msg.readUnsignedByte(); - switch (b) { - case 0x7d: - out.writeByte(0x7d); - out.writeByte(0x01); - break; - case 0x7e: - out.writeByte(0x7d); - out.writeByte(0x02); - break; - default: - out.writeByte(b); - break; + if (b == 0x7d) { + out.writeByte(0x7d); + out.writeByte(0x01); + } else if (b == 0x7e && index != startIndex && msg.isReadable()) { + out.writeByte(0x7d); + out.writeByte(0x02); + } else { + out.writeByte(b); } } } -- cgit v1.2.3