aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-08-03 19:06:12 -0700
committerAnton Tananaev <anton@traccar.org>2022-08-03 19:06:12 -0700
commit074cc52c3d645ac974a1489aa4e197d471093403 (patch)
treec26cf338a5b02805731c631fb101db1dffad7590 /src/main/java/org
parent6d1923bd6b4841eac9d1a383e1eafe6cab30ce8c (diff)
downloadtrackermap-server-074cc52c3d645ac974a1489aa4e197d471093403.tar.gz
trackermap-server-074cc52c3d645ac974a1489aa4e197d471093403.tar.bz2
trackermap-server-074cc52c3d645ac974a1489aa4e197d471093403.zip
Implement refuel events
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/traccar/config/Keys.java9
-rw-r--r--src/main/java/org/traccar/handler/events/FuelEventHandler.java28
-rw-r--r--src/main/java/org/traccar/model/Event.java1
3 files changed, 27 insertions, 11 deletions
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java
index e97e104a1..a3b39581d 100644
--- a/src/main/java/org/traccar/config/Keys.java
+++ b/src/main/java/org/traccar/config/Keys.java
@@ -310,6 +310,15 @@ public final class Keys {
0.0);
/**
+ * Fuel increase threshold value. When fuel level increases from one position to another for more the value, an
+ * event is generated.
+ */
+ public static final ConfigKey<Double> EVENT_FUEL_INCREASE_THRESHOLD = new DoubleConfigKey(
+ "fuelIncreaseThreshold",
+ List.of(KeyType.SERVER, KeyType.DEVICE),
+ 0.0);
+
+ /**
* Speed limit value in knots.
*/
public static final ConfigKey<Double> EVENT_OVERSPEED_LIMIT = new DoubleConfigKey(
diff --git a/src/main/java/org/traccar/handler/events/FuelEventHandler.java b/src/main/java/org/traccar/handler/events/FuelEventHandler.java
index 9ec819a5f..d5d4ab9be 100644
--- a/src/main/java/org/traccar/handler/events/FuelEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/FuelEventHandler.java
@@ -25,7 +25,6 @@ import org.traccar.model.Position;
import org.traccar.session.cache.CacheManager;
import javax.inject.Inject;
-import java.util.Collections;
import java.util.Map;
@ChannelHandler.Sharable
@@ -49,18 +48,25 @@ public class FuelEventHandler extends BaseEventHandler {
return null;
}
- double fuelDropThreshold = AttributeUtil.lookup(
- cacheManager, Keys.EVENT_FUEL_DROP_THRESHOLD, position.getDeviceId());
- if (fuelDropThreshold > 0) {
+ if (position.hasAttribute(Position.KEY_FUEL_LEVEL)) {
Position lastPosition = cacheManager.getPosition(position.getDeviceId());
- if (position.hasAttribute(Position.KEY_FUEL_LEVEL)
- && lastPosition != null && lastPosition.hasAttribute(Position.KEY_FUEL_LEVEL)) {
+ if (lastPosition != null && lastPosition.hasAttribute(Position.KEY_FUEL_LEVEL)) {
+ double before = lastPosition.getDouble(Position.KEY_FUEL_LEVEL);
+ double after = position.getDouble(Position.KEY_FUEL_LEVEL);
+ double change = after - before;
- double drop = lastPosition.getDouble(Position.KEY_FUEL_LEVEL)
- - position.getDouble(Position.KEY_FUEL_LEVEL);
- if (drop >= fuelDropThreshold) {
- Event event = new Event(Event.TYPE_DEVICE_FUEL_DROP, position);
- return Collections.singletonMap(event, position);
+ if (change > 0) {
+ double threshold = AttributeUtil.lookup(
+ cacheManager, Keys.EVENT_FUEL_INCREASE_THRESHOLD, position.getDeviceId());
+ if (change >= threshold) {
+ return Map.of(new Event(Event.TYPE_DEVICE_FUEL_INCREASE, position), position);
+ }
+ } else if (change < 0) {
+ double threshold = AttributeUtil.lookup(
+ cacheManager, Keys.EVENT_FUEL_DROP_THRESHOLD, position.getDeviceId());
+ if (Math.abs(change) >= threshold) {
+ return Map.of(new Event(Event.TYPE_DEVICE_FUEL_DROP, position), position);
+ }
}
}
}
diff --git a/src/main/java/org/traccar/model/Event.java b/src/main/java/org/traccar/model/Event.java
index f00a0e5f1..0e851d748 100644
--- a/src/main/java/org/traccar/model/Event.java
+++ b/src/main/java/org/traccar/model/Event.java
@@ -52,6 +52,7 @@ public class Event extends Message {
public static final String TYPE_DEVICE_OVERSPEED = "deviceOverspeed";
public static final String TYPE_DEVICE_FUEL_DROP = "deviceFuelDrop";
+ public static final String TYPE_DEVICE_FUEL_INCREASE = "deviceFuelIncrease";
public static final String TYPE_GEOFENCE_ENTER = "geofenceEnter";
public static final String TYPE_GEOFENCE_EXIT = "geofenceExit";