diff options
-rw-r--r-- | src/org/traccar/protocol/Gl200ProtocolDecoder.java | 101 | ||||
-rw-r--r-- | test/org/traccar/ProtocolDecoderTest.java | 6 | ||||
-rw-r--r-- | test/org/traccar/protocol/Gl200ProtocolDecoderTest.java | 10 |
3 files changed, 91 insertions, 26 deletions
diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index 2863fbaf8..a0d8bd1b2 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -41,6 +41,33 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .text("$").optional() .compile(); + private static final Pattern PATTERN_INF = new PatternBuilder() + .text("+RESP:GTINF,") + .number("[0-9A-Z]{2}xxxx,") // protocol version + .number("(d{15}),") // imei + .expression("[0-9A-Z]{17},") // vin + .expression("[^,]{0,20},") // device name + .number("(xx),") // state + .expression("[0-9F]{20},") // iccid + .number("d{1,2},") + .number("d{1,2},") + .expression("[01],") + .number("(d{1,5}),") // power + .text(",") + .number("(d+.d+),") // battery + .expression("([01]),") // charging + .expression("[01],") + .text(",,") + .number("d{14},") // last fix time + .text(",,,,,") + .number("[-+]dddd,") // timezone + .expression("[01],") // daylight saving + .number("(dddd)(dd)(dd)") // date + .number("(dd)(dd)(dd),") // time + .number("(xxxx)") // counter + .text("$").optional() + .compile(); + private static final Pattern PATTERN = new PatternBuilder() .groupBegin() .text("+").expression("(?:RESP|BUFF)").text(":") @@ -78,16 +105,17 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .or().any() .groupEnd().text(",") - .number("(d*),") // gps accuracy - .number("(d+.d)?,") // speed - .number("(d+)?,") // course - .number("(-?d+.d)?,") // altitude - .number("(-?d+.d+),") // longitude - .number("(-?d+.d+),") // latitude + .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),") // time - .number("(dddd)?,") // mcc - .number("(dddd)?,") // mnc + .number("(dd)(dd)(dd)").optional(2) // time + .text(",") + .number("(0ddd)?,") // mcc + .number("(0ddd)?,") // mnc .number("(xxxx|x{8})?,") // loc .number("(xxxx)?,") // cell .groupBegin() @@ -95,7 +123,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .number("(d{1,3})?,") // battery .groupEnd("?") .any().text(",") - .number("(xxxx)\\$?") + .number("(xxxx)") .text("$").optional() .compile(); @@ -111,6 +139,33 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { return null; } + parser = new Parser(PATTERN_INF, (String) msg); + if (parser.matches()) { + + Position position = new Position(); + position.setProtocol(getProtocolName()); + + if (!identify(parser.next(), channel, remoteAddress)) { + return null; + } + position.setDeviceId(getDeviceId()); + + 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()); + + DateBuilder dateBuilder = new DateBuilder() + .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + + getLastLocation(position, dateBuilder.getDate()); + + position.set(Event.KEY_INDEX, parser.next()); + + return position; + } + parser = new Parser(PATTERN, (String) msg); if (!parser.matches()) { return null; @@ -137,17 +192,21 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_FUEL, parser.next()); position.set(Event.KEY_OBD_ODOMETER, parser.next()); - position.setValid(parser.nextInt() < 20); - position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); - position.setCourse(parser.nextDouble()); - position.setAltitude(parser.nextDouble()); - position.setLongitude(parser.nextDouble()); - position.setLatitude(parser.nextDouble()); - - DateBuilder dateBuilder = new DateBuilder() - .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) - .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); - position.setTime(dateBuilder.getDate()); + if (parser.hasNext(12)) { + position.setValid(parser.nextInt() < 20); + position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); + position.setCourse(parser.nextDouble()); + position.setAltitude(parser.nextDouble()); + position.setLongitude(parser.nextDouble()); + position.setLatitude(parser.nextDouble()); + + DateBuilder dateBuilder = new DateBuilder() + .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + position.setTime(dateBuilder.getDate()); + } else { + getLastLocation(position, null); + } position.set(Event.KEY_MCC, parser.next()); position.set(Event.KEY_MNC, parser.next()); diff --git a/test/org/traccar/ProtocolDecoderTest.java b/test/org/traccar/ProtocolDecoderTest.java index 925f457a1..e52ea4695 100644 --- a/test/org/traccar/ProtocolDecoderTest.java +++ b/test/org/traccar/ProtocolDecoderTest.java @@ -51,10 +51,10 @@ public class ProtocolDecoderTest { protected void verifyAttributes(BaseProtocolDecoder decoder, Object object) throws Exception { Object decodedObject = decoder.decode(null, null, object); - Assert.assertNotNull(decodedObject); - Assert.assertTrue(decodedObject instanceof Position); + Assert.assertNotNull("position is null", decodedObject); + Assert.assertTrue("not a position", decodedObject instanceof Position); Position position = (Position) decodedObject; - Assert.assertFalse(position.getAttributes().isEmpty()); + Assert.assertFalse("no attributes", position.getAttributes().isEmpty()); } protected void verifyPosition(BaseProtocolDecoder decoder, Object object) throws Exception { diff --git a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java index 9a124143d..4596a5c90 100644 --- a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java @@ -9,7 +9,13 @@ public class Gl200ProtocolDecoderTest extends ProtocolDecoderTest { public void testDecode() throws Exception { Gl200ProtocolDecoder decoder = new Gl200ProtocolDecoder(new Gl200Protocol()); - + + 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$")); + verifyPosition(decoder, text( "+RESP:GTFRI,0F0106,862193020451183,,,10,1,1,0.0,163,,-57.513617,-25.368191,20150918182145,,,,,,21235.0,,,,0,210100,,,,20150918182149,00B8$")); @@ -123,7 +129,7 @@ public class Gl200ProtocolDecoderTest extends ProtocolDecoderTest { verifyNothing(decoder, text( "\u0000\u0004,0017,0,GTPNA,,867844000400914,,0,0,1,0,,,,0,0,,,,,,99,20150404190153,0601$")); - + verifyPosition(decoder, text( "\u0000\u0004,0017,0,GTEPN,,867844000400914,,0,0,1,0,0.0,0,1717.4,-75.598445,6.278578,20150405003116,,,,,95,20150405003358,0607$")); |