aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-11-25 09:20:01 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-11-25 09:20:01 +1300
commit9e5de36d24d477bddc7addc29f4b504314b644cf (patch)
tree1f3c924c60f44d79ae7dcd7497257ce647ba3707
parentfcdea01510dc9bf7144c76f4dd3a08c8c4eebaca (diff)
downloadtrackermap-server-9e5de36d24d477bddc7addc29f4b504314b644cf.tar.gz
trackermap-server-9e5de36d24d477bddc7addc29f4b504314b644cf.tar.bz2
trackermap-server-9e5de36d24d477bddc7addc29f4b504314b644cf.zip
Support Teltonika messages without location
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolDecoder.java69
-rw-r--r--test/org/traccar/ProtocolDecoderTest.java12
-rw-r--r--test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java3
3 files changed, 48 insertions, 36 deletions
diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
index 2217b5ce4..e82425a54 100644
--- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -81,49 +81,54 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
long time = buf.readUnsignedInt() & 0x3fffffff;
time += 1167609600; // 2007-01-01 00:00:00
- position.setTime(new Date(time * 1000));
globalMask = buf.readUnsignedByte();
- if (!BitUtil.check(globalMask, 0)) {
- return null;
- }
+ if (BitUtil.check(globalMask, 0)) {
- int locationMask = buf.readUnsignedByte();
+ position.setTime(new Date(time * 1000));
- if (BitUtil.check(locationMask, 0)) {
- position.setLatitude(buf.readFloat());
- position.setLongitude(buf.readFloat());
- }
+ int locationMask = buf.readUnsignedByte();
- if (BitUtil.check(locationMask, 1)) {
- position.setAltitude(buf.readUnsignedShort());
- }
+ if (BitUtil.check(locationMask, 0)) {
+ position.setLatitude(buf.readFloat());
+ position.setLongitude(buf.readFloat());
+ }
- if (BitUtil.check(locationMask, 2)) {
- position.setCourse(buf.readUnsignedByte() * 360.0 / 256);
- }
+ if (BitUtil.check(locationMask, 1)) {
+ position.setAltitude(buf.readUnsignedShort());
+ }
- if (BitUtil.check(locationMask, 3)) {
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- }
+ if (BitUtil.check(locationMask, 2)) {
+ position.setCourse(buf.readUnsignedByte() * 360.0 / 256);
+ }
- if (BitUtil.check(locationMask, 4)) {
- int satellites = buf.readUnsignedByte();
- position.set(Event.KEY_SATELLITES, satellites);
- position.setValid(satellites >= 3);
- }
+ if (BitUtil.check(locationMask, 3)) {
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
+ }
- if (BitUtil.check(locationMask, 5)) {
- position.set(Event.KEY_LAC, buf.readUnsignedShort());
- position.set(Event.KEY_CID, buf.readUnsignedShort());
- }
+ if (BitUtil.check(locationMask, 4)) {
+ int satellites = buf.readUnsignedByte();
+ position.set(Event.KEY_SATELLITES, satellites);
+ position.setValid(satellites >= 3);
+ }
- if (BitUtil.check(locationMask, 6)) {
- position.set(Event.KEY_GSM, buf.readUnsignedByte());
- }
+ if (BitUtil.check(locationMask, 5)) {
+ position.set(Event.KEY_LAC, buf.readUnsignedShort());
+ position.set(Event.KEY_CID, buf.readUnsignedShort());
+ }
+
+ if (BitUtil.check(locationMask, 6)) {
+ position.set(Event.KEY_GSM, buf.readUnsignedByte());
+ }
+
+ if (BitUtil.check(locationMask, 7)) {
+ position.set("operator", buf.readUnsignedInt());
+ }
+
+ } else {
+
+ getLastLocation(position, new Date(time * 1000));
- if (BitUtil.check(locationMask, 7)) {
- position.set("operator", buf.readUnsignedInt());
}
} else {
diff --git a/test/org/traccar/ProtocolDecoderTest.java b/test/org/traccar/ProtocolDecoderTest.java
index 8f7ed628b..5d2acdda1 100644
--- a/test/org/traccar/ProtocolDecoderTest.java
+++ b/test/org/traccar/ProtocolDecoderTest.java
@@ -119,21 +119,25 @@ public class ProtocolDecoderTest {
}
protected void verifyPositions(BaseProtocolDecoder decoder, Object object) throws Exception {
- verifyDecodedList(decoder.decode(null, null, object), null);
+ verifyDecodedList(decoder.decode(null, null, object), true, null);
+ }
+
+ protected void verifyPositions(BaseProtocolDecoder decoder, boolean checkLocation, Object object) throws Exception {
+ verifyDecodedList(decoder.decode(null, null, object), checkLocation, null);
}
protected void verifyPositions(BaseProtocolDecoder decoder, Object object, Position position) throws Exception {
- verifyDecodedList(decoder.decode(null, null, object), position);
+ verifyDecodedList(decoder.decode(null, null, object), true, position);
}
- private void verifyDecodedList(Object decodedObject, Position expected) {
+ private void verifyDecodedList(Object decodedObject, boolean checkLocation, Position expected) {
Assert.assertNotNull("list is null", decodedObject);
Assert.assertTrue("not a list", decodedObject instanceof List);
Assert.assertFalse("list if empty", ((List) decodedObject).isEmpty());
for (Object item : (List) decodedObject) {
- verifyDecodedPosition(item, true, false, expected);
+ verifyDecodedPosition(item, checkLocation, false, expected);
}
}
diff --git a/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java b/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java
index 7e3f7cb35..9e3c9a377 100644
--- a/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java
@@ -16,6 +16,9 @@ public class TeltonikaProtocolDecoderTest extends ProtocolDecoderTest {
verifyNothing(decoder, binary(
"000F313233343536373839303132333435"));
+ verifyPositions(decoder, false, binary(
+ "0000000000000055070450aa14320201f00150aa17f3031f42332a4c4193d68c008d00020901f00150aa1b6a031f423383f54193624f009d00000a01f00150aa1c230fc01a0000552b040164f400dd00f0010143100c0105000000050400006846"));
+
verifyPositions(decoder, binary(
"000000000000003508010000014f8e016420002141bbaf0f4e96a7fffa0000120000000602010047030242669c92000002c7000000009100000000000100002df3"));