aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/protocol')
-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
6 files changed, 144 insertions, 71 deletions
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;
}