aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-02-23 15:37:46 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-02-23 15:37:46 +1300
commit3daa5ad1e59a9da74dfb8efce698c754e141f6bf (patch)
tree32fb8217e59e7e25bac4c98c151c16405ab96411
parent993ac257133211953eb8c8d862c133f2d12de274 (diff)
downloadtraccar-server-3daa5ad1e59a9da74dfb8efce698c754e141f6bf.tar.gz
traccar-server-3daa5ad1e59a9da74dfb8efce698c754e141f6bf.tar.bz2
traccar-server-3daa5ad1e59a9da74dfb8efce698c754e141f6bf.zip
Support another GL200 message type
-rw-r--r--src/org/traccar/helper/Parser.java4
-rw-r--r--src/org/traccar/protocol/Gl200ProtocolDecoder.java79
-rw-r--r--test/org/traccar/protocol/Gl200ProtocolDecoderTest.java20
3 files changed, 87 insertions, 16 deletions
diff --git a/src/org/traccar/helper/Parser.java b/src/org/traccar/helper/Parser.java
index a3f118df0..73713c51c 100644
--- a/src/org/traccar/helper/Parser.java
+++ b/src/org/traccar/helper/Parser.java
@@ -37,6 +37,10 @@ public class Parser {
return matcher.find();
}
+ public void skip(int number) {
+ position += number;
+ }
+
public boolean hasNext() {
return hasNext(1);
}
diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
index ef8cf34e4..c6881d035 100644
--- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java
+++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java
@@ -16,6 +16,8 @@
package org.traccar.protocol;
import java.net.SocketAddress;
+import java.util.LinkedList;
+import java.util.List;
import java.util.regex.Pattern;
import org.jboss.netty.channel.Channel;
@@ -24,6 +26,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;
@@ -120,17 +123,49 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
.text("$").optional()
.compile();
+ private static final Pattern PATTERN_FRI = new PatternBuilder()
+ .text("+RESP:GTFRI,")
+ .number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
+ .number("(d{15}),") // imei
+ .expression("[^,]*,") // device name
+ .number("d?,")
+ .number("d{1,2},") // report type
+ .number("d{1,2},") // count
+ .expression("(")
+ .expression(PATTERN_LOCATION.pattern())
+ .expression(")+")
+ .groupBegin()
+ .number("(d{1,3})?,") // battery
+ .or()
+ .number("(d{1,7}.d)?,") // odometer
+ .number("d{5}:dd:dd,") // hour meter
+ .number("(x+)?,") // adc 1
+ .number("(x+)?,") // adc 2
+ .number("(d{1,3})?,") // battery
+ .number("(d{6})?,,,,") // device status
+ .groupEnd()
+ .number("(dddd)(dd)(dd)") // date
+ .number("(dd)(dd)(dd)").optional(2) // time
+ .text(",")
+ .number("(xxxx)") // count number
+ .text("$").optional()
+ .compile();
+
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?,")
+ .number("d{1,2},") // report type
.number("d{1,2},") // count
.expression(PATTERN_LOCATION.pattern())
+ .groupBegin()
.number("(d{1,3})?,") // battery
+ .or()
+ .number("(d{1,7}.d)?,") // odometer
+ .groupEnd()
.number("(dddd)(dd)(dd)") // date
.number("(dd)(dd)(dd)").optional(2) // time
.text(",")
@@ -138,7 +173,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
.text("$").optional()
.compile();
- private static final Pattern PATTERN_BACKUP = new PatternBuilder()
+ private static final Pattern PATTERN_BASIC = new PatternBuilder()
.text("+").expression("(?:RESP|BUFF)").text(":")
.expression("GT...,")
.number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version
@@ -263,6 +298,34 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
+ private Object decodeFri(Channel channel, SocketAddress remoteAddress, String sentence) {
+ Parser parser = new Parser(PATTERN_FRI, sentence);
+ if (!parser.matches()) {
+ return null;
+ }
+
+ List<Position> positions = new LinkedList<>();
+
+ if (!identify(parser.next(), channel, remoteAddress)) {
+ return null;
+ }
+
+ Parser itemParser = new Parser(PATTERN_LOCATION, parser.next());
+ while (itemParser.find()) {
+ Position position = new Position();
+ position.setProtocol(getProtocolName());
+ position.setDeviceId(getDeviceId());
+
+ decodeLocation(position, itemParser);
+
+ positions.add(position);
+ }
+
+ parser.skip(15);
+
+ return positions;
+ }
+
private Object decodeOther(Channel channel, SocketAddress remoteAddress, String sentence) {
Parser parser = new Parser(PATTERN, sentence);
if (!parser.matches()) {
@@ -280,6 +343,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
decodeLocation(position, parser);
position.set(Event.KEY_BATTERY, parser.next());
+ position.set(Event.KEY_ODOMETER, parser.next());
if (parser.hasNext(6)) {
DateBuilder dateBuilder = new DateBuilder()
@@ -297,8 +361,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
return position;
}
- private Object decodeBackup(Channel channel, SocketAddress remoteAddress, String sentence) {
- Parser parser = new Parser(PATTERN_BACKUP, sentence);
+ private Object decodeBasic(Channel channel, SocketAddress remoteAddress, String sentence) {
+ Parser parser = new Parser(PATTERN_BASIC, sentence);
if (!parser.matches()) {
return null;
}
@@ -349,13 +413,16 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder {
case "OBD":
result = decodeObd(channel, remoteAddress, sentence);
break;
+ case "FRI":
+ result = decodeFri(channel, remoteAddress, sentence);
+ break;
default:
result = decodeOther(channel, remoteAddress, sentence);
break;
}
if (result == null) {
- result = decodeBackup(channel, remoteAddress, sentence);
+ result = decodeBasic(channel, remoteAddress, sentence);
}
return result;
diff --git a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java
index 7a88ff5f5..f906217fe 100644
--- a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java
@@ -25,8 +25,8 @@ 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(
- "+RESP:GTFRI,120113,555564055560555,,1,1,1,,,,,,,,0282,0380,f080,cabf,6900,79,20140824165629,0001$"));
+ /*verifyAttributes(decoder, text(
+ "+RESP:GTFRI,120113,555564055560555,,1,1,1,,,,,,,,0282,0380,f080,cabf,6900,79,20140824165629,0001$"));*/
verifyPosition(decoder, text(
"+RESP:GTFRI,0F0106,862193020451183,,,10,1,1,0.0,163,,-57.513617,-25.368191,20150918182145,,,,,,21235.0,,,,0,210100,,,,20150918182149,00B8$"));
@@ -40,13 +40,13 @@ public class Gl200ProtocolDecoderTest extends ProtocolTest {
verifyPosition(decoder, text(
"+RESP:GTSTT,1A0401,860599000508846,,41,0,0.0,84,107.5,-76.657998,39.497203,20150623160622,0310,0260,B435,3B81,,20150623160622,0F54$"));
- verifyPosition(decoder, text(
+ verifyPositions(decoder, text(
"+RESP:GTFRI,1A0401,860599000508846,,0,0,1,1,134.8,154,278.7,-76.671089,39.778885,20150623154301,0310,0260,043F,7761,,99,20150623154314,0F24$"));
verifyPosition(decoder, text(
"+RESP:GTFRI,1A0200,860599000165464,CRI001,0,0,1,2,,41,,-71.153137,42.301634,20150328020301,,,,,280.3,55,20150327220351,320C"));
- verifyPosition(decoder, text(
+ verifyPositions(decoder, text(
"+RESP:GTFRI,02010D,867844001675407,,0,0,1,2,0.0,0,28.9,8.591011,56.476397,20140915213209,0238,0001,03CB,2871,,97,20140915213459,009A"));
verifyNothing(decoder, text(
@@ -58,13 +58,13 @@ public class Gl200ProtocolDecoderTest extends ProtocolTest {
verifyPosition(decoder, text(
"+RESP:GTSTT,04040C,359231038939904,,42,0,0.0,117,346.0,8.924243,50.798077,20130618125152,0262,0002,0299,109C,00,20130618125154,017A"));
- verifyPosition(decoder, text(
+ verifyPositions(decoder, text(
"+RESP:GTFRI,020102,000035988863964,,0,0,1,1,4.3,92,70.0,121.354335,31.222073,20090214013254,0460,0000,18d8,6141,00,,20090214093254,11F0"));
- verifyPosition(decoder, text(
+ verifyPositions(decoder, text(
"+RESP:GTFRI,020102,135790246811220,,0,0,1,1,4.3,92,70.0,121.354335,31.222073,20090214013254,0460,0000,18d8,6141,00,,20090214093254,11F0"));
- verifyPosition(decoder, text(
+ verifyPositions(decoder, text(
"+RESP:GTFRI,020102,135790246811220,,0,0,2,1,4.3,92,70.0,121.354335,31.222073,20090214013254,0460,0000,18d8,6141,00,0,4.3,92,70.0,121.354335,31.222073,20090101000000,0460,0000,18d8,6141,00,,20090214093254,11F0"));
verifyPosition(decoder, text(
@@ -85,16 +85,16 @@ public class Gl200ProtocolDecoderTest extends ProtocolTest {
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(
+ verifyPositions(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$"));
- verifyPosition(decoder, text(
+ verifyPositions(decoder, text(
"+RESP:GTFRI,02010C,867844001274649,,0,0,1,1,0.0,0,122.5,7.684216,51.524512,20140106233722,0262,0007,79EE,1D22,,93,20140107003805,03C4$"));
verifyPosition(decoder, text(
"+BUFF:GTFRI,210101,863286020016706,,,10,1,1,,,,49.903915,40.391669,20140818105815,,,,,,,,,,,210100,,,,,000C$"));
- verifyPosition(decoder, text(
+ verifyPositions(decoder, text(
"+RESP:GTFRI,240100,135790246811220,,,10,1,1,4.3,92,70.0,121.354335,31.222073,20090214013254,0460,0000,18d8,6141,00,2000.0,12345:12:34,,80,,,,,,20090214093254,11F0$"));
verifyPosition(decoder, text(