aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--debug.xml2
-rw-r--r--src/org/traccar/events/OverspeedEventHandler.java41
2 files changed, 39 insertions, 4 deletions
diff --git a/debug.xml b/debug.xml
index f078a7e9d..bd55b7ee1 100644
--- a/debug.xml
+++ b/debug.xml
@@ -44,7 +44,7 @@
<entry key='event.enable'>true</entry>
<entry key='event.suppressRepeated'>60</entry>
<entry key='event.overspeedHandler'>true</entry>
- <entry key='event.globalSpeedLimit'>90</entry>
+ <entry key='event.overspeed.groupsEnabled'>true</entry>
<entry key='event.motionHandler'>true</entry>
<entry key='event.geofenceHandler'>true</entry>
<entry key='event.alertHandler'>true</entry>
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()) {