aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/protocol/H02FrameDecoder.java10
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java6
-rw-r--r--test/org/traccar/protocol/H02FrameDecoderTest.java23
3 files changed, 34 insertions, 5 deletions
diff --git a/src/org/traccar/protocol/H02FrameDecoder.java b/src/org/traccar/protocol/H02FrameDecoder.java
index a22252a57..b2da64847 100644
--- a/src/org/traccar/protocol/H02FrameDecoder.java
+++ b/src/org/traccar/protocol/H02FrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2013 - 2017 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@ public class H02FrameDecoder extends FrameDecoder {
char marker = (char) buf.getByte(buf.readerIndex());
- while (marker != '*' && marker != '$' && buf.readableBytes() > 0) {
+ while (marker != '*' && marker != '$' && marker != 'X' && buf.readableBytes() > 0) {
buf.skipBytes(1);
if (buf.readableBytes() > 0) {
marker = (char) buf.getByte(buf.readerIndex());
@@ -66,6 +66,12 @@ public class H02FrameDecoder extends FrameDecoder {
return buf.readBytes(messageLength);
}
+ } else if (marker == 'X') {
+
+ if (buf.readableBytes() >= MESSAGE_SHORT) {
+ return buf.readBytes(MESSAGE_SHORT);
+ }
+
}
return null;
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index 431dd5c3c..c2a3b2b09 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -305,8 +305,6 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
ChannelBuffer buf = (ChannelBuffer) msg;
String marker = buf.toString(0, 1, StandardCharsets.US_ASCII);
- // handle X mode?
-
if (marker.equals("*")) {
String sentence = buf.toString(StandardCharsets.US_ASCII);
if (sentence.contains(",NBR,")) {
@@ -316,6 +314,8 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
}
} else if (marker.equals("$")) {
return decodeBinary(buf, channel, remoteAddress);
+ } else if (marker.equals("X")) {
+ return null; // X mode
}
return null;
diff --git a/test/org/traccar/protocol/H02FrameDecoderTest.java b/test/org/traccar/protocol/H02FrameDecoderTest.java
index 7d54299a5..1505e25ac 100644
--- a/test/org/traccar/protocol/H02FrameDecoderTest.java
+++ b/test/org/traccar/protocol/H02FrameDecoderTest.java
@@ -40,4 +40,27 @@ public class H02FrameDecoderTest extends ProtocolTest {
}
+ @Test
+ public void testDecodeAlternative() throws Exception {
+
+ H02FrameDecoder decoder = new H02FrameDecoder(0);
+
+ Assert.assertEquals(
+ binary("2a48512c343230363131393133302c4e42522c3130323430332c3233382c312c302c372c313131312c323236342c36332c313131312c323236352c35382c313131312c323236362c35302c313131312c333133352c33372c313131312c3630352c33332c313131312c343932302c33302c313131312c3630372c32382c3131303131372c46464646444646462c3623"),
+ decoder.decode(null, null, binary("2a48512c343230363131393133302c4e42522c3130323430332c3233382c312c302c372c313131312c323236342c36332c313131312c323236352c35382c313131312c323236362c35302c313131312c333133352c33372c313131312c3630352c33332c313131312c343932302c33302c313131312c3630372c32382c3131303131372c46464646444646462c3623")));
+
+ Assert.assertEquals(
+ binary("2442061191301024031101175540227006012321670c000095fffffbffff001f00000001f800ee010000000032"),
+ decoder.decode(null, null, binary("2442061191301024031101175540227006012321670c000095fffffbffff001f00000001f800ee010000000032")));
+
+ Assert.assertEquals(
+ binary("5800009814991024031101175540227006012321670c000095fffffbffff0033"),
+ decoder.decode(null, null, binary("5800009814991024031101175540227006012321670c000095fffffbffff0033")));
+
+ Assert.assertEquals(
+ binary("2a48512c343230363131393133302c4e42522c3130323431362c3233382c312c302c372c313131312c323236342c35332c313131312c323236352c36302c313131312c323236362c34342c313131312c333133352c34332c313131312c3630352c33392c313131312c343932302c32392c313131312c3630372c32342c3131303131372c46464646464246462c3623"),
+ decoder.decode(null, null, binary("2a48512c343230363131393133302c4e42522c3130323431362c3233382c312c302c372c313131312c323236342c35332c313131312c323236352c36302c313131312c323236362c34342c313131312c333133352c34332c313131312c3630352c33392c313131312c343932302c32392c313131312c3630372c32342c3131303131372c46464646464246462c3623")));
+
+ }
+
}