diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2023-08-15 13:53:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-15 13:53:50 -0700 |
commit | 14bca86d8cb71764c699f3cb039484dcd8238bc0 (patch) | |
tree | 836da7ddf4c2edfa75a7aecb1bf8e404bf4f77cc /src/main/java/org | |
parent | 7d53ddabd857330cd9791b12484d925857842cc9 (diff) | |
parent | 95059cb3db832a26c6dbf3706aded3a2ffbcf3d8 (diff) | |
download | trackermap-server-14bca86d8cb71764c699f3cb039484dcd8238bc0.tar.gz trackermap-server-14bca86d8cb71764c699f3cb039484dcd8238bc0.tar.bz2 trackermap-server-14bca86d8cb71764c699f3cb039484dcd8238bc0.zip |
Merge pull request #5159 from jguthrie100/immediate_overspeed_event
Throw overspeed event immediately, accounting for minimumDuration
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/traccar/session/state/OverspeedProcessor.java | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/main/java/org/traccar/session/state/OverspeedProcessor.java b/src/main/java/org/traccar/session/state/OverspeedProcessor.java index 62f6a3de2..b23649570 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); - - } - } + checkEvent(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); + + checkEvent(state, position, speedLimit, minimalDuration); } } + private static void checkEvent(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); + + } + } + } } |