aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/events/MotionEventHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/events/MotionEventHandler.java')
-rw-r--r--src/org/traccar/events/MotionEventHandler.java18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java
index ed21d7b83..1a8cb0ef8 100644
--- a/src/org/traccar/events/MotionEventHandler.java
+++ b/src/org/traccar/events/MotionEventHandler.java
@@ -36,6 +36,24 @@ public class MotionEventHandler extends BaseEventHandler {
tripsConfig = ReportUtils.initTripsConfig();
}
+ public static Event updateMotionState(DeviceState deviceState, TripsConfig tripsConfig) {
+ Event result = null;
+ if (deviceState.getMotionState() != null && deviceState.getMotionPosition() != null) {
+ boolean newMotion = !deviceState.getMotionState();
+ Position motionPosition = deviceState.getMotionPosition();
+ long currentTime = System.currentTimeMillis();
+ long motionTime = motionPosition.getFixTime().getTime()
+ + (newMotion ? tripsConfig.getMinimalTripDuration() : tripsConfig.getMinimalParkingDuration());
+ if (motionTime <= currentTime) {
+ String eventType = newMotion ? Event.TYPE_DEVICE_MOVING : Event.TYPE_DEVICE_STOPPED;
+ result = new Event(eventType, motionPosition.getDeviceId(), motionPosition.getId());
+ deviceState.setMotionState(newMotion);
+ deviceState.setMotionPosition(null);
+ }
+ }
+ return result;
+ }
+
public static Event updateMotionState(DeviceState deviceState, Position position, TripsConfig tripsConfig) {
Event result = null;
Boolean oldMotion = deviceState.getMotionState();