diff options
author | Abyss777 <abyss@fox5.ru> | 2017-08-11 09:22:53 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2017-08-11 09:27:41 +0500 |
commit | 2e459d8d591ee9d3578a38d981e7c1c13eb3c389 (patch) | |
tree | d5d69d81dc796b54d67946b753e5f801fcb07913 /src/org/traccar/events | |
parent | 532e0a98d469573a575dc595554792cbbd4cd953 (diff) | |
download | traccar-server-2e459d8d591ee9d3578a38d981e7c1c13eb3c389.tar.gz traccar-server-2e459d8d591ee9d3578a38d981e7c1c13eb3c389.tar.bz2 traccar-server-2e459d8d591ee9d3578a38d981e7c1c13eb3c389.zip |
Move state updates from ConnectionManager to proper event handlers
Diffstat (limited to 'src/org/traccar/events')
-rw-r--r-- | src/org/traccar/events/MotionEventHandler.java | 18 | ||||
-rw-r--r-- | src/org/traccar/events/OverspeedEventHandler.java | 20 |
2 files changed, 38 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(); diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java index 3b91fed4d..f0bf8a032 100644 --- a/src/org/traccar/events/OverspeedEventHandler.java +++ b/src/org/traccar/events/OverspeedEventHandler.java @@ -37,6 +37,26 @@ public class OverspeedEventHandler extends BaseEventHandler { minimalDuration = Context.getConfig().getLong("event.overspeed.minimalDuration") * 1000; } + public static Event updateOverspeedState(DeviceState deviceState, double speedLimit, + long minimalDuration, boolean notRepeat) { + Event result = null; + if (deviceState.getOverspeedState() != null && !deviceState.getOverspeedState() + && deviceState.getOverspeedPosition() != null && speedLimit != 0) { + long currentTime = System.currentTimeMillis(); + Position overspeedPosition = deviceState.getOverspeedPosition(); + long overspeedTime = overspeedPosition.getFixTime().getTime(); + if (overspeedTime + minimalDuration <= currentTime) { + result = new Event(Event.TYPE_DEVICE_OVERSPEED, overspeedPosition.getDeviceId(), + overspeedPosition.getId()); + result.set("speed", overspeedPosition.getSpeed()); + result.set(ATTRIBUTE_SPEED_LIMIT, speedLimit); + deviceState.setOverspeedState(notRepeat); + deviceState.setOverspeedPosition(null); + } + } + return result; + } + public static Event updateOverspeedState(DeviceState deviceState, Position position, double speedLimit, long minimalOverspeedDuration, boolean notRepeat) { Event result = null; |