aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorJamie Guthrie <jamie.guthrie@gmail.com>2023-08-15 12:45:46 +0200
committerJamie Guthrie <jamie.guthrie@gmail.com>2023-08-15 12:45:46 +0200
commit25c8da353ead804eabb5b3388f711f20585feff3 (patch)
treee8b836cebf498e915f4abf623000ee675dcd9781 /src/main
parent7d53ddabd857330cd9791b12484d925857842cc9 (diff)
downloadtrackermap-server-25c8da353ead804eabb5b3388f711f20585feff3.tar.gz
trackermap-server-25c8da353ead804eabb5b3388f711f20585feff3.tar.bz2
trackermap-server-25c8da353ead804eabb5b3388f711f20585feff3.zip
Throw overspeed event immediately, accounting for minimumDuration
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/session/state/OverspeedProcessor.java37
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..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);
+
+ }
+ }
+ }
}