aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-03-05 09:46:51 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-03-05 09:46:51 +1300
commit3c0d6bc88adc702fac35ef4f5c3a42e1b435f603 (patch)
tree10644bd6d0b2adccc980ff69e7ea12b5972c5962
parent4aaf5526f676b810b919737f081796614f93faf9 (diff)
downloadtrackermap-server-3c0d6bc88adc702fac35ef4f5c3a42e1b435f603.tar.gz
trackermap-server-3c0d6bc88adc702fac35ef4f5c3a42e1b435f603.tar.bz2
trackermap-server-3c0d6bc88adc702fac35ef4f5c3a42e1b435f603.zip
Improve Atrack decoder
-rw-r--r--src/org/traccar/protocol/AtrackProtocolDecoder.java4
-rw-r--r--test/org/traccar/protocol/AtrackProtocolDecoderTest.java3
2 files changed, 6 insertions, 1 deletions
diff --git a/src/org/traccar/protocol/AtrackProtocolDecoder.java b/src/org/traccar/protocol/AtrackProtocolDecoder.java
index 1323ce8a3..607b3e558 100644
--- a/src/org/traccar/protocol/AtrackProtocolDecoder.java
+++ b/src/org/traccar/protocol/AtrackProtocolDecoder.java
@@ -42,6 +42,8 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
private static final int MSG_HEARTBEAT = 0x1A;
private static final int MSG_DATA = 0x10;
+ private static final int MIN_DATA_LENGTH = 40;
+
private static void sendResponse(Channel channel, SocketAddress remoteAddress, long rawId, int index) {
if (channel != null) {
ChannelBuffer response = ChannelBuffers.directBuffer(12);
@@ -104,7 +106,7 @@ public class AtrackProtocolDecoder extends BaseProtocolDecoder {
List<Position> positions = new LinkedList<Position>();
- while (buf.readable()) {
+ while (buf.readableBytes() >= MIN_DATA_LENGTH) {
// Create new position
Position position = new Position();
diff --git a/test/org/traccar/protocol/AtrackProtocolDecoderTest.java b/test/org/traccar/protocol/AtrackProtocolDecoderTest.java
index c06845df7..043c843c0 100644
--- a/test/org/traccar/protocol/AtrackProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/AtrackProtocolDecoderTest.java
@@ -23,6 +23,9 @@ public class AtrackProtocolDecoderTest {
verify(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
"40501e58003301e000014104d8f19682525ecd5d525ee344525ee35effc88815026ab4d70000020000104403de01000b0000000007d007d000"))));
+ verify(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
+ "40501e58003301e000014104d8f19682525ecd5d525ee344525ee35effc88815026ab4d70000020000104403de01000b0000000007d007d000000000000000"))));
+
// 7-byte date
//verify(decoder.decode(null, null, null, ChannelBuffers.wrappedBuffer(ChannelBufferTools.convertHexString(
// "0203b494003c00eb00014104d8dd3a3e07de011b0b1f0307de011b0b1f0307de011b0b1f0300307f28030574d30000020000000600160100020000000007d007d000"))));