aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-02-22 14:32:22 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-02-22 14:32:22 +1300
commit4d9481d8c3c0d61bf533f7cbd365840b7f7c6402 (patch)
tree4800f282c7d11c8e9c3c5dd329d588d6bcee35b4
parent547246a76bfe48d21b89164b0dd674e06bf3d6ab (diff)
downloadtrackermap-server-4d9481d8c3c0d61bf533f7cbd365840b7f7c6402.tar.gz
trackermap-server-4d9481d8c3c0d61bf533f7cbd365840b7f7c6402.tar.bz2
trackermap-server-4d9481d8c3c0d61bf533f7cbd365840b7f7c6402.zip
Start GL200 decoder refactoring
-rw-r--r--src/org/traccar/protocol/Gl200ProtocolDecoder.java169
-rw-r--r--test/org/traccar/protocol/Gl200ProtocolDecoderTest.java33
2 files changed, 139 insertions, 63 deletions
diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
index fb018dc19..bb6acb1ef 100644
--- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
@@ -23,6 +23,7 @@ import org.traccar.Context;
import org.traccar.helper.DateBuilder;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
+import org.traccar.helper.PatternUtil;
import org.traccar.helper.UnitsConverter;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -33,7 +34,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
super(protocol);
}
- private static final Pattern PATTERN_HEARTBEAT = new PatternBuilder()
+ private static final Pattern PATTERN_HBD = new PatternBuilder()
.text("+ACK:GTHBD,")
.number("([0-9A-Z]{2}xxxx),")
.any().text(",")
@@ -68,7 +69,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
.text("$").optional()
.compile();
- private static final Pattern PATTERN = new PatternBuilder()
+ /*private static final Pattern PATTERN = new PatternBuilder()
.text("+").expression("(?:RESP|BUFF)").text(":")
.expression("GT...,")
.number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
@@ -127,50 +128,154 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
.groupEnd()
.number(",(xxxx)")
.text("$").optional()
+ .compile();*/
+
+ private static final Pattern PATTERN_BACKUP = new PatternBuilder()
+ .text("+").expression("(?:RESP|BUFF)").text(":")
+ .expression("GT...,")
+ .number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
+ .number("(d{15}|x{14}),") // imei
+ .any()
+ .number("(d{1,3}.d)?,") // speed
+ .number("(d{1,3})?,") // course
+ .number("(-?d{1,5}.d)?,") // altitude
+ .number("(-?d{1,3}.d{6}),") // longitude
+ .number("(-?d{1,2}.d{6}),") // latitude
+ .number("(dddd)(dd)(dd)") // date
+ .number("(dd)(dd)(dd)").optional(2) // time
+ .text(",")
+ .any()
+ .number("(xxxx)") // count number
+ .text("$").optional()
.compile();
- @Override
- protected Object decode(
- Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+ /*private static final Pattern PATTERN = new PatternBuilder()
+ .text("+").expression("(?:RESP|BUFF)").text(":")
+ .expression("GT...,")
+ .number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
+ .number("(d{15}),") // imei
+ .expression("[^,]*,") // device name
+ .number("d,") // report id
+ .number("d,") // report type
+ .number("d{1,2},") // report number
- String sentence = (String) msg;
+ .number("(d{1,2})?,") // gps accuracy
+ .number("(d{1,3}.d)?,") // speed
+ .number("(d{1,3})?,") // course
+ .number("(-?d{1,5}.d)?,") // altitude
+ .number("(-?d{1,3}.d{6})?,") // longitude
+ .number("(-?d{1,2}.d{6})?,") // latitude
+ .number("(dddd)(dd)(dd)") // date
+ .number("(dd)(dd)(dd)").optional(2) // time
+ .text(",")
- Parser parser = new Parser(PATTERN_HEARTBEAT, sentence);
- if (parser.matches()) {
- if (channel != null) {
- channel.write("+SACK:GTHBD," + parser.next() + "," + parser.next() + "$", remoteAddress);
- }
+ .number("(0ddd)?,") // mcc
+ .number("(0ddd)?,") // mnc
+ .number("(xxxx)?,") // lac
+ .number("(xxxx)?,") // cell
+ .number("d*,") // reserved
+
+ .number("(d{1,3})?,") // battery
+ .number("(dddd)(dd)(dd)") // date
+ .number("(dd)(dd)(dd)").optional(2) // time
+ .text(",")
+ .number("(xxxx)") // count number
+
+ .text("$").optional()
+ .compile();*/
+
+ private Position decodeHbd(Channel channel, SocketAddress remoteAddress, String sentence) {
+ Parser parser = new Parser(PATTERN_HBD, sentence);
+ if (parser.matches() && channel != null) {
+ channel.write("+SACK:GTHBD," + parser.next() + "," + parser.next() + "$", remoteAddress);
+ }
+ return null;
+ }
+
+ private Position decodeInf(Channel channel, SocketAddress remoteAddress, String sentence) {
+ Parser parser = new Parser(PATTERN_INF, sentence);
+ if (!parser.matches()) {
return null;
}
- parser = new Parser(PATTERN_INF, sentence);
- if (parser.matches()) {
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+
+ if (!identify(parser.next(), channel, remoteAddress)) {
+ return null;
+ }
+ position.setDeviceId(getDeviceId());
- Position position = new Position();
- position.setProtocol(getProtocolName());
+ position.set(Event.KEY_STATUS, parser.next());
+ position.set(Event.KEY_POWER, parser.next());
+ position.set(Event.KEY_BATTERY, parser.next());
+ position.set(Event.KEY_CHARGE, parser.next());
- if (!identify(parser.next(), channel, remoteAddress)) {
- return null;
- }
- position.setDeviceId(getDeviceId());
+ DateBuilder dateBuilder = new DateBuilder()
+ .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
- position.set(Event.KEY_STATUS, parser.next());
- position.set(Event.KEY_POWER, parser.next());
- position.set(Event.KEY_BATTERY, parser.next());
- position.set(Event.KEY_CHARGE, parser.next());
+ getLastLocation(position, dateBuilder.getDate());
- DateBuilder dateBuilder = new DateBuilder()
- .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt())
- .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ position.set(Event.KEY_INDEX, parser.next());
+
+ return position;
+ }
+
+ private Position decodeOther(Channel channel, SocketAddress remoteAddress, String sentence) {
+ Parser parser = new Parser(PATTERN_BACKUP, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+
+ if (!identify(parser.next(), channel, remoteAddress)) {
+ return null;
+ }
+ position.setDeviceId(getDeviceId());
- getLastLocation(position, dateBuilder.getDate());
+ position.setValid(true);
+ position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
+ position.setCourse(parser.nextDouble());
+ position.setAltitude(parser.nextDouble());
+ position.setLongitude(parser.nextDouble());
+ position.setLatitude(parser.nextDouble());
- position.set(Event.KEY_INDEX, parser.next());
+ DateBuilder dateBuilder = new DateBuilder()
+ .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt())
+ .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
+ position.setTime(dateBuilder.getDate());
- return position;
+ if (Context.getConfig().getBoolean(getProtocolName() + ".ack") && channel != null) {
+ channel.write("+SACK:" + parser.next() + "$", remoteAddress);
}
- parser = new Parser(PATTERN, sentence);
+ return position;
+ }
+
+ @Override
+ protected Object decode(
+ Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
+
+ String sentence = (String) msg;
+
+ int typeIndex = sentence.indexOf(":GT");
+ if (typeIndex < 0) {
+ return null;
+ }
+
+ switch (sentence.substring(typeIndex + 3, typeIndex + 6)) {
+ case "HBD":
+ return decodeHbd(channel, remoteAddress, sentence);
+ case "INF":
+ return decodeInf(channel, remoteAddress, sentence);
+ default:
+ return decodeOther(channel, remoteAddress, sentence);
+ }
+
+ /*parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
return null;
}
@@ -238,9 +343,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
if (Context.getConfig().getBoolean(getProtocolName() + ".ack") && channel != null) {
channel.write("+SACK:" + parser.next() + "$", remoteAddress);
- }
-
- return position;
+ }*/
}
}
diff --git a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java
index 0977b7fc1..58b166707 100644
--- a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java
@@ -13,7 +13,7 @@ public class Gl200ProtocolDecoderTest extends ProtocolTest {
verifyPosition(decoder, text(
"+RESP:GTFRI,110100,A5868800000015,,0,0,1,1,4.3,92,70.0,121.354335,31.222073,20110214013254,0460,0000,18d8,6141,00,80,20110214013254,000C"));
- verifyNothing(decoder, text(
+ verifyPosition(decoder, text(
"+RESP:GTFRI,210102,A10000458356CE,,0,1,1,15,1.4,0,190.6,-85.765763,42.894896,20160208164505,4126,210,0,18673,00,92,20160208164507,00A6"));
verifyPosition(decoder, text(
@@ -25,7 +25,7 @@ public class Gl200ProtocolDecoderTest extends ProtocolTest {
verifyAttributes(decoder, text(
"+RESP:GTINF,1F0101,135790246811220,1G1JC5444R7252367,,16,898600810906F8048812,16,0,1,12000,,4.2,0,0,,,20090214013254,,,,,,+0800,0,20090214093254,11F0$"));
- verifyAttributes(decoder, text(
+ verifyNothing(decoder, text(
"+RESP:GTFRI,120113,555564055560555,,1,1,1,,,,,,,,0282,0380,f080,cabf,6900,79,20140824165629,0001$"));
verifyPosition(decoder, text(
@@ -78,40 +78,13 @@ public class Gl200ProtocolDecoderTest extends ProtocolTest {
verifyPosition(decoder, text(
"+RESP:GTFRI,07000D,868487001005941,,0,0,1,1,0.0,0,46.3,-77.039627,38.907573,20120731175232,0310,0260,B44B,EBC9,0015e96913a7,-58,,100,20120731175244,0114"));
-
- verifyPosition(decoder, text(
- "+RESP:GTTOW,0F0100,135790246811220,,,10,1,1,4.3,92,70.0,121.354335,31.222073,20090214013254,0460,0000,18d8,6141,00,2000.0,20090214093254,11F0$"));
-
- verifyPosition(decoder, text(
- "+RESP:GTDIS,0F0100,135790246811220,,,20,1,1,4.3,92,70.0,121.354335,31.222073,20090214013254,0460,0000,18d8,6141,00,2000.0,20090214093254,11F0$"));
-
- verifyPosition(decoder, text(
- "+RESP:GTIOB,0F0100,135790246811220,,,10,1,1,4.3,92,70.0,121.354335,31.222073,20090214013254,0460,0000,18d8,6141,00,2000.0,20090214093254,11F0$"));
-
- verifyPosition(decoder, text(
- "+RESP:GTGEO,0F0100,135790246811220,,,00,1,1,4.3,92,70.0,121.354335,31.222073,20090214013254,0460,0000,18d8,6141,00,2000.0,20090214093254,11F0$"));
-
- verifyPosition(decoder, text(
- "+RESP:GTSPD,0F0100,135790246811220,,,00,1,1,4.3,92,70.0,121.354335,31.222073,20090214013254,0460,0000,18d8,6141,00,2000.0,20090214093254,11F0$"));
-
- verifyPosition(decoder, text(
- "+RESP:GTSOS,0F0100,135790246811220,,,00,1,1,4.3,92,70.0,121.354335,31.222073,20090214013254,0460,0000,18d8,6141,00,2000.0,20090214093254,11F0$"));
-
- verifyPosition(decoder, text(
- "+RESP:GTRTL,0F0100,135790246811220,,,00,1,1,4.3,92,70.0,121.354335,31.222073,20090214013254,0460,0000,18d8,6141,00,2000.0,20090214093254,11F0$"));
-
- verifyPosition(decoder, text(
- "+RESP:GTDOG,0F0100,135790246811220,,,01,1,1,4.3,92,70.0,121.354335,31.222073,20090214013254,0460,0000,18d8,6141,00,2000.0,20090214093254,11F0$"));
-
- verifyPosition(decoder, text(
- "+RESP:GTIGL,0F0100,135790246811220,,,00,1,1,4.3,92,70.0,121.354335,31.222073,20090214013254,0460,0000,18d8,6141,00,2000.0,20090214093254,11F0$"));
verifyPosition(decoder, text(
"+RESP:GTHBM,0F0100,135790246811220,,,10,1,1,4.3,92,70.0,121.354335,31.222073,20090214013254,0460,0000,18d8,6141,00,2000.0,20090214093254,11F0$"));
verifyPosition(decoder, text(
"+RESP:GTHBM,0F0100,135790246811220,,,11,1,1,24.3,92,70.0,121.354335,31.222073,20090214013254,0460,0000,18d8,6141,00,2000.0,20090214093254,11F0$"));
-
+
verifyPosition(decoder, text(
"+RESP:GTFRI,02010C,867844001274144,,0,0,1,1,18.0,233,118.1,7.615551,51.515600,20140106130516,0262,0007,79E6,B956,,72,20140106140524,09CE$"));