diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-01-21 22:19:20 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-01-21 22:19:20 +1300 |
commit | fc0a26137fbd00339fcbf28b10b2afae6242d094 (patch) | |
tree | 33b8764b40a55af68a2d52bd81b35cf48a56731a | |
parent | 39de5581b92a505a19cf1929a52bc562c48c3e2f (diff) | |
download | trackermap-server-fc0a26137fbd00339fcbf28b10b2afae6242d094.tar.gz trackermap-server-fc0a26137fbd00339fcbf28b10b2afae6242d094.tar.bz2 trackermap-server-fc0a26137fbd00339fcbf28b10b2afae6242d094.zip |
Fix Ulbotech frame and protocol decoders
5 files changed, 39 insertions, 17 deletions
diff --git a/src/org/traccar/model/Extensible.java b/src/org/traccar/model/Extensible.java index 40a286987..f59b3d22e 100644 --- a/src/org/traccar/model/Extensible.java +++ b/src/org/traccar/model/Extensible.java @@ -53,7 +53,7 @@ public abstract class Extensible extends Message { } public void add(Map.Entry<String, Object> entry) { - if (entry.getValue() != null) { + if (entry != null && entry.getValue() != null) { attributes.put(entry.getKey(), entry.getValue()); } } diff --git a/src/org/traccar/protocol/UlbotechFrameDecoder.java b/src/org/traccar/protocol/UlbotechFrameDecoder.java index f0671c717..09c1db717 100644 --- a/src/org/traccar/protocol/UlbotechFrameDecoder.java +++ b/src/org/traccar/protocol/UlbotechFrameDecoder.java @@ -33,25 +33,36 @@ public class UlbotechFrameDecoder extends FrameDecoder { return null; } - int index = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 0xF8); - if (index != -1) { - ChannelBuffer result = ChannelBuffers.buffer(index + 1 - buf.readerIndex()); - - while (buf.readerIndex() <= index) { - int b = buf.readUnsignedByte(); - if (b == 0xF7) { - int ext = buf.readUnsignedByte(); - if (ext == 0x00) { - result.writeByte(0xF7); - } else if (ext == 0x0F) { - result.writeByte(0xF8); + if (buf.getUnsignedByte(buf.readerIndex()) == 0xF8) { + + int index = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 0xF8); + if (index != -1) { + ChannelBuffer result = ChannelBuffers.buffer(index + 1 - buf.readerIndex()); + + while (buf.readerIndex() <= index) { + int b = buf.readUnsignedByte(); + if (b == 0xF7) { + int ext = buf.readUnsignedByte(); + if (ext == 0x00) { + result.writeByte(0xF7); + } else if (ext == 0x0F) { + result.writeByte(0xF8); + } + } else { + result.writeByte(b); } - } else { - result.writeByte(b); } + + return result; + } + + } else { + + int index = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '#'); + if (index != -1) { + return buf.readBytes(index + 1 - buf.readerIndex()); } - return result; } return null; diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java index 712444d95..3dc5b36cb 100644 --- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java +++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java @@ -101,7 +101,10 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { ChannelBuffer buf = (ChannelBuffer) msg; - buf.readByte(); // header + if (buf.readUnsignedByte() != 0xF8) { + return null; + } + buf.readUnsignedByte(); // version buf.readUnsignedByte(); // type @@ -218,6 +221,7 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder { if (hasLocation) { return position; } + return null; } diff --git a/test/org/traccar/protocol/UlbotechFrameDecoderTest.java b/test/org/traccar/protocol/UlbotechFrameDecoderTest.java index baf151659..3a21fd209 100644 --- a/test/org/traccar/protocol/UlbotechFrameDecoderTest.java +++ b/test/org/traccar/protocol/UlbotechFrameDecoderTest.java @@ -12,6 +12,10 @@ public class UlbotechFrameDecoderTest extends ProtocolTest { UlbotechFrameDecoder decoder = new UlbotechFrameDecoder(); Assert.assertEquals( + binary("2a545330312c33353430343330353133383934363023"), + decoder.decode(null, null, binary("2a545330312c33353430343330353133383934363023"))); + + Assert.assertEquals( binary("f8010108679650230646339de69054010e015ee17506bde2c60000000000ac0304024000000404000009f705060390181422170711310583410c0000310d00312f834131018608040003130a100101136cf8"), decoder.decode(null, null, binary("f8010108679650230646339de69054010e015ee17506bde2c60000000000ac0304024000000404000009f70005060390181422170711310583410c0000310d00312f834131018608040003130a100101136cf8"))); diff --git a/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java b/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java index 1fb515315..e87e95efe 100644 --- a/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java +++ b/test/org/traccar/protocol/UlbotechProtocolDecoderTest.java @@ -10,6 +10,9 @@ public class UlbotechProtocolDecoderTest extends ProtocolTest { UlbotechProtocolDecoder decoder = new UlbotechProtocolDecoder(new UlbotechProtocol()); + verifyNothing(decoder, binary( + "2a545330312c33353430343330353133383934363023")); + verifyPosition(decoder, binary( "f8010108679650230646339de69054010e015ee17506bde2c60000000000ac0304024000000404000009f705060390181422170711310583410c0000310d00312f834131018608040003130a100101136cf8")); |