aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/Main.java4
-rw-r--r--src/org/traccar/WebDataHandler.java4
-rw-r--r--src/org/traccar/database/DataManager.java1
-rw-r--r--src/org/traccar/protocol/H02ProtocolDecoder.java28
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolDecoder.java69
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java5
-rw-r--r--src/org/traccar/protocol/TytanProtocolDecoder.java14
-rw-r--r--src/org/traccar/protocol/UlbotechProtocolDecoder.java4
-rw-r--r--src/org/traccar/web/CommandServlet.java15
-rw-r--r--src/org/traccar/web/ConsoleServlet.java52
-rw-r--r--src/org/traccar/web/WebServer.java13
11 files changed, 150 insertions, 59 deletions
diff --git a/src/org/traccar/Main.java b/src/org/traccar/Main.java
index a51fa80bf..7ff93fda6 100644
--- a/src/org/traccar/Main.java
+++ b/src/org/traccar/Main.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012 - 2013 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2012 - 2015 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.
@@ -34,11 +34,11 @@ public final class Main {
Context.getWebServer().start();
}
- // Shutdown server properly
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
Log.info("Shutting down server...");
+
if (Context.getWebServer() != null) {
Context.getWebServer().stop();
}
diff --git a/src/org/traccar/WebDataHandler.java b/src/org/traccar/WebDataHandler.java
index 332fc5222..f40d49a6d 100644
--- a/src/org/traccar/WebDataHandler.java
+++ b/src/org/traccar/WebDataHandler.java
@@ -101,8 +101,8 @@ public class WebDataHandler extends BaseDataHandler {
.replace("{protocol}", String.valueOf(position.getProtocol()))
.replace("{deviceTime}", String.valueOf(position.getDeviceTime().getTime()))
.replace("{fixTime}", String.valueOf(position.getFixTime().getTime()))
- .replace("{valid}", String.valueOf(position.getLatitude()))
- .replace("{latitude}", String.valueOf(position.getValid()))
+ .replace("{valid}", String.valueOf(position.getValid()))
+ .replace("{latitude}", String.valueOf(position.getLatitude()))
.replace("{longitude}", String.valueOf(position.getLongitude()))
.replace("{altitude}", String.valueOf(position.getAltitude()))
.replace("{speed}", String.valueOf(position.getSpeed()))
diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java
index c98a5ede7..31d7155d3 100644
--- a/src/org/traccar/database/DataManager.java
+++ b/src/org/traccar/database/DataManager.java
@@ -103,6 +103,7 @@ public class DataManager implements IdentityManager {
ds.setPassword(config.getString("database.password"));
ds.setIdleConnectionTestPeriod(600);
ds.setTestConnectionOnCheckin(true);
+ ds.setMaxStatementsPerConnection(config.getInteger("database.maxStatements"));
int maxPoolSize = config.getInteger("database.maxPoolSize");
if (maxPoolSize != 0) {
ds.setMaxPoolSize(maxPoolSize);
diff --git a/src/org/traccar/protocol/H02ProtocolDecoder.java b/src/org/traccar/protocol/H02ProtocolDecoder.java
index d245fbdc8..31bdd9aa9 100644
--- a/src/org/traccar/protocol/H02ProtocolDecoder.java
+++ b/src/org/traccar/protocol/H02ProtocolDecoder.java
@@ -122,9 +122,17 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
.any()
.number("(dd)(dd)(dd),") // time
.expression("([AV])?,") // validity
- .number("-?(d+)-?(dd.d+),") // latitude
+ .groupBegin()
+ .number("(d+)(dd.d+),") // latitude
+ .or()
+ .number("-(d+)-(d+.d+),") // latitude
+ .groupEnd()
.expression("([NS]),")
- .number("-?(d+)-?(dd.d+),") // longitude
+ .groupBegin()
+ .number("(d+)(dd.d+),") // longitude
+ .or()
+ .number("-(d+)-(d+.d+),") // longitude
+ .groupEnd()
.expression("([EW]),")
.number("(d+.?d*),") // speed
.number("(d+.?d*)?,") // course
@@ -155,8 +163,20 @@ public class H02ProtocolDecoder extends BaseProtocolDecoder {
position.setValid(parser.next().equals("A"));
}
- position.setLatitude(parser.nextCoordinate());
- position.setLongitude(parser.nextCoordinate());
+ if (parser.hasNext(2)) {
+ position.setLatitude(parser.nextCoordinate());
+ }
+ if (parser.hasNext(2)) {
+ position.setLatitude(parser.nextCoordinate());
+ }
+
+ if (parser.hasNext(2)) {
+ position.setLongitude(parser.nextCoordinate());
+ }
+ if (parser.hasNext(2)) {
+ position.setLongitude(parser.nextCoordinate());
+ }
+
position.setSpeed(parser.nextDouble());
position.setCourse(parser.nextDouble());
diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
index 2217b5ce4..e82425a54 100644
--- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -81,49 +81,54 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
long time = buf.readUnsignedInt() & 0x3fffffff;
time += 1167609600; // 2007-01-01 00:00:00
- position.setTime(new Date(time * 1000));
globalMask = buf.readUnsignedByte();
- if (!BitUtil.check(globalMask, 0)) {
- return null;
- }
+ if (BitUtil.check(globalMask, 0)) {
- int locationMask = buf.readUnsignedByte();
+ position.setTime(new Date(time * 1000));
- if (BitUtil.check(locationMask, 0)) {
- position.setLatitude(buf.readFloat());
- position.setLongitude(buf.readFloat());
- }
+ int locationMask = buf.readUnsignedByte();
- if (BitUtil.check(locationMask, 1)) {
- position.setAltitude(buf.readUnsignedShort());
- }
+ if (BitUtil.check(locationMask, 0)) {
+ position.setLatitude(buf.readFloat());
+ position.setLongitude(buf.readFloat());
+ }
- if (BitUtil.check(locationMask, 2)) {
- position.setCourse(buf.readUnsignedByte() * 360.0 / 256);
- }
+ if (BitUtil.check(locationMask, 1)) {
+ position.setAltitude(buf.readUnsignedShort());
+ }
- if (BitUtil.check(locationMask, 3)) {
- position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
- }
+ if (BitUtil.check(locationMask, 2)) {
+ position.setCourse(buf.readUnsignedByte() * 360.0 / 256);
+ }
- if (BitUtil.check(locationMask, 4)) {
- int satellites = buf.readUnsignedByte();
- position.set(Event.KEY_SATELLITES, satellites);
- position.setValid(satellites >= 3);
- }
+ if (BitUtil.check(locationMask, 3)) {
+ position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte()));
+ }
- if (BitUtil.check(locationMask, 5)) {
- position.set(Event.KEY_LAC, buf.readUnsignedShort());
- position.set(Event.KEY_CID, buf.readUnsignedShort());
- }
+ if (BitUtil.check(locationMask, 4)) {
+ int satellites = buf.readUnsignedByte();
+ position.set(Event.KEY_SATELLITES, satellites);
+ position.setValid(satellites >= 3);
+ }
- if (BitUtil.check(locationMask, 6)) {
- position.set(Event.KEY_GSM, buf.readUnsignedByte());
- }
+ if (BitUtil.check(locationMask, 5)) {
+ position.set(Event.KEY_LAC, buf.readUnsignedShort());
+ position.set(Event.KEY_CID, buf.readUnsignedShort());
+ }
+
+ if (BitUtil.check(locationMask, 6)) {
+ position.set(Event.KEY_GSM, buf.readUnsignedByte());
+ }
+
+ if (BitUtil.check(locationMask, 7)) {
+ position.set("operator", buf.readUnsignedInt());
+ }
+
+ } else {
+
+ getLastLocation(position, new Date(time * 1000));
- if (BitUtil.check(locationMask, 7)) {
- position.set("operator", buf.readUnsignedInt());
}
} else {
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
index 6fa4edb06..e8d0d210d 100644
--- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java
@@ -154,6 +154,11 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder {
}
position.setDeviceId(getDeviceId());
+ int alarm = sentence.indexOf("BO01");
+ if (alarm != -1) {
+ position.set(Event.KEY_ALARM, Integer.parseInt(sentence.substring(alarm + 4, alarm + 5)));
+ }
+
DateBuilder dateBuilder = new DateBuilder();
if (parser.next() == null) {
dateBuilder.setDate(parser.nextInt(), parser.nextInt(), parser.nextInt());
diff --git a/src/org/traccar/protocol/TytanProtocolDecoder.java b/src/org/traccar/protocol/TytanProtocolDecoder.java
index b0c1d243b..40861bacb 100644
--- a/src/org/traccar/protocol/TytanProtocolDecoder.java
+++ b/src/org/traccar/protocol/TytanProtocolDecoder.java
@@ -18,10 +18,8 @@ package org.traccar.protocol;
import java.net.SocketAddress;
import java.nio.charset.Charset;
import java.util.Date;
-import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
-import java.util.Set;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
@@ -81,16 +79,8 @@ public class TytanProtocolDecoder extends BaseProtocolDecoder {
position.set("authorized", ChannelBuffers.hexDump(buf.readBytes(8)));
break;
case 24:
- Set<Integer> temps = new LinkedHashSet<>();
- int temp = buf.readUnsignedByte();
- for (int i = 3; i >= 0; i--) {
- n = (temp >> (2 * i)) & 0x03;
- if (!temps.contains(n)) {
- temps.add(n);
- }
- }
- for (int i : temps) {
- position.set(Event.PREFIX_TEMP + i, buf.readUnsignedByte());
+ for (int i = 0; i < length / 2; i++) {
+ position.set(Event.PREFIX_TEMP + buf.readUnsignedByte(), buf.readByte());
}
break;
case 28:
diff --git a/src/org/traccar/protocol/UlbotechProtocolDecoder.java b/src/org/traccar/protocol/UlbotechProtocolDecoder.java
index 5d882ffd8..dd6fb1593 100644
--- a/src/org/traccar/protocol/UlbotechProtocolDecoder.java
+++ b/src/org/traccar/protocol/UlbotechProtocolDecoder.java
@@ -204,7 +204,9 @@ public class UlbotechProtocolDecoder extends BaseProtocolDecoder {
case DATA_EVENT:
position.set(Event.KEY_EVENT, buf.readUnsignedByte());
- position.set("event-mask", buf.readUnsignedInt());
+ if (length > 1) {
+ position.set("event-mask", buf.readUnsignedInt());
+ }
break;
default:
diff --git a/src/org/traccar/web/CommandServlet.java b/src/org/traccar/web/CommandServlet.java
index be2d50ccc..d307913df 100644
--- a/src/org/traccar/web/CommandServlet.java
+++ b/src/org/traccar/web/CommandServlet.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2015 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.web;
import javax.json.Json;
diff --git a/src/org/traccar/web/ConsoleServlet.java b/src/org/traccar/web/ConsoleServlet.java
new file mode 100644
index 000000000..b219eaba4
--- /dev/null
+++ b/src/org/traccar/web/ConsoleServlet.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2015 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.web;
+
+import org.h2.server.web.ConnectionInfo;
+import org.h2.server.web.WebServlet;
+import org.traccar.Context;
+import org.traccar.helper.Log;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+public class ConsoleServlet extends WebServlet {
+
+ @Override
+ public void init() {
+ super.init();
+
+ try {
+ Field field = WebServlet.class.getDeclaredField("server");
+ field.setAccessible(true);
+ org.h2.server.web.WebServer server = (org.h2.server.web.WebServer) field.get(this);
+
+ ConnectionInfo connectionInfo = new ConnectionInfo("Traccar|"
+ + Context.getConfig().getString("database.driver") + "|"
+ + Context.getConfig().getString("database.url") + "|"
+ + Context.getConfig().getString("database.user"));
+
+ Method method = org.h2.server.web.WebServer.class.getDeclaredMethod("updateSetting", ConnectionInfo.class);
+ method.setAccessible(true);
+ method.invoke(server, connectionInfo);
+
+ } catch (NoSuchFieldException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
+ Log.warning(e);
+ }
+ }
+
+}
diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java
index 146dee613..0f9bf8181 100644
--- a/src/org/traccar/web/WebServer.java
+++ b/src/org/traccar/web/WebServer.java
@@ -61,6 +61,9 @@ public class WebServer {
break;
case "new":
initApi();
+ if (config.getBoolean("web.console")) {
+ initConsole();
+ }
initWebApp();
break;
case "old":
@@ -118,12 +121,10 @@ public class WebServer {
handlers.addHandler(servletHandler);
}
- private void initRestApi() {
- ResourceConfig resourceConfig = new ResourceConfig();
- resourceConfig.packages("org.traccar.api");
- ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
- ServletHolder servletHolder = new ServletHolder(new ServletContainer(resourceConfig));
- servletHandler.addServlet(servletHolder, "/rest/*");
+ private void initConsole() {
+ ServletContextHandler servletHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
+ servletHandler.setContextPath("/console");
+ servletHandler.addServlet(new ServletHolder(new ConsoleServlet()), "/*");
handlers.addHandler(servletHandler);
}