aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/events/MotionEventHandler.java
diff options
context:
space:
mode:
authorninioe <ninioe@gmail.com>2016-08-01 16:12:47 +0300
committerninioe <ninioe@gmail.com>2016-08-01 16:12:47 +0300
commit94781fa3ba35e494e309aee19a5e15c14d3193c1 (patch)
treea1e4a90e9a2fce3db8bc51981aeb8a23cced5e6d /src/org/traccar/events/MotionEventHandler.java
parentb4841fa0a6293c0b895cf6bb65c6c2d871c78397 (diff)
parente177e7d083a4dd3f64172802661bf658d26d1163 (diff)
downloadtrackermap-server-94781fa3ba35e494e309aee19a5e15c14d3193c1.tar.gz
trackermap-server-94781fa3ba35e494e309aee19a5e15c14d3193c1.tar.bz2
trackermap-server-94781fa3ba35e494e309aee19a5e15c14d3193c1.zip
Merge remote-tracking branch 'refs/remotes/tananaev/master'
Diffstat (limited to 'src/org/traccar/events/MotionEventHandler.java')
-rw-r--r--src/org/traccar/events/MotionEventHandler.java48
1 files changed, 12 insertions, 36 deletions
diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java
index 4a3d2f0f0..ddb99185f 100644
--- a/src/org/traccar/events/MotionEventHandler.java
+++ b/src/org/traccar/events/MotionEventHandler.java
@@ -15,25 +15,18 @@
*/
package org.traccar.events;
-import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import org.traccar.BaseEventHandler;
import org.traccar.Context;
-import org.traccar.helper.Log;
import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
public class MotionEventHandler extends BaseEventHandler {
- private static final double SPEED_THRESHOLD = 0.01;
- private int suppressRepeated;
-
- public MotionEventHandler() {
- suppressRepeated = Context.getConfig().getInteger("event.suppressRepeated", 60);
- }
+ private static final double SPEED_THRESHOLD = 0.01;
@Override
protected Collection<Event> analyzePosition(Position position) {
@@ -42,40 +35,23 @@ public class MotionEventHandler extends BaseEventHandler {
if (device == null) {
return null;
}
- if (position.getId() != device.getPositionId() || !position.getValid()) {
+ if (!Context.getDeviceManager().isLatestPosition(position) || !position.getValid()) {
return null;
}
Collection<Event> result = null;
double speed = position.getSpeed();
- boolean valid = position.getValid();
- String motion = device.getMotion();
- if (motion == null) {
- motion = Device.STATUS_STOPPED;
+ double oldSpeed = 0;
+ Position lastPosition = Context.getDeviceManager().getLastPosition(position.getDeviceId());
+ if (lastPosition != null) {
+ oldSpeed = lastPosition.getSpeed();
}
- try {
- if (valid && speed > SPEED_THRESHOLD && !motion.equals(Device.STATUS_MOVING)) {
- device.setMotion(Device.STATUS_MOVING);
- Context.getDeviceManager().updateDeviceStatus(device);
- result = new ArrayList<>();
- result.add(new Event(Event.TYPE_DEVICE_MOVING, position.getDeviceId(), position.getId()));
- } else if (valid && speed < SPEED_THRESHOLD && motion.equals(Device.STATUS_MOVING)) {
- device.setMotion(Device.STATUS_STOPPED);
- Context.getDeviceManager().updateDeviceStatus(device);
- result = new ArrayList<>();
- result.add(new Event(Event.TYPE_DEVICE_STOPPED, position.getDeviceId(), position.getId()));
- }
-
- if (result != null && !result.isEmpty()) {
- for (Event event : result) {
- if (!Context.getDataManager().getLastEvents(position.getDeviceId(),
- event.getType(), suppressRepeated).isEmpty()) {
- event = null;
- }
- }
- }
- } catch (SQLException error) {
- Log.warning(error);
+ if (speed > SPEED_THRESHOLD && oldSpeed <= SPEED_THRESHOLD) {
+ result = new ArrayList<>();
+ result.add(new Event(Event.TYPE_DEVICE_MOVING, position.getDeviceId(), position.getId()));
+ } else if (speed <= SPEED_THRESHOLD && oldSpeed > SPEED_THRESHOLD) {
+ result = new ArrayList<>();
+ result.add(new Event(Event.TYPE_DEVICE_STOPPED, position.getDeviceId(), position.getId()));
}
return result;
}