diff options
-rw-r--r-- | src/org/traccar/Config.java | 12 | ||||
-rw-r--r-- | src/org/traccar/events/MotionEventHandler.java | 10 |
2 files changed, 19 insertions, 3 deletions
diff --git a/src/org/traccar/Config.java b/src/org/traccar/Config.java index 49d6e4fde..7fd725734 100644 --- a/src/org/traccar/Config.java +++ b/src/org/traccar/Config.java @@ -74,4 +74,16 @@ public class Config { } } + public double getDouble(String key) { + return getDouble(key, 0.0); + } + + public double getDouble(String key, double defaultValue) { + if (properties.containsKey(key)) { + return Double.parseDouble(properties.getProperty(key)); + } else { + return defaultValue; + } + } + } diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java index 7178f7036..33c7735cd 100644 --- a/src/org/traccar/events/MotionEventHandler.java +++ b/src/org/traccar/events/MotionEventHandler.java @@ -26,7 +26,11 @@ import org.traccar.model.Position; public class MotionEventHandler extends BaseEventHandler { - private static final double SPEED_THRESHOLD = 0.01; + private double speedThreshold; + + public MotionEventHandler() { + speedThreshold = Context.getConfig().getDouble("event.motion.speedThreshold", 0.01); + } @Override protected Collection<Event> analyzePosition(Position position) { @@ -46,10 +50,10 @@ public class MotionEventHandler extends BaseEventHandler { if (lastPosition != null) { oldSpeed = lastPosition.getSpeed(); } - if (speed > SPEED_THRESHOLD && oldSpeed <= SPEED_THRESHOLD) { + if (speed > speedThreshold && oldSpeed <= speedThreshold) { result = new ArrayList<>(); result.add(new Event(Event.TYPE_DEVICE_MOVING, position.getDeviceId(), position.getId())); - } else if (speed <= SPEED_THRESHOLD && oldSpeed > SPEED_THRESHOLD) { + } else if (speed <= speedThreshold && oldSpeed > speedThreshold) { result = new ArrayList<>(); result.add(new Event(Event.TYPE_DEVICE_STOPPED, position.getDeviceId(), position.getId())); } |