aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--setup/default.xml8
-rw-r--r--src/org/traccar/BasePipelineFactory.java25
-rw-r--r--src/org/traccar/events/FuelDropEventHandler.java60
-rw-r--r--src/org/traccar/model/Event.java1
4 files changed, 70 insertions, 24 deletions
diff --git a/setup/default.xml b/setup/default.xml
index 971d923a8..e369ad9f0 100644
--- a/setup/default.xml
+++ b/setup/default.xml
@@ -18,14 +18,6 @@
<entry key='logger.file'>./logs/tracker-server.log</entry>
<entry key='event.enable'>true</entry>
- <entry key='event.overspeedHandler'>true</entry>
- <entry key='event.overspeed.notRepeat'>true</entry>
- <entry key='event.motionHandler'>true</entry>
- <entry key='event.geofenceHandler'>true</entry>
- <entry key='event.alertHandler'>true</entry>
- <entry key='event.ignitionHandler'>true</entry>
- <entry key='event.statusHandler'>true</entry>
- <entry key='event.maintenanceHandler'>true</entry>
<!-- DATABASE CONFIG -->
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index 33f778885..620c4729a 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -30,6 +30,7 @@ import org.jboss.netty.channel.SimpleChannelHandler;
import org.jboss.netty.handler.logging.LoggingHandler;
import org.jboss.netty.handler.timeout.IdleStateHandler;
import org.traccar.events.CommandResultEventHandler;
+import org.traccar.events.FuelDropEventHandler;
import org.traccar.events.GeofenceEventHandler;
import org.traccar.events.IgnitionEventHandler;
import org.traccar.events.MaintenanceEventHandler;
@@ -55,6 +56,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
private CommandResultEventHandler commandResultEventHandler;
private OverspeedEventHandler overspeedEventHandler;
+ private FuelDropEventHandler fuelDropEventHandler;
private MotionEventHandler motionEventHandler;
private GeofenceEventHandler geofenceEventHandler;
private AlertEventHandler alertEventHandler;
@@ -153,25 +155,12 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
if (Context.getConfig().getBoolean("event.enable")) {
commandResultEventHandler = new CommandResultEventHandler();
-
- if (Context.getConfig().getBoolean("event.overspeedHandler")) {
- overspeedEventHandler = new OverspeedEventHandler();
- }
-
- if (Context.getConfig().getBoolean("event.motionHandler")) {
- motionEventHandler = new MotionEventHandler();
- }
- }
- if (Context.getConfig().getBoolean("event.geofenceHandler")) {
+ overspeedEventHandler = new OverspeedEventHandler();
+ fuelDropEventHandler = new FuelDropEventHandler();
+ motionEventHandler = new MotionEventHandler();
geofenceEventHandler = new GeofenceEventHandler();
- }
- if (Context.getConfig().getBoolean("event.alertHandler")) {
alertEventHandler = new AlertEventHandler();
- }
- if (Context.getConfig().getBoolean("event.ignitionHandler")) {
ignitionEventHandler = new IgnitionEventHandler();
- }
- if (Context.getConfig().getBoolean("event.maintenanceHandler")) {
maintenanceEventHandler = new MaintenanceEventHandler();
}
}
@@ -236,6 +225,10 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
pipeline.addLast("OverspeedEventHandler", overspeedEventHandler);
}
+ if (fuelDropEventHandler != null) {
+ pipeline.addLast("FuelDropEventHandler", fuelDropEventHandler);
+ }
+
if (motionEventHandler != null) {
pipeline.addLast("MotionEventHandler", motionEventHandler);
}
diff --git a/src/org/traccar/events/FuelDropEventHandler.java b/src/org/traccar/events/FuelDropEventHandler.java
new file mode 100644
index 000000000..dfdbf7d7a
--- /dev/null
+++ b/src/org/traccar/events/FuelDropEventHandler.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.traccar.events;
+
+import org.traccar.BaseEventHandler;
+import org.traccar.Context;
+import org.traccar.model.Device;
+import org.traccar.model.Event;
+import org.traccar.model.Position;
+
+import java.util.Collection;
+import java.util.Collections;
+
+public class FuelDropEventHandler extends BaseEventHandler {
+
+ public static final String ATTRIBUTE_FUEL_DROP_THRESHOLD = "fuelDropThreshold";
+
+ @Override
+ protected Collection<Event> analyzePosition(Position position) {
+
+ Device device = Context.getIdentityManager().getDeviceById(position.getDeviceId());
+ if (device == null) {
+ return null;
+ }
+ if (!Context.getIdentityManager().isLatestPosition(position) || !position.getValid()) {
+ return null;
+ }
+
+ double fuelDropThreshold = Context.getDeviceManager()
+ .lookupAttributeDouble(device.getId(), ATTRIBUTE_FUEL_DROP_THRESHOLD, 0, false);
+
+ Position lastPosition = Context.getIdentityManager().getLastPosition(position.getDeviceId());
+ if (position.getAttributes().containsKey(Position.KEY_FUEL_LEVEL)
+ && lastPosition != null && lastPosition.getAttributes().containsKey(Position.KEY_FUEL_LEVEL)) {
+
+ double drop = lastPosition.getDouble(Position.KEY_FUEL_LEVEL) - position.getDouble(Position.KEY_FUEL_LEVEL);
+ if (drop >= fuelDropThreshold) {
+ Event event = new Event(Event.TYPE_DEVICE_FUEL_DROP, position.getDeviceId(), position.getId());
+ event.set(ATTRIBUTE_FUEL_DROP_THRESHOLD, fuelDropThreshold);
+ return Collections.singleton(event);
+ }
+ }
+
+ return null;
+ }
+
+}
diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java
index 96b371896..6a24d91c6 100644
--- a/src/org/traccar/model/Event.java
+++ b/src/org/traccar/model/Event.java
@@ -47,6 +47,7 @@ public class Event extends Message {
public static final String TYPE_DEVICE_STOPPED = "deviceStopped";
public static final String TYPE_DEVICE_OVERSPEED = "deviceOverspeed";
+ public static final String TYPE_DEVICE_FUEL_DROP = "deviceFuelDrop";
public static final String TYPE_GEOFENCE_ENTER = "geofenceEnter";
public static final String TYPE_GEOFENCE_EXIT = "geofenceExit";