aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/events/OverspeedEventHandler.java41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java
index 6c9b523f4..b2b1aeb5f 100644
--- a/src/org/traccar/events/OverspeedEventHandler.java
+++ b/src/org/traccar/events/OverspeedEventHandler.java
@@ -24,16 +24,19 @@ import org.traccar.Context;
import org.traccar.model.Device;
import org.traccar.model.Event;
import org.traccar.model.Position;
+import org.traccar.model.Server;
import org.traccar.helper.Log;
import org.traccar.helper.UnitsConverter;
public class OverspeedEventHandler extends BaseEventHandler {
- private double globalSpeedLimit;
+ public static final String ATTRIBUTE_SPEED_LIMIT = "speedLimit";
+
+ private boolean checkGroups;
private int suppressRepeated;
public OverspeedEventHandler() {
- globalSpeedLimit = UnitsConverter.knotsFromKph(Context.getConfig().getInteger("event.globalSpeedLimit", 0));
+ checkGroups = Context.getConfig().getBoolean("event.overspeed.groupsEnabled");
suppressRepeated = Context.getConfig().getInteger("event.suppressRepeated", 60);
}
@@ -50,8 +53,40 @@ public class OverspeedEventHandler extends BaseEventHandler {
Collection<Event> events = new ArrayList<>();
double speed = position.getSpeed();
+ Double speedLimit = new Double(0);
- if (globalSpeedLimit != 0 && speed > globalSpeedLimit) {
+ if (device.getAttributes().containsKey(ATTRIBUTE_SPEED_LIMIT)) {
+ speedLimit = Double.parseDouble((String) device.getAttributes().get(ATTRIBUTE_SPEED_LIMIT));
+ }
+ if (speedLimit == 0 && checkGroups) {
+ long groupId = device.getGroupId();
+ while (groupId != 0) {
+ if (Context.getDeviceManager().getGroupById(groupId).getAttributes()
+ .containsKey(ATTRIBUTE_SPEED_LIMIT)) {
+ speedLimit = Double.parseDouble((String) Context.getDeviceManager().getGroupById(groupId)
+ .getAttributes().get(ATTRIBUTE_SPEED_LIMIT));
+ if (speedLimit != 0) {
+ break;
+ }
+ }
+ if (Context.getDeviceManager().getGroupById(groupId) != null) {
+ groupId = Context.getDeviceManager().getGroupById(groupId).getGroupId();
+ } else {
+ groupId = 0;
+ }
+ }
+ }
+ if (speedLimit == 0) {
+ try {
+ Server server = Context.getDataManager().getServer();
+ if (server.getAttributes().containsKey(ATTRIBUTE_SPEED_LIMIT)) {
+ speedLimit = Double.parseDouble((String) server.getAttributes().get(ATTRIBUTE_SPEED_LIMIT));
+ }
+ } catch (SQLException error) {
+ Log.warning(error);
+ }
+ }
+ if (speedLimit != 0 && speed > UnitsConverter.knotsFromKph(speedLimit)) {
try {
if (Context.getDataManager().getLastEvents(
position.getDeviceId(), Event.TYPE_DEVICE_OVERSPEED, suppressRepeated).isEmpty()) {