diff options
Diffstat (limited to 'src/org/traccar/events')
-rw-r--r-- | src/org/traccar/events/AlertEventHandler.java | 2 | ||||
-rw-r--r-- | src/org/traccar/events/CommandResultEventHandler.java | 2 | ||||
-rw-r--r-- | src/org/traccar/events/DriverEventHandler.java | 2 | ||||
-rw-r--r-- | src/org/traccar/events/FuelDropEventHandler.java | 2 | ||||
-rw-r--r-- | src/org/traccar/events/GeofenceEventHandler.java | 2 | ||||
-rw-r--r-- | src/org/traccar/events/IgnitionEventHandler.java | 2 | ||||
-rw-r--r-- | src/org/traccar/events/MaintenanceEventHandler.java | 57 | ||||
-rw-r--r-- | src/org/traccar/events/MotionEventHandler.java | 2 | ||||
-rw-r--r-- | src/org/traccar/events/OverspeedEventHandler.java | 43 |
9 files changed, 79 insertions, 35 deletions
diff --git a/src/org/traccar/events/AlertEventHandler.java b/src/org/traccar/events/AlertEventHandler.java index 7db371c70..b14869e72 100644 --- a/src/org/traccar/events/AlertEventHandler.java +++ b/src/org/traccar/events/AlertEventHandler.java @@ -18,11 +18,13 @@ package org.traccar.events; import java.util.Collections; import java.util.Map; +import io.netty.channel.ChannelHandler; import org.traccar.BaseEventHandler; import org.traccar.Context; import org.traccar.model.Event; import org.traccar.model.Position; +@ChannelHandler.Sharable public class AlertEventHandler extends BaseEventHandler { private final boolean ignoreDuplicateAlerts; diff --git a/src/org/traccar/events/CommandResultEventHandler.java b/src/org/traccar/events/CommandResultEventHandler.java index 775aa903f..89ec44190 100644 --- a/src/org/traccar/events/CommandResultEventHandler.java +++ b/src/org/traccar/events/CommandResultEventHandler.java @@ -18,10 +18,12 @@ package org.traccar.events; import java.util.Collections; import java.util.Map; +import io.netty.channel.ChannelHandler; import org.traccar.BaseEventHandler; import org.traccar.model.Event; import org.traccar.model.Position; +@ChannelHandler.Sharable public class CommandResultEventHandler extends BaseEventHandler { @Override diff --git a/src/org/traccar/events/DriverEventHandler.java b/src/org/traccar/events/DriverEventHandler.java index 39b8eb9c0..c8efd0576 100644 --- a/src/org/traccar/events/DriverEventHandler.java +++ b/src/org/traccar/events/DriverEventHandler.java @@ -19,11 +19,13 @@ package org.traccar.events; import java.util.Collections; import java.util.Map; +import io.netty.channel.ChannelHandler; import org.traccar.BaseEventHandler; import org.traccar.Context; import org.traccar.model.Event; import org.traccar.model.Position; +@ChannelHandler.Sharable public class DriverEventHandler extends BaseEventHandler { @Override diff --git a/src/org/traccar/events/FuelDropEventHandler.java b/src/org/traccar/events/FuelDropEventHandler.java index 2ee3e1a58..31b17d500 100644 --- a/src/org/traccar/events/FuelDropEventHandler.java +++ b/src/org/traccar/events/FuelDropEventHandler.java @@ -15,6 +15,7 @@ */ package org.traccar.events; +import io.netty.channel.ChannelHandler; import org.traccar.BaseEventHandler; import org.traccar.Context; import org.traccar.model.Device; @@ -24,6 +25,7 @@ import org.traccar.model.Position; import java.util.Collections; import java.util.Map; +@ChannelHandler.Sharable public class FuelDropEventHandler extends BaseEventHandler { public static final String ATTRIBUTE_FUEL_DROP_THRESHOLD = "fuelDropThreshold"; diff --git a/src/org/traccar/events/GeofenceEventHandler.java b/src/org/traccar/events/GeofenceEventHandler.java index 31d82a81e..ea379dbdb 100644 --- a/src/org/traccar/events/GeofenceEventHandler.java +++ b/src/org/traccar/events/GeofenceEventHandler.java @@ -20,6 +20,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import io.netty.channel.ChannelHandler; import org.traccar.BaseEventHandler; import org.traccar.Context; import org.traccar.database.GeofenceManager; @@ -28,6 +29,7 @@ import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; +@ChannelHandler.Sharable public class GeofenceEventHandler extends BaseEventHandler { private GeofenceManager geofenceManager; diff --git a/src/org/traccar/events/IgnitionEventHandler.java b/src/org/traccar/events/IgnitionEventHandler.java index cc53b216c..a17f15318 100644 --- a/src/org/traccar/events/IgnitionEventHandler.java +++ b/src/org/traccar/events/IgnitionEventHandler.java @@ -19,12 +19,14 @@ package org.traccar.events; import java.util.Collections; import java.util.Map; +import io.netty.channel.ChannelHandler; import org.traccar.BaseEventHandler; import org.traccar.Context; import org.traccar.model.Device; import org.traccar.model.Event; import org.traccar.model.Position; +@ChannelHandler.Sharable public class IgnitionEventHandler extends BaseEventHandler { @Override diff --git a/src/org/traccar/events/MaintenanceEventHandler.java b/src/org/traccar/events/MaintenanceEventHandler.java index 86abf7c17..5bebb1baf 100644 --- a/src/org/traccar/events/MaintenanceEventHandler.java +++ b/src/org/traccar/events/MaintenanceEventHandler.java @@ -1,6 +1,6 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) - * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org) + * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2018 Andrey Kunitsyn (andrey@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,54 +16,49 @@ */ package org.traccar.events; -import java.util.Collections; +import java.util.HashMap; import java.util.Map; +import io.netty.channel.ChannelHandler; import org.traccar.BaseEventHandler; import org.traccar.Context; -import org.traccar.model.Device; import org.traccar.model.Event; +import org.traccar.model.Maintenance; import org.traccar.model.Position; +@ChannelHandler.Sharable public class MaintenanceEventHandler extends BaseEventHandler { - public static final String ATTRIBUTE_MAINTENANCE_START = "maintenance.start"; - public static final String ATTRIBUTE_MAINTENANCE_INTERVAL = "maintenance.interval"; - @Override protected Map<Event, Position> analyzePosition(Position position) { - Device device = Context.getIdentityManager().getById(position.getDeviceId()); - if (device == null || !Context.getIdentityManager().isLatestPosition(position)) { - return null; - } - - double maintenanceInterval = Context.getDeviceManager() - .lookupAttributeDouble(device.getId(), ATTRIBUTE_MAINTENANCE_INTERVAL, 0, false); - if (maintenanceInterval == 0) { + if (Context.getIdentityManager().getById(position.getDeviceId()) == null + || !Context.getIdentityManager().isLatestPosition(position)) { return null; } - double maintenanceStart = Context.getDeviceManager() - .lookupAttributeDouble(device.getId(), ATTRIBUTE_MAINTENANCE_START, 0, false); - - double oldTotalDistance = 0.0; - double newTotalDistance = 0.0; Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId()); - if (lastPosition != null) { - oldTotalDistance = lastPosition.getDouble(Position.KEY_TOTAL_DISTANCE); + if (lastPosition == null) { + return null; } - newTotalDistance = position.getDouble(Position.KEY_TOTAL_DISTANCE); - - oldTotalDistance -= maintenanceStart; - newTotalDistance -= maintenanceStart; - if ((long) (oldTotalDistance / maintenanceInterval) < (long) (newTotalDistance / maintenanceInterval)) { - Event event = new Event(Event.TYPE_MAINTENANCE, position.getDeviceId(), position.getId()); - event.set(Position.KEY_TOTAL_DISTANCE, newTotalDistance); - return Collections.singletonMap(event, position); + Map<Event, Position> events = new HashMap<>(); + for (long maintenanceId : Context.getMaintenancesManager().getAllDeviceItems(position.getDeviceId())) { + Maintenance maintenance = Context.getMaintenancesManager().getById(maintenanceId); + 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()) + < (long) ((newValue - maintenance.getStart()) / maintenance.getPeriod())) { + Event event = new Event(Event.TYPE_MAINTENANCE, position.getDeviceId(), position.getId()); + event.setMaintenanceId(maintenanceId); + event.set(maintenance.getType(), newValue); + events.put(event, position); + } + } } - return null; + return events; } } diff --git a/src/org/traccar/events/MotionEventHandler.java b/src/org/traccar/events/MotionEventHandler.java index 0c1c4848f..4047b83a4 100644 --- a/src/org/traccar/events/MotionEventHandler.java +++ b/src/org/traccar/events/MotionEventHandler.java @@ -19,6 +19,7 @@ package org.traccar.events; import java.util.Collections; import java.util.Map; +import io.netty.channel.ChannelHandler; import org.traccar.BaseEventHandler; import org.traccar.Context; import org.traccar.model.Device; @@ -28,6 +29,7 @@ import org.traccar.model.Position; import org.traccar.reports.ReportUtils; import org.traccar.reports.model.TripsConfig; +@ChannelHandler.Sharable public class MotionEventHandler extends BaseEventHandler { private TripsConfig tripsConfig; diff --git a/src/org/traccar/events/OverspeedEventHandler.java b/src/org/traccar/events/OverspeedEventHandler.java index cb658415c..4f9a35793 100644 --- a/src/org/traccar/events/OverspeedEventHandler.java +++ b/src/org/traccar/events/OverspeedEventHandler.java @@ -1,5 +1,6 @@ /* - * Copyright 2016 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2018 Andrey Kunitsyn (andrey@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,23 +19,28 @@ package org.traccar.events; import java.util.Collections; import java.util.Map; +import io.netty.channel.ChannelHandler; import org.traccar.BaseEventHandler; import org.traccar.Context; import org.traccar.model.Device; import org.traccar.model.DeviceState; import org.traccar.model.Event; +import org.traccar.model.Geofence; import org.traccar.model.Position; +@ChannelHandler.Sharable public class OverspeedEventHandler extends BaseEventHandler { public static final String ATTRIBUTE_SPEED_LIMIT = "speedLimit"; private boolean notRepeat; + private boolean preferLowest; private long minimalDuration; - public OverspeedEventHandler(long minimalDuration, boolean notRepeat) { + public OverspeedEventHandler(long minimalDuration, boolean notRepeat, boolean preferLowest) { this.notRepeat = notRepeat; this.minimalDuration = minimalDuration; + this.preferLowest = preferLowest; } private Map<Event, Position> newEvent(DeviceState deviceState, double speedLimit) { @@ -42,8 +48,10 @@ public class OverspeedEventHandler extends BaseEventHandler { Event event = new Event(Event.TYPE_DEVICE_OVERSPEED, position.getDeviceId(), position.getId()); event.set("speed", deviceState.getOverspeedPosition().getSpeed()); event.set(ATTRIBUTE_SPEED_LIMIT, speedLimit); + event.setGeofenceId(deviceState.getOverspeedGeofenceId()); deviceState.setOverspeedState(notRepeat); deviceState.setOverspeedPosition(null); + deviceState.setOverspeedGeofenceId(0); return Collections.singletonMap(event, position); } @@ -61,7 +69,8 @@ public class OverspeedEventHandler extends BaseEventHandler { return result; } - public Map<Event, Position> updateOverspeedState(DeviceState deviceState, Position position, double speedLimit) { + public Map<Event, Position> updateOverspeedState( + DeviceState deviceState, Position position, double speedLimit, long geofenceId) { Map<Event, Position> result = null; Boolean oldOverspeed = deviceState.getOverspeedState(); @@ -71,12 +80,15 @@ public class OverspeedEventHandler extends BaseEventHandler { if (newOverspeed && !oldOverspeed) { if (deviceState.getOverspeedPosition() == null) { deviceState.setOverspeedPosition(position); + deviceState.setOverspeedGeofenceId(geofenceId); } } else if (oldOverspeed && !newOverspeed) { deviceState.setOverspeedState(false); deviceState.setOverspeedPosition(null); + deviceState.setOverspeedGeofenceId(0); } else { deviceState.setOverspeedPosition(null); + deviceState.setOverspeedGeofenceId(0); } Position overspeedPosition = deviceState.getOverspeedPosition(); if (overspeedPosition != null) { @@ -101,6 +113,28 @@ public class OverspeedEventHandler extends BaseEventHandler { } double speedLimit = Context.getDeviceManager().lookupAttributeDouble(deviceId, ATTRIBUTE_SPEED_LIMIT, 0, false); + + double geofenceSpeedLimit = 0; + long overspeedGeofenceId = 0; + + if (Context.getGeofenceManager() != null && device.getGeofenceIds() != null) { + for (long geofenceId : device.getGeofenceIds()) { + Geofence geofence = Context.getGeofenceManager().getById(geofenceId); + if (geofence != null) { + double currentSpeedLimit = geofence.getDouble(ATTRIBUTE_SPEED_LIMIT); + if (currentSpeedLimit > 0 && geofenceSpeedLimit == 0 + || preferLowest && currentSpeedLimit < geofenceSpeedLimit + || !preferLowest && currentSpeedLimit > geofenceSpeedLimit) { + geofenceSpeedLimit = currentSpeedLimit; + overspeedGeofenceId = geofenceId; + } + } + } + } + if (geofenceSpeedLimit > 0) { + speedLimit = geofenceSpeedLimit; + } + if (speedLimit == 0) { return null; } @@ -110,8 +144,9 @@ public class OverspeedEventHandler extends BaseEventHandler { if (deviceState.getOverspeedState() == null) { deviceState.setOverspeedState(position.getSpeed() > speedLimit); + deviceState.setOverspeedGeofenceId(position.getSpeed() > speedLimit ? overspeedGeofenceId : 0); } else { - result = updateOverspeedState(deviceState, position, speedLimit); + result = updateOverspeedState(deviceState, position, speedLimit, overspeedGeofenceId); } Context.getDeviceManager().setDeviceState(deviceId, deviceState); |