aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/traccar/config/Keys.java2
-rw-r--r--src/main/java/org/traccar/handler/MotionHandler.java16
-rw-r--r--src/main/java/org/traccar/reports/common/TripsConfig.java12
3 files changed, 13 insertions, 17 deletions
diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java
index c69289403..f0e0bf2b6 100644
--- a/src/main/java/org/traccar/config/Keys.java
+++ b/src/main/java/org/traccar/config/Keys.java
@@ -380,7 +380,7 @@ public final class Keys {
*/
public static final ConfigKey<Double> EVENT_MOTION_SPEED_THRESHOLD = new DoubleConfigKey(
"event.motion.speedThreshold",
- List.of(KeyType.CONFIG),
+ List.of(KeyType.CONFIG, KeyType.DEVICE),
0.01);
/**
diff --git a/src/main/java/org/traccar/handler/MotionHandler.java b/src/main/java/org/traccar/handler/MotionHandler.java
index 10312f9b3..297527b4d 100644
--- a/src/main/java/org/traccar/handler/MotionHandler.java
+++ b/src/main/java/org/traccar/handler/MotionHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 - 2022 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2023 Anton Tananaev (anton@traccar.org)
* Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,8 +18,10 @@ package org.traccar.handler;
import io.netty.channel.ChannelHandler;
import org.traccar.BaseDataHandler;
+import org.traccar.config.Keys;
+import org.traccar.helper.model.AttributeUtil;
import org.traccar.model.Position;
-import org.traccar.reports.common.TripsConfig;
+import org.traccar.session.cache.CacheManager;
import javax.inject.Inject;
import javax.inject.Singleton;
@@ -28,17 +30,19 @@ import javax.inject.Singleton;
@ChannelHandler.Sharable
public class MotionHandler extends BaseDataHandler {
- private final double speedThreshold;
+ private final CacheManager cacheManager;
@Inject
- public MotionHandler(TripsConfig tripsConfig) {
- speedThreshold = tripsConfig.getSpeedThreshold();
+ public MotionHandler(CacheManager cacheManager) {
+ this.cacheManager = cacheManager;
}
@Override
protected Position handlePosition(Position position) {
if (!position.hasAttribute(Position.KEY_MOTION)) {
- position.set(Position.KEY_MOTION, position.getSpeed() > speedThreshold);
+ double threshold = AttributeUtil.lookup(
+ cacheManager, Keys.EVENT_MOTION_SPEED_THRESHOLD, position.getDeviceId());
+ position.set(Position.KEY_MOTION, position.getSpeed() > threshold);
}
return position;
}
diff --git a/src/main/java/org/traccar/reports/common/TripsConfig.java b/src/main/java/org/traccar/reports/common/TripsConfig.java
index 52db97b74..841d9c652 100644
--- a/src/main/java/org/traccar/reports/common/TripsConfig.java
+++ b/src/main/java/org/traccar/reports/common/TripsConfig.java
@@ -33,20 +33,18 @@ public class TripsConfig {
config.getLong(Keys.REPORT_TRIP_MINIMAL_PARKING_DURATION) * 1000,
config.getLong(Keys.REPORT_TRIP_MINIMAL_NO_DATA_DURATION) * 1000,
config.getBoolean(Keys.REPORT_TRIP_USE_IGNITION),
- config.getBoolean(Keys.EVENT_MOTION_PROCESS_INVALID_POSITIONS),
- config.getDouble(Keys.EVENT_MOTION_SPEED_THRESHOLD));
+ config.getBoolean(Keys.EVENT_MOTION_PROCESS_INVALID_POSITIONS));
}
public TripsConfig(
double minimalTripDistance, long minimalTripDuration, long minimalParkingDuration,
- long minimalNoDataDuration, boolean useIgnition, boolean processInvalidPositions, double speedThreshold) {
+ long minimalNoDataDuration, boolean useIgnition, boolean processInvalidPositions) {
this.minimalTripDistance = minimalTripDistance;
this.minimalTripDuration = minimalTripDuration;
this.minimalParkingDuration = minimalParkingDuration;
this.minimalNoDataDuration = minimalNoDataDuration;
this.useIgnition = useIgnition;
this.processInvalidPositions = processInvalidPositions;
- this.speedThreshold = speedThreshold;
}
private final double minimalTripDistance;
@@ -85,10 +83,4 @@ public class TripsConfig {
return processInvalidPositions;
}
- private final double speedThreshold;
-
- public double getSpeedThreshold() {
- return speedThreshold;
- }
-
}