From 4054777eac379ce07560c44901ada659aad062ba Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 19 Jul 2016 11:36:21 +1200 Subject: Get device id from position --- src/org/traccar/BaseProtocolDecoder.java | 38 +++++++++++++++++--------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java index 9a253e351..59205bc6f 100644 --- a/src/org/traccar/BaseProtocolDecoder.java +++ b/src/org/traccar/BaseProtocolDecoder.java @@ -78,25 +78,27 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { } public void getLastLocation(Position position, Date deviceTime) { - position.setOutdated(true); - - Position last = Context.getIdentityManager().getLastPosition(getDeviceId()); - if (last != null) { - position.setFixTime(last.getFixTime()); - position.setValid(last.getValid()); - position.setLatitude(last.getLatitude()); - position.setLongitude(last.getLongitude()); - position.setAltitude(last.getAltitude()); - position.setSpeed(last.getSpeed()); - position.setCourse(last.getCourse()); - } else { - position.setFixTime(new Date(0)); - } + if (position.getDeviceId() != 0) { + position.setOutdated(true); + + Position last = Context.getIdentityManager().getLastPosition(position.getDeviceId()); + if (last != null) { + position.setFixTime(last.getFixTime()); + position.setValid(last.getValid()); + position.setLatitude(last.getLatitude()); + position.setLongitude(last.getLongitude()); + position.setAltitude(last.getAltitude()); + position.setSpeed(last.getSpeed()); + position.setCourse(last.getCourse()); + } else { + position.setFixTime(new Date(0)); + } - if (deviceTime != null) { - position.setDeviceTime(deviceTime); - } else { - position.setDeviceTime(new Date()); + if (deviceTime != null) { + position.setDeviceTime(deviceTime); + } else { + position.setDeviceTime(new Date()); + } } } -- cgit v1.2.3