diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2013-03-20 21:42:05 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2013-03-20 21:42:05 +1300 |
commit | 1a0a34acfb775385fe37de4992215a2e328cc6f6 (patch) | |
tree | d718dccd2ab30b3910c3b2e9e729e1c32607cda1 | |
parent | 572dfddfb64f99dbfde60fda628bba327c245465 (diff) | |
download | trackermap-server-1a0a34acfb775385fe37de4992215a2e328cc6f6.tar.gz trackermap-server-1a0a34acfb775385fe37de4992215a2e328cc6f6.tar.bz2 trackermap-server-1a0a34acfb775385fe37de4992215a2e328cc6f6.zip |
Fix Galileo protocol
-rw-r--r-- | src/org/traccar/protocol/GalileoProtocolDecoder.java | 15 | ||||
-rw-r--r-- | test/org/traccar/protocol/GalileoProtocolDecoderTest.java | 7 |
2 files changed, 18 insertions, 4 deletions
diff --git a/src/org/traccar/protocol/GalileoProtocolDecoder.java b/src/org/traccar/protocol/GalileoProtocolDecoder.java index e4b80777e..ac820b587 100644 --- a/src/org/traccar/protocol/GalileoProtocolDecoder.java +++ b/src/org/traccar/protocol/GalileoProtocolDecoder.java @@ -92,7 +92,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { ChannelBuffer buf = (ChannelBuffer) msg; buf.readUnsignedByte(); // header - int length = buf.readUnsignedShort() & 0x7fff + 3; + int length = (buf.readUnsignedShort() & 0x7fff) + 3; // Create new position Position position = new Position(); @@ -109,6 +109,7 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { position.setDeviceId(getDataManager().getDeviceByImei(imei).getId()); } catch(Exception error) { Log.warning("Unknown device - " + imei); + return null; } break; @@ -159,6 +160,18 @@ public class GalileoProtocolDecoder extends BaseProtocolDecoder { } } + + if (position.getDeviceId() == null || + position.getValid() == null || + position.getTime() == null || + position.getSpeed() == null) { + Log.warning("Identifier or location information missing"); + return null; + } + + if (position.getAltitude() == null) { + position.setAltitude(0.0); + } sendReply(channel, buf.readUnsignedShort()); diff --git a/test/org/traccar/protocol/GalileoProtocolDecoderTest.java b/test/org/traccar/protocol/GalileoProtocolDecoderTest.java index d1706e5be..facaf1109 100644 --- a/test/org/traccar/protocol/GalileoProtocolDecoderTest.java +++ b/test/org/traccar/protocol/GalileoProtocolDecoderTest.java @@ -1,7 +1,8 @@ package org.traccar.protocol; +import java.nio.ByteOrder; import org.jboss.netty.buffer.ChannelBuffers; -import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import org.junit.Test; public class GalileoProtocolDecoderTest { @@ -12,8 +13,8 @@ public class GalileoProtocolDecoderTest { GalileoProtocolDecoder decoder = new GalileoProtocolDecoder(null); decoder.setDataManager(new TestDataManager()); - /*byte[] buf1 = {0x00}; - assertNotNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(buf1)));*/ + byte[] buf1 = {0x01,0x13,(byte)0x80,0x03,0x38,0x36,0x38,0x32,0x30,0x34,0x30,0x30,0x31,0x35,0x34,0x39,0x30,0x38,0x37,0x04,0x32,0x00,(byte)0x85,(byte)0x90}; + assertNull(decoder.decode(null, null, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, buf1))); } |