aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/events
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-07-25 23:53:44 +1200
committerGitHub <noreply@github.com>2016-07-25 23:53:44 +1200
commit7e20896334f4f6927cf14c5272cf7d893efc3a05 (patch)
tree4ce04313dde4989a4c5b16816ddfeab1a6381876 /src/org/traccar/events
parent8c4eb2eff9da9bf0538e413444c1e6dae981b99e (diff)
parent80847cc39a0570a91618c2d9da283767a99fd975 (diff)
downloadtraccar-server-7e20896334f4f6927cf14c5272cf7d893efc3a05.tar.gz
traccar-server-7e20896334f4f6927cf14c5272cf7d893efc3a05.tar.bz2
traccar-server-7e20896334f4f6927cf14c5272cf7d893efc3a05.zip
Merge pull request #2149 from Abyss777/lastposition_reorganization
Move lastPosition update to the end of pipeline
Diffstat (limited to 'src/org/traccar/events')
-rw-r--r--src/org/traccar/events/GeofenceEventHandler.java2
-rw-r--r--src/org/traccar/events/MotionEventHandler.java20
-rw-r--r--src/org/traccar/events/OverspeedEventHandler.java5
3 files changed, 11 insertions, 16 deletions
diff --git a/src/org/traccar/events/GeofenceEventHandler.java b/src/org/traccar/events/GeofenceEventHandler.java
index 1ea7aee41..a9bed6f82 100644
--- a/src/org/traccar/events/GeofenceEventHandler.java
+++ b/src/org/traccar/events/GeofenceEventHandler.java
@@ -47,7 +47,7 @@ public class GeofenceEventHandler extends BaseEventHandler {
if (device == null) {
return null;
}
- if (position.getId() != device.getPositionId() || !position.getValid()) {
+ if (!Context.getDeviceManager().isLatestPosition(position) || !position.getValid()) {
return null;
}
diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java
index 4a3d2f0f0..4b652a727 100644
--- a/src/org/traccar/events/MotionEventHandler.java
+++ b/src/org/traccar/events/MotionEventHandler.java
@@ -28,7 +28,7 @@ import org.traccar.model.Position;
public class MotionEventHandler extends BaseEventHandler {
- private static final double SPEED_THRESHOLD = 0.01;
+ private static final double SPEED_THRESHOLD = 0.01;
private int suppressRepeated;
public MotionEventHandler() {
@@ -42,26 +42,22 @@ 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);
+ if (speed > SPEED_THRESHOLD && oldSpeed <= SPEED_THRESHOLD) {
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);
+ } else if (speed <= SPEED_THRESHOLD && oldSpeed > SPEED_THRESHOLD) {
result = new ArrayList<>();
result.add(new Event(Event.TYPE_DEVICE_STOPPED, position.getDeviceId(), position.getId()));
}
diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java
index fd005e170..6c9b523f4 100644
--- a/src/org/traccar/events/OverspeedEventHandler.java
+++ b/src/org/traccar/events/OverspeedEventHandler.java
@@ -44,15 +44,14 @@ public class OverspeedEventHandler 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> events = new ArrayList<>();
double speed = position.getSpeed();
- boolean valid = position.getValid();
- if (valid && globalSpeedLimit != 0 && speed > globalSpeedLimit) {
+ if (globalSpeedLimit != 0 && speed > globalSpeedLimit) {
try {
if (Context.getDataManager().getLastEvents(
position.getDeviceId(), Event.TYPE_DEVICE_OVERSPEED, suppressRepeated).isEmpty()) {