From 8d5b4ec5ec8e4aaa2c34793e3100a7782551afbd Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 12 Jul 2016 17:02:38 +1200 Subject: Fix issue in Hua Sheng frame decoder --- src/org/traccar/protocol/HuaShengFrameDecoder.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/HuaShengFrameDecoder.java b/src/org/traccar/protocol/HuaShengFrameDecoder.java index 5d68fef9e..0e1becc30 100644 --- a/src/org/traccar/protocol/HuaShengFrameDecoder.java +++ b/src/org/traccar/protocol/HuaShengFrameDecoder.java @@ -16,6 +16,7 @@ package org.traccar.protocol; import org.jboss.netty.buffer.ChannelBuffer; +import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.handler.codec.frame.FrameDecoder; @@ -34,7 +35,23 @@ public class HuaShengFrameDecoder extends FrameDecoder { int index = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 0xC0); if (index != -1) { - return buf.readBytes(index + 1 - buf.readerIndex()); + ChannelBuffer result = ChannelBuffers.buffer(index + 1 - buf.readerIndex()); + + while (buf.readerIndex() <= index) { + int b = buf.readUnsignedByte(); + if (b == 0xDB) { + int ext = buf.readUnsignedByte(); + if (ext == 0xDC) { + result.writeByte(0xC0); + } else if (ext == 0xDD) { + result.writeByte(0xDB); + } + } else { + result.writeByte(b); + } + } + + return result; } return null; -- cgit v1.2.3