diff options
Diffstat (limited to 'src/org/traccar/events')
-rw-r--r-- | src/org/traccar/events/IgnitionEventHandler.java | 12 | ||||
-rw-r--r-- | src/org/traccar/events/MaintenanceEventHandler.java | 15 | ||||
-rw-r--r-- | src/org/traccar/events/OverspeedEventHandler.java | 2 |
3 files changed, 9 insertions, 20 deletions
diff --git a/src/org/traccar/events/IgnitionEventHandler.java b/src/org/traccar/events/IgnitionEventHandler.java index b52083f57..3086adb13 100644 --- a/src/org/traccar/events/IgnitionEventHandler.java +++ b/src/org/traccar/events/IgnitionEventHandler.java @@ -39,20 +39,12 @@ public class IgnitionEventHandler extends BaseEventHandler { Collection<Event> result = null; - boolean ignition = false; - Object ignitionObject = position.getAttributes().get(Position.KEY_IGNITION); - if (ignitionObject != null && ignitionObject instanceof Boolean) { - ignition = (Boolean) ignitionObject; - } + boolean ignition = position.getBoolean(Position.KEY_IGNITION); boolean oldIgnition = false; - Object oldIgnitionObject = null; Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId()); if (lastPosition != null) { - oldIgnitionObject = lastPosition.getAttributes().get(Position.KEY_IGNITION); - } - if (oldIgnitionObject != null && oldIgnitionObject instanceof Boolean) { - oldIgnition = (Boolean) oldIgnitionObject; + oldIgnition = lastPosition.getBoolean(Position.KEY_IGNITION); } if (ignition && !oldIgnition) { diff --git a/src/org/traccar/events/MaintenanceEventHandler.java b/src/org/traccar/events/MaintenanceEventHandler.java index 466e0b617..9e0da97f5 100644 --- a/src/org/traccar/events/MaintenanceEventHandler.java +++ b/src/org/traccar/events/MaintenanceEventHandler.java @@ -38,30 +38,27 @@ public class MaintenanceEventHandler extends BaseEventHandler { } double maintenanceInterval = Context.getDeviceManager() - .lookupServerDouble(device.getId(), ATTRIBUTE_MAINTENANCE_INTERVAL, 0); + .lookupAttributeDouble(device.getId(), ATTRIBUTE_MAINTENANCE_INTERVAL, 0, false); if (maintenanceInterval == 0) { return null; } double maintenanceStart = Context.getDeviceManager() - .lookupServerDouble(device.getId(), ATTRIBUTE_MAINTENANCE_START, 0); + .lookupAttributeDouble(device.getId(), ATTRIBUTE_MAINTENANCE_START, 0, false); Collection<Event> events = new ArrayList<>(); double oldTotalDistance = 0.0; double newTotalDistance = 0.0; Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId()); - if (lastPosition != null && lastPosition.getAttributes().containsKey(Position.KEY_TOTAL_DISTANCE)) { - oldTotalDistance = ((Number) lastPosition.getAttributes().get(Position.KEY_TOTAL_DISTANCE)).doubleValue(); - } - - if (position.getAttributes().containsKey(Position.KEY_TOTAL_DISTANCE)) { - newTotalDistance = ((Number) position.getAttributes().get(Position.KEY_TOTAL_DISTANCE)).doubleValue(); + if (lastPosition != null) { + oldTotalDistance = lastPosition.getDouble(Position.KEY_TOTAL_DISTANCE); } + newTotalDistance = position.getDouble(Position.KEY_TOTAL_DISTANCE); oldTotalDistance -= maintenanceStart; newTotalDistance -= maintenanceStart; if ((long) (oldTotalDistance / maintenanceInterval) < (long) (newTotalDistance / maintenanceInterval)) { - events.add(new Event(Event.TYPE_MAINTENANCE_NEEDED, position.getDeviceId(), position.getId())); + events.add(new Event(Event.TYPE_MAINTENANCE, position.getDeviceId(), position.getId())); } return events; diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java index c3e3e19cb..505d706f4 100644 --- a/src/org/traccar/events/OverspeedEventHandler.java +++ b/src/org/traccar/events/OverspeedEventHandler.java @@ -48,7 +48,7 @@ public class OverspeedEventHandler extends BaseEventHandler { Collection<Event> events = new ArrayList<>(); double speed = position.getSpeed(); double speedLimit = Context.getDeviceManager() - .lookupServerDouble(device.getId(), ATTRIBUTE_SPEED_LIMIT, 0); + .lookupAttributeDouble(device.getId(), ATTRIBUTE_SPEED_LIMIT, 0, false); if (speedLimit == 0) { return null; } |