aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debug.xml2
-rw-r--r--schema/changelog-3.7.xml2
-rw-r--r--setup/unix/traccar.xml2
-rw-r--r--setup/windows/traccar.xml2
-rw-r--r--src/org/traccar/DefaultDataHandler.java1
-rw-r--r--src/org/traccar/MainEventHandler.java7
-rw-r--r--src/org/traccar/database/DeviceManager.java10
-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
-rw-r--r--src/org/traccar/model/Device.java13
11 files changed, 29 insertions, 37 deletions
diff --git a/debug.xml b/debug.xml
index 304ae7f3d..095f7d4b2 100644
--- a/debug.xml
+++ b/debug.xml
@@ -170,7 +170,7 @@
</entry>
<entry key='database.updateDeviceStatus'>
- UPDATE devices SET status = :status, lastUpdate = :lastUpdate, motion = :motion WHERE id = :id;
+ UPDATE devices SET status = :status, lastUpdate = :lastUpdate WHERE id = :id;
</entry>
<entry key='database.deleteDevice'>
diff --git a/schema/changelog-3.7.xml b/schema/changelog-3.7.xml
index e23e44b04..c988b8bdb 100644
--- a/schema/changelog-3.7.xml
+++ b/schema/changelog-3.7.xml
@@ -24,6 +24,8 @@
<column name="attributes" type="VARCHAR(4096)" />
</addColumn>
+ <dropColumn tableName="devices" columnName="motion" />
+
</changeSet>
<changeSet author="author" id="changelog-3.7-notmssql">
diff --git a/setup/unix/traccar.xml b/setup/unix/traccar.xml
index e8b29a296..90cb5f74e 100644
--- a/setup/unix/traccar.xml
+++ b/setup/unix/traccar.xml
@@ -119,7 +119,7 @@
</entry>
<entry key='database.updateDeviceStatus'>
- UPDATE devices SET status = :status, lastUpdate = :lastUpdate, motion = :motion WHERE id = :id;
+ UPDATE devices SET status = :status, lastUpdate = :lastUpdate WHERE id = :id;
</entry>
<entry key='database.deleteDevice'>
diff --git a/setup/windows/traccar.xml b/setup/windows/traccar.xml
index 6220263ef..25128a3e0 100644
--- a/setup/windows/traccar.xml
+++ b/setup/windows/traccar.xml
@@ -119,7 +119,7 @@
</entry>
<entry key='database.updateDeviceStatus'>
- UPDATE devices SET status = :status, lastUpdate = :lastUpdate, motion = :motion WHERE id = :id;
+ UPDATE devices SET status = :status, lastUpdate = :lastUpdate WHERE id = :id;
</entry>
<entry key='database.deleteDevice'>
diff --git a/src/org/traccar/DefaultDataHandler.java b/src/org/traccar/DefaultDataHandler.java
index 8923c3a0e..7194c6a77 100644
--- a/src/org/traccar/DefaultDataHandler.java
+++ b/src/org/traccar/DefaultDataHandler.java
@@ -25,7 +25,6 @@ public class DefaultDataHandler extends BaseDataHandler {
try {
Context.getDataManager().addPosition(position);
- Context.getDeviceManager().updateLatestPosition(position);
} catch (Exception error) {
Log.warning(error);
}
diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java
index 771009aca..c01760283 100644
--- a/src/org/traccar/MainEventHandler.java
+++ b/src/org/traccar/MainEventHandler.java
@@ -26,6 +26,7 @@ import org.jboss.netty.handler.timeout.IdleStateEvent;
import org.traccar.helper.Log;
import org.traccar.model.Position;
+import java.sql.SQLException;
import java.text.SimpleDateFormat;
public class MainEventHandler extends IdleStateAwareChannelHandler {
@@ -36,6 +37,11 @@ public class MainEventHandler extends IdleStateAwareChannelHandler {
if (e.getMessage() != null && e.getMessage() instanceof Position) {
Position position = (Position) e.getMessage();
+ try {
+ Context.getDeviceManager().updateLatestPosition(position);
+ } catch (SQLException error) {
+ Log.warning(error);
+ }
String uniqueId = Context.getIdentityManager().getDeviceById(position.getDeviceId()).getUniqueId();
@@ -54,6 +60,7 @@ public class MainEventHandler extends IdleStateAwareChannelHandler {
s.append(", result: ").append(cmdResult);
}
Log.info(s.toString());
+
}
}
diff --git a/src/org/traccar/database/DeviceManager.java b/src/org/traccar/database/DeviceManager.java
index 4dd7b41cb..5a0c87985 100644
--- a/src/org/traccar/database/DeviceManager.java
+++ b/src/org/traccar/database/DeviceManager.java
@@ -105,7 +105,6 @@ public class DeviceManager implements IdentityManager {
}
}
device.setStatus(Device.STATUS_OFFLINE);
- device.setMotion(Device.STATUS_STOPPED);
}
}
for (Long cachedDeviceId : devicesById.keySet()) {
@@ -176,7 +175,6 @@ public class DeviceManager implements IdentityManager {
if (devicesById.containsKey(device.getId())) {
Device cachedDevice = devicesById.get(device.getId());
cachedDevice.setStatus(device.getStatus());
- cachedDevice.setMotion(device.getMotion());
}
}
@@ -191,10 +189,14 @@ public class DeviceManager implements IdentityManager {
positions.remove(deviceId);
}
+ public boolean isLatestPosition(Position position) {
+ Position lastPosition = getLastPosition(position.getDeviceId());
+ return lastPosition == null || position.getFixTime().compareTo(lastPosition.getFixTime()) > 0;
+ }
+
public void updateLatestPosition(Position position) throws SQLException {
- Position lastPosition = getLastPosition(position.getDeviceId());
- if (lastPosition == null || position.getFixTime().compareTo(lastPosition.getFixTime()) > 0) {
+ if (isLatestPosition(position)) {
dataManager.updateLatestPosition(position);
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()) {
diff --git a/src/org/traccar/model/Device.java b/src/org/traccar/model/Device.java
index 1669aee31..e90742836 100644
--- a/src/org/traccar/model/Device.java
+++ b/src/org/traccar/model/Device.java
@@ -92,19 +92,6 @@ public class Device extends Extensible {
this.groupId = groupId;
}
- public static final String STATUS_MOVING = "moving";
- public static final String STATUS_STOPPED = "stopped";
-
- private String motion;
-
- public String getMotion() {
- return motion;
- }
-
- public void setMotion(String motion) {
- this.motion = motion;
- }
-
private List<Long> geofenceIds;
public List<Long> getGeofenceIds() {