From 25c8da353ead804eabb5b3388f711f20585feff3 Mon Sep 17 00:00:00 2001 From: Jamie Guthrie Date: Tue, 15 Aug 2023 12:45:46 +0200 Subject: Throw overspeed event immediately, accounting for minimumDuration --- .../traccar/session/state/OverspeedProcessor.java | 37 ++++++++++++---------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'src/main/java/org/traccar/session/state') diff --git a/src/main/java/org/traccar/session/state/OverspeedProcessor.java b/src/main/java/org/traccar/session/state/OverspeedProcessor.java index 62f6a3de2..a6cd72322 100644 --- a/src/main/java/org/traccar/session/state/OverspeedProcessor.java +++ b/src/main/java/org/traccar/session/state/OverspeedProcessor.java @@ -34,22 +34,7 @@ public final class OverspeedProcessor { if (oldState) { boolean newState = position.getSpeed() > speedLimit; if (newState) { - if (state.getOverspeedTime() != null) { - long oldTime = state.getOverspeedTime().getTime(); - long newTime = position.getFixTime().getTime(); - if (newTime - oldTime > minimalDuration) { - - Event event = new Event(Event.TYPE_DEVICE_OVERSPEED, position); - event.set(ATTRIBUTE_SPEED, position.getSpeed()); - event.set(Position.KEY_SPEED_LIMIT, speedLimit); - event.setGeofenceId(state.getOverspeedGeofenceId()); - - state.setOverspeedTime(null); - state.setOverspeedGeofenceId(0); - state.setEvent(event); - - } - } + setEvent(state, position, speedLimit, minimalDuration); } else { state.setOverspeedState(false); state.setOverspeedTime(null); @@ -59,7 +44,27 @@ public final class OverspeedProcessor { state.setOverspeedState(true); state.setOverspeedTime(position.getFixTime()); state.setOverspeedGeofenceId(geofenceId); + + setEvent(state, position, speedLimit, minimalDuration); } } + private static void setEvent(OverspeedState state, Position position, double speedLimit, long minimalDuration) { + if (state.getOverspeedTime() != null) { + long oldTime = state.getOverspeedTime().getTime(); + long newTime = position.getFixTime().getTime(); + if (newTime - oldTime >= minimalDuration) { + + Event event = new Event(Event.TYPE_DEVICE_OVERSPEED, position); + event.set(ATTRIBUTE_SPEED, position.getSpeed()); + event.set(Position.KEY_SPEED_LIMIT, speedLimit); + event.setGeofenceId(state.getOverspeedGeofenceId()); + + state.setOverspeedTime(null); + state.setOverspeedGeofenceId(0); + state.setEvent(event); + + } + } + } } -- cgit v1.2.3