aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-11-22 22:46:13 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2017-11-22 22:46:13 +1300
commit6c0fe165f72a998d447d0983c94e234681a6b680 (patch)
tree73a951e7743aa43d79531511b96011e1b4946ec8
parent43ffaf8c3bb0c4937f8d9185f47a95530d118931 (diff)
downloadtraccar-server-6c0fe165f72a998d447d0983c94e234681a6b680.tar.gz
traccar-server-6c0fe165f72a998d447d0983c94e234681a6b680.tar.bz2
traccar-server-6c0fe165f72a998d447d0983c94e234681a6b680.zip
Fix JT600 frame decoder
-rw-r--r--src/org/traccar/protocol/Jt600FrameDecoder.java4
-rw-r--r--test/org/traccar/protocol/Jt600FrameDecoderTest.java14
2 files changed, 11 insertions, 7 deletions
diff --git a/src/org/traccar/protocol/Jt600FrameDecoder.java b/src/org/traccar/protocol/Jt600FrameDecoder.java
index 5606ae1fc..261f46fe8 100644
--- a/src/org/traccar/protocol/Jt600FrameDecoder.java
+++ b/src/org/traccar/protocol/Jt600FrameDecoder.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.
@@ -37,7 +37,7 @@ public class Jt600FrameDecoder extends FrameDecoder {
if (type == '$') {
boolean longFormat = buf.getUnsignedByte(buf.readerIndex() + 1) == 0x75;
int length = buf.getUnsignedShort(buf.readerIndex() + (longFormat ? 8 : 7)) + 10;
- if (length >= buf.readableBytes()) {
+ if (length <= buf.readableBytes()) {
return buf.readBytes(length);
}
} else if (type == '(') {
diff --git a/test/org/traccar/protocol/Jt600FrameDecoderTest.java b/test/org/traccar/protocol/Jt600FrameDecoderTest.java
index afa53ba13..15e6ec18c 100644
--- a/test/org/traccar/protocol/Jt600FrameDecoderTest.java
+++ b/test/org/traccar/protocol/Jt600FrameDecoderTest.java
@@ -11,23 +11,27 @@ public class Jt600FrameDecoderTest extends ProtocolTest {
Jt600FrameDecoder decoder = new Jt600FrameDecoder();
- Assert.assertEquals(
+ verifyFrame(
+ binary("24315011626912001b21111718095900000000000000000e0000005c000000000000000000"),
+ decoder.decode(null, null, binary("24315011626912001b21111718095900000000000000000e0000005c00000000000000000024315011626912001b22111708130400000000000000000e0000005a00000000000000000024315011626912001b22111708140400000000000000000e0000005a000000723e18a61b01")));
+
+ verifyFrame(
binary("2475604055531611002311111600311326144436028210791d016c0000001f070000000020c03c4f6d07d80ccf"),
decoder.decode(null, null, binary("2475604055531611002311111600311326144436028210791d016c0000001f070000000020c03c4f6d07d80ccf")));
- Assert.assertEquals(
+ verifyFrame(
binary("2475605035891613002328091601152806086750106533350c00000000000a000000000000e1ff4f97007f1607"),
decoder.decode(null, null, binary("2475605035891613002328091601152806086750106533350c00000000000a000000000000e1ff4f97007f1607")));
- Assert.assertEquals(
+ verifyFrame(
binary("28333132303832303032392C5730312C30323535332E333535352C452C323433382E303939372C532C412C3137313031322C3035333333392C302C382C32302C362C33312C352C32302C323029"),
decoder.decode(null, null, binary("28333132303832303032392C5730312C30323535332E333535352C452C323433382E303939372C532C412C3137313031322C3035333333392C302C382C32302C362C33312C352C32302C323029")));
- Assert.assertEquals(
+ verifyFrame(
binary("24312082002911001B171012053405243809970255335555000406140003EE2B91044D1F02"),
decoder.decode(null, null, binary("24312082002911001B171012053405243809970255335555000406140003EE2B91044D1F02")));
- Assert.assertEquals(
+ verifyFrame(
binary("28373536303430353535332c404a5429"),
decoder.decode(null, null, binary("28373536303430353535332c404a5429")));