aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-10-26 12:11:58 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-10-26 12:11:58 +1300
commitefa23587b3ca8ea0c08e418a4c445cfa0062f110 (patch)
tree28f27abda4574ee07c1db4ef7449218a78de5497
parent39650cf5e3fa32f767dac5ce0ee066e8e4906945 (diff)
downloadtraccar-server-efa23587b3ca8ea0c08e418a4c445cfa0062f110.tar.gz
traccar-server-efa23587b3ca8ea0c08e418a4c445cfa0062f110.tar.bz2
traccar-server-efa23587b3ca8ea0c08e418a4c445cfa0062f110.zip
Modify Meitrack frame decoder
-rw-r--r--src/org/traccar/protocol/MeitrackFrameDecoder.java8
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolDecoder.java2
-rw-r--r--test/org/traccar/protocol/MeitrackFrameDecoderTest.java22
3 files changed, 26 insertions, 6 deletions
diff --git a/src/org/traccar/protocol/MeitrackFrameDecoder.java b/src/org/traccar/protocol/MeitrackFrameDecoder.java
index e96359104..e34116fa4 100644
--- a/src/org/traccar/protocol/MeitrackFrameDecoder.java
+++ b/src/org/traccar/protocol/MeitrackFrameDecoder.java
@@ -26,16 +26,14 @@ public class MeitrackFrameDecoder extends FrameDecoder {
@Override
protected Object decode(
- ChannelHandlerContext ctx,
- Channel channel,
- ChannelBuffer buf) throws Exception {
+ ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {
if (buf.readableBytes() < 10) {
return null;
}
- Integer index = ChannelBufferTools.find(buf, buf.readerIndex(), buf.writerIndex(), ",");
- if (index != null) {
+ int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
+ if (index != -1) {
int length = index - buf.readerIndex() + Integer.parseInt(
buf.toString(buf.readerIndex() + 3, index - buf.readerIndex() - 3, Charset.defaultCharset()));
if (buf.readableBytes() >= length) {
diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
index f8eb6ed91..3aae0542b 100644
--- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java
@@ -267,7 +267,7 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder {
ChannelBuffer buf = (ChannelBuffer) msg;
// Find type
- Integer index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
+ int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ',');
index = buf.indexOf(index + 1, buf.writerIndex(), (byte) ',');
String type = buf.toString(index + 1, 3, Charset.defaultCharset());
diff --git a/test/org/traccar/protocol/MeitrackFrameDecoderTest.java b/test/org/traccar/protocol/MeitrackFrameDecoderTest.java
new file mode 100644
index 000000000..29d1b6148
--- /dev/null
+++ b/test/org/traccar/protocol/MeitrackFrameDecoderTest.java
@@ -0,0 +1,22 @@
+package org.traccar.protocol;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.junit.Assert;
+import org.junit.Test;
+import org.traccar.ProtocolDecoderTest;
+
+public class MeitrackFrameDecoderTest extends ProtocolDecoderTest {
+
+ @Test
+ public void testDecode() throws Exception {
+
+ MeitrackFrameDecoder decoder = new MeitrackFrameDecoder();
+
+ Assert.assertEquals(
+ binary("24244e3132372c3836333037313031333830333036362c4141412c33352c2d312e3330323638302c33362e3835323133352c3135303430393231313032362c412c392c302c302e312c302c352c313635332c343039362c33323634382c3633397c30327c313030347c3930432c303030302c307c307c307c3346467c3330302c2a37430d0a"),
+ decoder.decode(null, null, binary("24244e3132372c3836333037313031333830333036362c4141412c33352c2d312e3330323638302c33362e3835323133352c3135303430393231313032362c412c392c302c302e312c302c352c313635332c343039362c33323634382c3633397c30327c313030347c3930432c303030302c307c307c307c3346467c3330302c2a37430d0a")));
+
+ }
+
+}