aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/BasePipelineFactory.java9
-rw-r--r--src/org/traccar/Main.java17
-rw-r--r--src/org/traccar/database/DataManager.java26
-rw-r--r--src/org/traccar/events/AlertEventHandler.java38
-rw-r--r--src/org/traccar/model/Event.java2
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java16
-rw-r--r--src/org/traccar/web/WebServer.java3
7 files changed, 109 insertions, 2 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index 44f1b0657..31845290f 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -33,6 +33,7 @@ import org.traccar.events.CommandResultEventHandler;
import org.traccar.events.GeofenceEventHandler;
import org.traccar.events.MotionEventHandler;
import org.traccar.events.OverspeedEventHandler;
+import org.traccar.events.AlertEventHandler;
import org.traccar.helper.Log;
import java.net.InetSocketAddress;
@@ -52,6 +53,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
private OverspeedEventHandler overspeedEventHandler;
private MotionEventHandler motionEventHandler;
private GeofenceEventHandler geofenceEventHandler;
+ private AlertEventHandler alertEventHandler;
private static final class OpenChannelHandler extends SimpleChannelHandler {
@@ -146,6 +148,9 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
if (Context.getConfig().getBoolean("event.geofenceHandler")) {
geofenceEventHandler = new GeofenceEventHandler();
}
+ if (Context.getConfig().getBoolean("event.alertHandler")) {
+ alertEventHandler = new AlertEventHandler();
+ }
}
protected abstract void addSpecificHandlers(ChannelPipeline pipeline);
@@ -207,6 +212,10 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
pipeline.addLast("GeofenceEventHandler", geofenceEventHandler);
}
+ if (alertEventHandler != null) {
+ pipeline.addLast("AlertEventHandler", alertEventHandler);
+ }
+
pipeline.addLast("mainHandler", new MainEventHandler());
return pipeline;
}
diff --git a/src/org/traccar/Main.java b/src/org/traccar/Main.java
index 1b8d93e34..570becc2d 100644
--- a/src/org/traccar/Main.java
+++ b/src/org/traccar/Main.java
@@ -17,9 +17,14 @@ package org.traccar;
import org.traccar.helper.Log;
+import java.sql.SQLException;
+import java.util.Timer;
+import java.util.TimerTask;
import java.util.Locale;
public final class Main {
+ static final long CLEAN_DELAY = 500;
+ static final long CLEAN_PERIOD = 24 * 60 * 60 * 1000;
private Main() {
}
@@ -35,6 +40,18 @@ public final class Main {
Context.getWebServer().start();
}
+ Timer timer = new Timer();
+ timer.scheduleAtFixedRate(new TimerTask() {
+ @Override
+ public void run() {
+ try {
+ Context.getDataManager().clearPositionsHistory();
+ } catch (SQLException error) {
+ Log.warning(error);
+ }
+ }
+ }, CLEAN_DELAY, CLEAN_PERIOD);
+
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index be77a3d36..04d0d44ea 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -304,6 +304,32 @@ public class DataManager {
.executeQuery(Position.class);
}
+ public void clearPositionsHistory() throws SQLException {
+ int histDays = config.getInteger("database.positionsHistoryDays");
+ if (histDays == 0) {
+ return;
+ }
+
+ String sql = getQuery("database.clearPositionsHistory");
+ if (sql == null) {
+ return;
+ }
+
+ for (Device device : getAllDevices()) {
+ Date lastUpdate = device.getLastUpdate();
+ if (lastUpdate != null) {
+
+ Date dateBefore = new Date(lastUpdate.getTime() - histDays * 24 * 3600 * 1000);
+
+ QueryBuilder.create(dataSource, sql)
+ .setLong("positionId", device.getPositionId())
+ .setLong("deviceId", device.getId())
+ .setDate("serverTime", dateBefore)
+ .executeUpdate();
+ }
+ }
+ }
+
public Server getServer() throws SQLException {
return QueryBuilder.create(dataSource, getQuery("database.selectServers"))
.executeQuerySingle(Server.class);
diff --git a/src/org/traccar/events/AlertEventHandler.java b/src/org/traccar/events/AlertEventHandler.java
new file mode 100644
index 000000000..61c2d7b16
--- /dev/null
+++ b/src/org/traccar/events/AlertEventHandler.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com)
+ *
+ * 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 java.util.ArrayList;
+import java.util.Collection;
+
+import org.traccar.BaseEventHandler;
+import org.traccar.model.Event;
+import org.traccar.model.Position;
+
+public class AlertEventHandler extends BaseEventHandler {
+
+ @Override
+ protected Collection<Event> analyzePosition(Position position) {
+ Object alarm = position.getAttributes().get(Position.KEY_ALARM);
+ if (alarm != null) {
+ Collection<Event> events = new ArrayList<>();
+ events.add(new Event(Event.TYPE_ALARM, position.getDeviceId(), position.getId()));
+ return events;
+ }
+ return null;
+ }
+
+}
diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java
index 235a39f9a..a2c346688 100644
--- a/src/org/traccar/model/Event.java
+++ b/src/org/traccar/model/Event.java
@@ -48,6 +48,8 @@ public class Event extends Message {
public static final String TYPE_GEOFENCE_ENTER = "geofenceEnter";
public static final String TYPE_GEOFENCE_EXIT = "geofenceExit";
+ public static final String TYPE_ALARM = "alarm";
+
private Date serverTime;
public Date getServerTime() {
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index b340973e6..83ed4b099 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -65,8 +65,20 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
private void processStatus(Position position, long status) {
if (!BitUtil.check(status, 0) || !BitUtil.check(status, 1)
- || !BitUtil.check(status, 3) || !BitUtil.check(status, 4)) {
- position.set(Position.KEY_ALARM, true);
+ || !BitUtil.check(status, 3) || !BitUtil.check(status, 4) || !BitUtil.check(status, 7)) {
+
+ if (!BitUtil.check(status, 0)) {
+ position.set(Position.KEY_ALARM, Position.ALARM_VIBRATION);
+ } else if (!BitUtil.check(status, 1)) {
+ position.set(Position.KEY_ALARM, "robbery");
+ } else if (!BitUtil.check(status, 3)) {
+ position.set(Position.KEY_ALARM, "illegal ignition");
+ } else if (!BitUtil.check(status, 4)) {
+ position.set(Position.KEY_ALARM, "entering");
+ } else if (!BitUtil.check(status, 7)) {
+ position.set(Position.KEY_ALARM, "out");
+ }
+
}
position.set(Position.KEY_IGNITION, !BitUtil.check(status, 10));
position.set(Position.KEY_STATUS, status);
diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java
index 5527e80f3..4ef31b1df 100644
--- a/src/org/traccar/web/WebServer.java
+++ b/src/org/traccar/web/WebServer.java
@@ -118,6 +118,9 @@ public class WebServer {
resourceHandler.setResourceBase(config.getString("web.path"));
if (config.getBoolean("web.debug")) {
resourceHandler.setWelcomeFiles(new String[] {"debug.html"});
+ //Troubleshooting Locked UI Files on Windows while app is running (like html, js, css, etc...),
+ //you can make changes to the UI Files and refresh the page in the browser without stopping the app first
+ resourceHandler.setMinMemoryMappedContentLength(-1);
} else {
resourceHandler.setWelcomeFiles(new String[] {"release.html", "index.html"});
}