aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/BasePipelineFactory.java5
-rw-r--r--src/org/traccar/Context.java7
-rw-r--r--src/org/traccar/WebDataHandler.java19
-rw-r--r--src/org/traccar/model/Server.java8
-rw-r--r--src/org/traccar/protocol/Gl200ProtocolDecoder.java31
-rw-r--r--src/org/traccar/protocol/MegastekProtocolDecoder.java119
-rw-r--r--src/org/traccar/protocol/MeiligaoProtocol.java5
-rw-r--r--src/org/traccar/protocol/MeitrackProtocol.java11
-rw-r--r--src/org/traccar/protocol/MeitrackProtocolEncoder.java40
-rw-r--r--src/org/traccar/protocol/TotemProtocolDecoder.java9
10 files changed, 169 insertions, 85 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java
index 216e48709..0dc0bbb47 100644
--- a/src/org/traccar/BasePipelineFactory.java
+++ b/src/org/traccar/BasePipelineFactory.java
@@ -34,7 +34,7 @@ import org.traccar.helper.Log;
public abstract class BasePipelineFactory implements ChannelPipelineFactory {
private final TrackerServer server;
- private int resetDelay;
+ private final int resetDelay;
private FilterHandler filterHandler;
private DistanceHandler distanceHandler;
@@ -54,9 +54,6 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory {
}
}
- /**
- * Logging using global logger
- */
protected class StandardLoggingHandler extends LoggingHandler {
@Override
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java
index d50a0c626..f818368d0 100644
--- a/src/org/traccar/Context.java
+++ b/src/org/traccar/Context.java
@@ -15,6 +15,7 @@
*/
package org.traccar;
+import com.ning.http.client.AsyncHttpClient;
import org.traccar.database.ConnectionManager;
import org.traccar.database.DataManager;
import org.traccar.database.IdentityManager;
@@ -81,6 +82,12 @@ public class Context {
public static ServerManager getServerManager() {
return serverManager;
}
+
+ private static final AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
+
+ public static AsyncHttpClient getAsyncHttpClient() {
+ return asyncHttpClient;
+ }
public static void init(String[] arguments) throws Exception {
diff --git a/src/org/traccar/WebDataHandler.java b/src/org/traccar/WebDataHandler.java
index 5e3626022..5f12b9c93 100644
--- a/src/org/traccar/WebDataHandler.java
+++ b/src/org/traccar/WebDataHandler.java
@@ -15,7 +15,6 @@
*/
package org.traccar;
-import com.ning.http.client.AsyncHttpClient;
import java.util.Calendar;
import java.util.Formatter;
import java.util.Locale;
@@ -62,16 +61,16 @@ public class WebDataHandler extends BaseDataHandler {
Device device = Context.getIdentityManager().getDeviceById(position.getDeviceId());
- String request = url.
- replace("{uniqueId}", device.getUniqueId()).
- replace("{deviceId}", String.valueOf(device.getId())).
- replace("{fixTime}", String.valueOf(position.getFixTime().getTime())).
- replace("{latitude}", String.valueOf(position.getLatitude())).
- replace("{longitude}", String.valueOf(position.getLongitude())).
- replace("{gprmc}", formatSentence(position));
+ String request = url
+ .replace("{uniqueId}", device.getUniqueId())
+ .replace("{deviceId}", String.valueOf(device.getId()))
+ .replace("{fixTime}", String.valueOf(position.getFixTime().getTime()))
+ .replace("{latitude}", String.valueOf(position.getLatitude()))
+ .replace("{longitude}", String.valueOf(position.getLongitude()))
+ .replace("{gprmc}", formatSentence(position))
+ .replace("{statusCode}", position.getSpeed() < 1.0 ? "0xF020" : "0xF11C");
- AsyncHttpClient asyncHttpClient = new AsyncHttpClient();
- asyncHttpClient.prepareGet(request).execute();
+ Context.getAsyncHttpClient().prepareGet(request).execute();
return position;
}
diff --git a/src/org/traccar/model/Server.java b/src/org/traccar/model/Server.java
index f5ad4887c..b910e30ec 100644
--- a/src/org/traccar/model/Server.java
+++ b/src/org/traccar/model/Server.java
@@ -34,6 +34,14 @@ public class Server implements Factory {
public String getMap() { return map; }
public void setMap(String map) { this.map = map; }
+ private String bingKey;
+ public String getBingKey() { return bingKey; }
+ public void setBingKey(String bingKey) { this.bingKey = bingKey; }
+
+ private String mapUrl;
+ public String getMapUrl() { return mapUrl; }
+ public void setMapUrl(String mapUrl) { this.mapUrl = mapUrl; }
+
private String language;
public String getLanguage() { return language; }
public void setLanguage(String language) { this.language = language; }
diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
index 3628730e3..38b1df1a6 100644
--- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
@@ -44,7 +44,30 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
"(?:\\x00?\\x04,\\p{XDigit}{4},[01],))" +
"GT...," +
"(?:[0-9A-Z]{2}\\p{XDigit}{4})?," + // Protocol version
- "([^,]+),.*," + // IMEI
+ "([^,]+)," + // IMEI
+
+ "(?:[0-9A-Z]{17}," + // VIN
+ "[^,]{0,20}," + // Device name
+ "[01]," + // Report type
+ "\\p{XDigit}{1,8}," + // Report mask
+ "[0-9A-Z]{17}," + // VIN
+ "[01]," + // ODB connect
+ "\\d{1,5}," + // ODB voltage
+ "\\p{XDigit}{8}," + // Support PIDs
+ "\\d{1,5}," + // Engine RPM
+ "\\d{1,3}," + // Speed
+ "-?\\d{1,3}," + // Coolant temp
+ "(\\d+\\.?\\d*|Inf|NaN)?," + // Fuel consumption
+ "\\d{1,5}," + // Odometer
+ "\\d{1,5}," +
+ "[01]," + // ODB connect
+ "\\d{1,3}," + // Number of DTCs
+ "\\p{XDigit}*," + // DTCs
+ "\\d{1,3}," + // Throttle
+ "\\d{1,3}," + // Engine load
+ "(\\d{1,3})?,"+ // Fuel level
+ "\\d+|.*)," + // Odometer
+
"(\\d*)," + // GPS accuracy
"(\\d+.\\d)?," + // Speed
"(\\d+)?," + // Course
@@ -58,7 +81,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
"(\\p{XDigit}{4}|\\p{XDigit}{8})?," + // LAC
"(\\p{XDigit}{4})?," + // Cell
"(?:(\\d+\\.\\d)?," + // Odometer
- "(\\d{1,3})?,)?" + // Battery
+ "(\\d{1,3})?,)?" + // Battery*/
".*," +
"(\\p{XDigit}{4})\\$?");
@@ -96,6 +119,10 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
}
position.setDeviceId(getDeviceId());
+ // Fuel
+ position.set("fuel-consumption", parser.group(index++));
+ position.set(Event.KEY_FUEL, parser.group(index++));
+
// Validity
position.setValid(Integer.valueOf(parser.group(index++)) < 20);
diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java
index 019bb69de..c07e73533 100644
--- a/src/org/traccar/protocol/MegastekProtocolDecoder.java
+++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java
@@ -20,9 +20,7 @@ import java.util.Calendar;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.jboss.netty.channel.Channel;
-
import org.traccar.BaseProtocolDecoder;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -44,7 +42,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
"(\\d+\\.\\d+)?," + // Speed
"(\\d+\\.\\d+)?," + // Course
"(\\d{2})(\\d{2})(\\d{2})" + // Date (DDMMYY)
- "[^\\*]+\\*[0-9a-fA-F]{2}"); // Checksum
+ ".*"); // Checksum
private static final Pattern patternSimple = Pattern.compile(
"[FL]," + // Flag
@@ -143,10 +141,18 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
id = sentence.substring(beginIndex, endIndex);
beginIndex = endIndex + 1;
- endIndex = sentence.indexOf('*', beginIndex) + 3;
+ endIndex = sentence.indexOf('*', beginIndex);
+ if (endIndex != -1) {
+ endIndex += 3;
+ } else {
+ endIndex = sentence.length();
+ }
gprmc = sentence.substring(beginIndex, endIndex);
beginIndex = endIndex + 1;
+ if (beginIndex > sentence.length()) {
+ beginIndex = endIndex;
+ }
status = sentence.substring(beginIndex);
} else {
@@ -175,78 +181,75 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder {
if (simple) {
- // Parse status
Matcher parser = patternSimple.matcher(status);
- if (!parser.matches()) {
- return null;
- }
+ if (parser.matches()) {
- int index = 1;
+ int index = 1;
- // Alarm
- position.set(Event.KEY_ALARM, parser.group(index++));
+ position.set(Event.KEY_ALARM, parser.group(index++));
- // IMEI
- if (!identify(parser.group(index++), channel, null, false)) {
- if (!identify(id, channel)) {
- return null;
+ // IMEI
+ if (!identify(parser.group(index++), channel, null, false)) {
+ if (!identify(id, channel)) {
+ return null;
+ }
}
- }
- position.setDeviceId(getDeviceId());
+ position.setDeviceId(getDeviceId());
- // Satellites
- position.set(Event.KEY_SATELLITES, parser.group(index++));
+ position.set(Event.KEY_SATELLITES, parser.group(index++));
- // Altitude
- String altitude = parser.group(index++);
- if (altitude != null) {
- position.setAltitude(Double.valueOf(altitude));
- }
+ String altitude = parser.group(index++);
+ if (altitude != null) {
+ position.setAltitude(Double.valueOf(altitude));
+ }
- // Battery
- position.set(Event.KEY_POWER, Double.valueOf(parser.group(index++)));
+ position.set(Event.KEY_POWER, Double.valueOf(parser.group(index++)));
- // Charger
- String charger = parser.group(index++);
- if (charger != null) {
- position.set(Event.KEY_CHARGE, Integer.valueOf(charger) == 1);
- }
+ String charger = parser.group(index++);
+ if (charger != null) {
+ position.set(Event.KEY_CHARGE, Integer.valueOf(charger) == 1);
+ }
- position.set(Event.KEY_MCC, parser.group(index++));
- position.set(Event.KEY_MNC, parser.group(index++));
- position.set(Event.KEY_LAC, parser.group(index++));
+ position.set(Event.KEY_MCC, parser.group(index++));
+ position.set(Event.KEY_MNC, parser.group(index++));
+ position.set(Event.KEY_LAC, parser.group(index++));
+
+ } else {
+
+ if (!identify(id, channel)) {
+ return null;
+ }
+ position.setDeviceId(getDeviceId());
+
+ }
} else {
- // Parse status
Matcher parser = patternAlternative.matcher(status);
if (!parser.matches()) {
- return null;
- }
- int index = 1;
+ int index = 1;
- if (!identify(id, channel)) {
- return null;
+ if (!identify(id, channel)) {
+ return null;
+ }
+ position.setDeviceId(getDeviceId());
+
+ position.set(Event.KEY_MCC, parser.group(index++));
+ position.set(Event.KEY_MNC, parser.group(index++));
+ position.set(Event.KEY_LAC, parser.group(index++));
+ position.set(Event.KEY_GSM, parser.group(index++));
+
+ position.set(Event.KEY_BATTERY, Double.valueOf(parser.group(index++)));
+
+ position.set(Event.KEY_FLAGS, parser.group(index++));
+ position.set(Event.KEY_INPUT, parser.group(index++));
+ position.set(Event.KEY_OUTPUT, parser.group(index++));
+ position.set(Event.PREFIX_ADC + 1, parser.group(index++));
+ position.set(Event.PREFIX_ADC + 2, parser.group(index++));
+ position.set(Event.PREFIX_ADC + 3, parser.group(index++));
+ position.set(Event.KEY_ALARM, parser.group(index++));
}
- position.setDeviceId(getDeviceId());
-
- position.set(Event.KEY_MCC, parser.group(index++));
- position.set(Event.KEY_MNC, parser.group(index++));
- position.set(Event.KEY_LAC, parser.group(index++));
- position.set(Event.KEY_GSM, parser.group(index++));
-
- // Battery
- position.set(Event.KEY_BATTERY, Double.valueOf(parser.group(index++)));
-
- position.set(Event.KEY_FLAGS, parser.group(index++));
- position.set(Event.KEY_INPUT, parser.group(index++));
- position.set(Event.KEY_OUTPUT, parser.group(index++));
- position.set(Event.PREFIX_ADC + 1, parser.group(index++));
- position.set(Event.PREFIX_ADC + 2, parser.group(index++));
- position.set(Event.PREFIX_ADC + 3, parser.group(index++));
- position.set(Event.KEY_ALARM, parser.group(index++));
-
}
return position;
diff --git a/src/org/traccar/protocol/MeiligaoProtocol.java b/src/org/traccar/protocol/MeiligaoProtocol.java
index 70c9a87ec..9e8da7dc2 100644
--- a/src/org/traccar/protocol/MeiligaoProtocol.java
+++ b/src/org/traccar/protocol/MeiligaoProtocol.java
@@ -15,16 +15,13 @@
*/
package org.traccar.protocol;
+import java.util.List;
import org.jboss.netty.bootstrap.ConnectionlessBootstrap;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelPipeline;
-import org.jboss.netty.handler.codec.string.StringDecoder;
-import org.jboss.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
import org.traccar.TrackerServer;
-import java.util.List;
-
public class MeiligaoProtocol extends BaseProtocol {
public MeiligaoProtocol() {
diff --git a/src/org/traccar/protocol/MeitrackProtocol.java b/src/org/traccar/protocol/MeitrackProtocol.java
index bcc224a94..6f452aa33 100644
--- a/src/org/traccar/protocol/MeitrackProtocol.java
+++ b/src/org/traccar/protocol/MeitrackProtocol.java
@@ -15,19 +15,24 @@
*/
package org.traccar.protocol;
+import java.nio.ByteOrder;
+import java.util.List;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
import org.traccar.TrackerServer;
-
-import java.nio.ByteOrder;
-import java.util.List;
+import org.traccar.model.Command;
public class MeitrackProtocol extends BaseProtocol {
public MeitrackProtocol() {
super("meitrack");
+ setSupportedCommands(
+ Command.TYPE_ENGINE_STOP,
+ Command.TYPE_ENGINE_RESUME,
+ Command.TYPE_ALARM_ARM,
+ Command.TYPE_ALARM_DISARM);
}
@Override
diff --git a/src/org/traccar/protocol/MeitrackProtocolEncoder.java b/src/org/traccar/protocol/MeitrackProtocolEncoder.java
new file mode 100644
index 000000000..73f3d01e4
--- /dev/null
+++ b/src/org/traccar/protocol/MeitrackProtocolEncoder.java
@@ -0,0 +1,40 @@
+/*
+ * 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.protocol;
+
+import org.traccar.StringProtocolEncoder;
+import org.traccar.model.Command;
+
+public class MeitrackProtocolEncoder extends StringProtocolEncoder {
+
+ @Override
+ protected Object encodeCommand(Command command) {
+
+ switch (command.getType()) {
+ case Command.TYPE_ENGINE_STOP:
+ return formatCommand(command, "@@M33,{%s},C01,0,12222*18\r\n", Command.KEY_UNIQUE_ID);
+ case Command.TYPE_ENGINE_RESUME:
+ return formatCommand(command, "@@M33,{%s},C01,0,02222*18\r\n", Command.KEY_UNIQUE_ID);
+ case Command.TYPE_ALARM_ARM:
+ return formatCommand(command, "@@M33,{%s},C01,0,22122*18\r\n", Command.KEY_UNIQUE_ID);
+ case Command.TYPE_ALARM_DISARM:
+ return formatCommand(command, "@@M33,{%s},C01,0,22022*18\r\n", Command.KEY_UNIQUE_ID);
+ }
+
+ return null;
+ }
+
+}
diff --git a/src/org/traccar/protocol/TotemProtocolDecoder.java b/src/org/traccar/protocol/TotemProtocolDecoder.java
index a22bbf71e..358c5cb67 100644
--- a/src/org/traccar/protocol/TotemProtocolDecoder.java
+++ b/src/org/traccar/protocol/TotemProtocolDecoder.java
@@ -20,10 +20,7 @@ import java.util.Calendar;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-
import org.traccar.BaseProtocolDecoder;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -59,7 +56,7 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
"(\\d{3})" + // Battery
"(\\d{4})\\|" + // External Power
"(?:(\\d+)\\|)?" + // ADC
- "(\\p{XDigit}{8})\\|" + // Location Code
+ "(\\p{XDigit}+)\\|" + // Location Code
"(\\d+)\\|" + // Temperature
"(\\d+.\\d+)\\|" + // Odometer
"\\d+\\|" + // Serial Number
@@ -315,6 +312,10 @@ public class TotemProtocolDecoder extends BaseProtocolDecoder {
position.setLongitude(longitude);
}
+
+ if (channel != null) {
+ channel.write("ACK OK\r\n");
+ }
return position;
}