aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-07-12 17:02:38 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2016-07-12 17:02:38 +1200
commit8d5b4ec5ec8e4aaa2c34793e3100a7782551afbd (patch)
treee9beaee9f915d936e3d05c43bef2f2f6be46c6ab
parent781f4b0a01dd8b16892b0bb907d43f9e0ca6f2ba (diff)
downloadtrackermap-server-8d5b4ec5ec8e4aaa2c34793e3100a7782551afbd.tar.gz
trackermap-server-8d5b4ec5ec8e4aaa2c34793e3100a7782551afbd.tar.bz2
trackermap-server-8d5b4ec5ec8e4aaa2c34793e3100a7782551afbd.zip
Fix issue in Hua Sheng frame decoder
-rw-r--r--src/org/traccar/protocol/HuaShengFrameDecoder.java19
-rw-r--r--test/org/traccar/protocol/HuaShengFrameDecoderTest.java8
2 files changed, 26 insertions, 1 deletions
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;
diff --git a/test/org/traccar/protocol/HuaShengFrameDecoderTest.java b/test/org/traccar/protocol/HuaShengFrameDecoderTest.java
index 56b8f210c..c3f5c585f 100644
--- a/test/org/traccar/protocol/HuaShengFrameDecoderTest.java
+++ b/test/org/traccar/protocol/HuaShengFrameDecoderTest.java
@@ -19,6 +19,14 @@ public class HuaShengFrameDecoderTest extends ProtocolTest {
binary("c0010c003e0002000000000010020012a0014f42445f3347315f56312e302e330013a0043335353835353035303434303635380006a08701000006a0a1035fc0"),
decoder.decode(null, null, binary("c0010c003e0002000000000010020012a0014f42445f3347315f56312e302e330013a0043335353835353035303434303635380006a08701000006a0a1035fc0")));
+ Assert.assertEquals(
+ binary("c00000003faa0000000000003ea5a5005a3f00c000000031363037303530373132353700e6d186ffcc7a25002201160010000000010015000000000000000000c0"),
+ decoder.decode(null, null, binary("c00000003faa0000000000003ea5a5005a3f00dbdc00000031363037303530373132353700e6d186ffcc7a25002201160010000000010015000000000000000000c0")));
+
+ Assert.assertEquals(
+ binary("C000000041AA00000000000030C000000031353035323630373538323800ADDCC100226AEF0000000000120005000100151206EF0504E99975002903EB80556492CEC0"),
+ decoder.decode(null, null, binary("C000000041AA00000000000030DBDC00000031353035323630373538323800ADDCC100226AEF0000000000120005000100151206EF0504E99975002903EB80556492CEC0")));
+
}
}