From 5741cd0fdbddb623f1807463d9a8d26cf5cc8f4d Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 24 Feb 2016 00:22:20 +1300 Subject: Finish new GL200 decoder implementation --- src/org/traccar/protocol/Gl200ProtocolDecoder.java | 33 +++++++++++++++++----- .../traccar/protocol/Gl200ProtocolDecoderTest.java | 15 ++++++---- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index c6881d035..9098cbd8c 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -82,10 +82,17 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .number("(dddd)(dd)(dd)") // date .number("(dd)(dd)(dd)").optional(2) // time .text(",") + .groupBegin() .number("(0ddd)?,") // mcc .number("(0ddd)?,") // mnc .number("(xxxx)?,") // lac .number("(xxxx)?,") // cell + .or() + .number("(d+)?,") // mcc + .number("(d+)?,") // mnc + .number("(d+)?,") // lac + .number("(d+)?,") // cell + .groupEnd() .number("d*,") // reserved .compile(); @@ -126,14 +133,14 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { private static final Pattern PATTERN_FRI = new PatternBuilder() .text("+RESP:GTFRI,") .number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version - .number("(d{15}),") // imei + .number("(d{15}|x{14}),") // imei .expression("[^,]*,") // device name - .number("d?,") + .number("d*,") .number("d{1,2},") // report type .number("d{1,2},") // count - .expression("(") + .expression("((?:") .expression(PATTERN_LOCATION.pattern()) - .expression(")+") + .expression(")+)") .groupBegin() .number("(d{1,3})?,") // battery .or() @@ -157,7 +164,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .number("(?:[0-9A-Z]{2}xxxx)?,") // protocol version .number("(d{15}),") // imei .expression("[^,]*,") // device name - .number("d?,") + .number("d*,") .number("d{1,2},") // report type .number("d{1,2},") // count .expression(PATTERN_LOCATION.pattern()) @@ -254,6 +261,8 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_LAC, parser.nextInt(16)); position.set(Event.KEY_CID, parser.nextInt(16)); } + + parser.skip(4); // alternative networks } private Object decodeObd(Channel channel, SocketAddress remoteAddress, String sentence) { @@ -304,7 +313,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { return null; } - List positions = new LinkedList<>(); + LinkedList positions = new LinkedList<>(); if (!identify(parser.next(), channel, remoteAddress)) { return null; @@ -321,7 +330,17 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { positions.add(position); } - parser.skip(15); + Position position = positions.getLast(); + + decodeLocation(position, parser); + + position.set(Event.KEY_BATTERY, parser.next()); + + position.set(Event.KEY_ODOMETER, parser.next()); + position.set(Event.PREFIX_ADC + 1, parser.next()); + position.set(Event.PREFIX_ADC + 2, parser.next()); + position.set(Event.KEY_BATTERY, parser.next()); + position.set(Event.KEY_STATUS, parser.next()); return positions; } diff --git a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java index f906217fe..4e7686da7 100644 --- a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java @@ -10,10 +10,13 @@ public class Gl200ProtocolDecoderTest extends ProtocolTest { Gl200ProtocolDecoder decoder = new Gl200ProtocolDecoder(new Gl200Protocol()); - verifyPosition(decoder, text( + verifyPositions(decoder, text( + "+RESP:GTFRI,060228,862894020178276,,15153,10,1,1,0.0,0,431.7,-63.169571,-17.776235,20160210153458,0736,0003,6AD4,80EF,00,34.9,00117:31:26,13442,15163,0,210101,,,,20160210113503,38EE$")); + + verifyPositions(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")); - verifyPosition(decoder, text( + verifyPositions(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,8 +28,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$"));*/ + verifyPositions(decoder, false, 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$")); @@ -97,8 +100,8 @@ public class Gl200ProtocolDecoderTest extends ProtocolTest { 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( - "+RESP:GTFRI,240100,135790246811220,,,10,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,2000.0,12345:12:34,,,80,,,,,,20090214093254,11F0$")); + verifyPositions(decoder, text( + "+RESP:GTFRI,240100,135790246811220,,,10,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,2000.0,12345:12:34,,,80,,,,,20090214093254,11F0$")); verifyPosition(decoder, text( "+RESP:GTSTT,280100,A1000043D20139,,42,0,0.1,321,228.6,-76.660884,39.832552,20150615120628,0310,0484,00600019,0A52,,20150615085741,0320$")); -- cgit v1.2.3