From 4749a641514d86a7fd6b369e8d4467e253ca517f Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 6 Aug 2015 15:55:08 +1200 Subject: Implement GVT-800 decoding (fix #1334) --- src/org/traccar/model/Event.java | 1 + src/org/traccar/protocol/ApelProtocolDecoder.java | 2 +- .../traccar/protocol/MegastekProtocolDecoder.java | 126 ++++++++++++++++++--- .../traccar/protocol/ProgressProtocolDecoder.java | 2 +- 4 files changed, 114 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/org/traccar/model/Event.java b/src/org/traccar/model/Event.java index fba5619d2..df9a9a8e5 100644 --- a/src/org/traccar/model/Event.java +++ b/src/org/traccar/model/Event.java @@ -77,6 +77,7 @@ public abstract class Event { public static final String KEY_FLAGS = "flags"; public static final String KEY_CHARGE = "charge"; public static final String KEY_IP = "ip"; + public static final String KEY_ARCHIVE = "archive"; // Starts with 1 not 0 public static final String PREFIX_TEMP = "temp"; diff --git a/src/org/traccar/protocol/ApelProtocolDecoder.java b/src/org/traccar/protocol/ApelProtocolDecoder.java index 6ce823a29..09c1a79f1 100644 --- a/src/org/traccar/protocol/ApelProtocolDecoder.java +++ b/src/org/traccar/protocol/ApelProtocolDecoder.java @@ -146,7 +146,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { // Message index int subtype = type; if (type == MSG_TYPE_LOG_RECORDS) { - position.set("archive", true); + position.set(Event.KEY_ARCHIVE, true); lastIndex = buf.readUnsignedInt() + 1; position.set(Event.KEY_INDEX, lastIndex); diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java index e35b75869..866e92465 100644 --- a/src/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java @@ -22,7 +22,6 @@ 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; @@ -127,13 +126,8 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { return true; } - - @Override - protected Object decode( - Channel channel, SocketAddress remoteAddress, Object msg) - throws Exception { - String sentence = (String) msg; + private Position decodeOld(Channel channel, String sentence) { // Detect type boolean simple = (sentence.charAt(3) == ',' || sentence.charAt(6) == ','); @@ -154,7 +148,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { beginIndex = endIndex + 1; status = sentence.substring(beginIndex); - + } else { int beginIndex = 3; @@ -167,7 +161,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { beginIndex = endIndex + 1; status = sentence.substring(beginIndex); - + } // Create new position @@ -178,7 +172,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { if (!parseGPRMC(gprmc, position)) { return null; } - + if (simple) { // Parse status @@ -186,7 +180,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { if (!parser.matches()) { return null; } - + int index = 1; // Alarm @@ -221,7 +215,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { 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 { // Parse status @@ -229,7 +223,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { if (!parser.matches()) { return null; } - + int index = 1; if (!identify(id, channel)) { @@ -244,7 +238,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { // 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++)); @@ -252,9 +246,111 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { 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; + } + + private static final Pattern patternNew = Pattern.compile( + "\\$MGV\\d{3}," + + "(\\d+)," + // IMEI + "[^,]*," + // Name + "([RS])," + + "(\\d{2})(\\d{2})(\\d{2})," + // Date (DDMMYY) + "(\\d{2})(\\d{2})(\\d{2})," + // Time (HHMMSS) + "([AV])," + // Validity + "(\\d+)(\\d{2}\\.\\d+)," + // Latitude (DDMM.MMMM) + "([NS])," + + "(\\d+)(\\d{2}\\.\\d+)," + // Longitude (DDDMM.MMMM) + "([EW])," + + "\\d{2}," + + "(\\d{2})," + // Satellites + "\\d{2}," + + "(\\d+\\.\\d+)," + // HDOP + "(\\d+\\.\\d+)," + // Speed + "(\\d+\\.\\d+)," + // Course + "(\\d+\\.\\d+)," + // Altitude + "(\\d+\\.\\d+)," + // Odometer + ".*"); + + //$MGV002,013777007536434,,R,010114,000057,V,0000.0000,N,00000.0000,E,00,00,00,99.9,0.000,0.00,0.0,80.263,510,89,2342,030B,,0000,0000,200,96,0, , ,,,,Timer;! + //,,, + // ,,