aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/handler
diff options
context:
space:
mode:
authorjcardus <asklocation.net@gmail.com>2022-10-26 14:48:31 +0100
committerGitHub <noreply@github.com>2022-10-26 14:48:31 +0100
commit8ceb20c2d9c70f5e0aa107095a23c187019401f1 (patch)
tree2e4e411a6c9d6b26f6841639cffdfaf931d54255 /src/main/java/org/traccar/handler
parent78a0df7befc84b7d138b403b137f26f9df379c3d (diff)
downloadtrackermap-server-8ceb20c2d9c70f5e0aa107095a23c187019401f1.tar.gz
trackermap-server-8ceb20c2d9c70f5e0aa107095a23c187019401f1.tar.bz2
trackermap-server-8ceb20c2d9c70f5e0aa107095a23c187019401f1.zip
2 Bugs on maintenance
According to the documentation: "Traccar can help control maintenance intervals of devices. There are two attributes to configure: maintenance.start and maintenance.interval. They can be set in device, group or server attributes. Traccar generates event every time totalDistance attribute gets over maintenance.start + maintenance.interval * N value where N is a natural number. Example: maintenance.start=6000000, maintenance.interval=8000000 Events will be generated when totalDistance goes over 6000 km, 14000 km, 22000 km and so on." In this example, the event won't be fired when it goes over 6000 km. If maintenance.interval < maintenance.start and maintenance.start is multiple of maintenance.interval then the event will be fired before maintenance.start because the comparison will be on negative numbers. Another solution would be to use absolute numbers on the comparison. Example: maintenance.start = 10 000 000 maintenance.interval = 2 000 000 the event will be fired when it goes over 2 000 000 the event wont' be fired when it goes over 10 000 000
Diffstat (limited to 'src/main/java/org/traccar/handler')
-rw-r--r--src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java b/src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java
index 4fcfcd079..25a622373 100644
--- a/src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java
+++ b/src/main/java/org/traccar/handler/events/MaintenanceEventHandler.java
@@ -51,13 +51,15 @@ public class MaintenanceEventHandler extends BaseEventHandler {
if (maintenance.getPeriod() != 0) {
double oldValue = lastPosition.getDouble(maintenance.getType());
double newValue = position.getDouble(maintenance.getType());
- if (oldValue != 0.0 && newValue != 0.0
- && (long) ((oldValue - maintenance.getStart()) / maintenance.getPeriod())
+ if (oldValue != 0.0 && newValue != 0.0 && newValue >= maintenance.getStart()) {
+ if (oldValue < maintenance.getStart()
+ || (long) ((oldValue - maintenance.getStart()) / maintenance.getPeriod())
< (long) ((newValue - maintenance.getStart()) / maintenance.getPeriod())) {
- Event event = new Event(Event.TYPE_MAINTENANCE, position);
- event.setMaintenanceId(maintenance.getId());
- event.set(maintenance.getType(), newValue);
- events.put(event, position);
+ Event event = new Event(Event.TYPE_MAINTENANCE, position);
+ event.setMaintenanceId(maintenance.getId());
+ event.set(maintenance.getType(), newValue);
+ events.put(event, position);
+ }
}
}
}