From 9e5de36d24d477bddc7addc29f4b504314b644cf Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 25 Nov 2015 09:20:01 +1300 Subject: Support Teltonika messages without location --- .../traccar/protocol/TeltonikaProtocolDecoder.java | 69 ++++++++++++---------- 1 file changed, 37 insertions(+), 32 deletions(-) (limited to 'src/org/traccar/protocol') 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 { -- cgit v1.2.3