From 4b816255f5e55cddd8ea022b940f33bd204aeb60 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Thu, 6 Oct 2016 13:59:31 +0500 Subject: GTINF can come from buffer --- src/org/traccar/protocol/Gl200ProtocolDecoder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index 2d28ea199..7187aa7cc 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -50,7 +50,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .compile(); private static final Pattern PATTERN_INF = new PatternBuilder() - .text("+RESP:GTINF,") + .text("+").expression("(?:RESP|BUFF):GTINF,") .number("[0-9A-Z]{2}xxxx,") // protocol version .number("(d{15}),") // imei .expression("(?:[0-9A-Z]{17},)?") // vin -- cgit v1.2.3 From 7ee3482b31288d29d7a46fbdf4ffba6732159a89 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 7 Oct 2016 11:36:12 +0500 Subject: - Handle GTVER packets - Added few alarms --- src/org/traccar/model/Position.java | 2 + src/org/traccar/protocol/Gl200ProtocolDecoder.java | 64 +++++++++++++++++++++- .../traccar/protocol/Gl200ProtocolDecoderTest.java | 15 +++++ 3 files changed, 79 insertions(+), 2 deletions(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java index 3a7070083..abe8dd813 100644 --- a/src/org/traccar/model/Position.java +++ b/src/org/traccar/model/Position.java @@ -93,6 +93,8 @@ public class Position extends Message { public static final String ALARM_BREAKING = "hardBreaking"; public static final String ALARM_FATIGUE_DRIVING = "fatigueDriving"; public static final String ALARM_POWER_CUT = "powerCut"; + public static final String ALARM_JAMMING = "jamming"; + public static final String ALARM_TEMPERATURE = "temperature"; private String protocol; diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index 7187aa7cc..973907235 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -88,6 +88,20 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { .text("$").optional() .compile(); + private static final Pattern PATTERN_VER = new PatternBuilder() + .text("+").expression("(?:RESP|BUFF):GTVER,") + .number("[0-9A-Z]{2}xxxx,") // protocol version + .number("(d{15}),") // imei + .expression("[^,]*,") // device name + .expression("([^,]*),") // device type + .number("(xxxx),") // firmware version + .number("(xxxx),") // hardware version + .number("(dddd)(dd)(dd)") // date + .number("(dd)(dd)(dd),") // time + .number("(xxxx)") // counter + .text("$").optional() + .compile(); + private static final Pattern PATTERN_LOCATION = new PatternBuilder() .number("(?:d{1,2})?,") // gps accuracy .number("(d{1,3}.d)?,") // speed @@ -331,6 +345,34 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { return position; } + private Object decodeVer(Channel channel, SocketAddress remoteAddress, String sentence) { + Parser parser = new Parser(PATTERN_VER, sentence); + if (!parser.matches()) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + + DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, parser.next()); + if (deviceSession == null) { + return null; + } + position.setDeviceId(deviceSession.getDeviceId()); + + position.set("deviceType", parser.next()); + position.set("firmwareVersion", parser.nextInt(16)); + position.set("hardwareVersion", parser.nextInt(16)); + + DateBuilder dateBuilder = new DateBuilder() + .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt()) + .setTime(parser.nextInt(), parser.nextInt(), parser.nextInt()); + + getLastLocation(position, dateBuilder.getDate()); + + return position; + } + private void decodeLocation(Position position, Parser parser) { position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble())); position.setCourse(parser.nextDouble()); @@ -587,7 +629,7 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { return position; } - private Object decodeBasic(Channel channel, SocketAddress remoteAddress, String sentence) { + private Object decodeBasic(Channel channel, SocketAddress remoteAddress, String sentence, String type) { Parser parser = new Parser(PATTERN_BASIC, sentence); if (!parser.matches()) { return null; @@ -624,6 +666,21 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { } } + switch (type) { + case "BPL": + position.set(Position.KEY_ALARM, Position.ALARM_LOW_BATTERY); + break; + case "TEM": + position.set(Position.KEY_ALARM, Position.ALARM_TEMPERATURE); + break; + case "JDR": + case "JDS": + position.set(Position.KEY_ALARM, Position.ALARM_JAMMING); + break; + default: + break; + } + return position; } @@ -660,13 +717,16 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { case "IDA": result = decodeIda(channel, remoteAddress, sentence); break; + case "VER": + result = decodeVer(channel, remoteAddress, sentence); + break; default: result = decodeOther(channel, remoteAddress, sentence, type); break; } if (result == null) { - result = decodeBasic(channel, remoteAddress, sentence); + result = decodeBasic(channel, remoteAddress, sentence, type); } if (result != null) { diff --git a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java index c2cdafb49..83f8b02f1 100644 --- a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java @@ -162,6 +162,21 @@ public class Gl200ProtocolDecoderTest extends ProtocolTest { verifyPosition(decoder, text( "+RESP:GTRTL,280100,A1000043D20139,,0,0,1,1,0.1,321,239.1,-76.661047,39.832501,20150615114455,0310,0484,00600019,0A52,,87,20150615074456,031E$")); + + verifyAttributes(decoder, text( + "+BUFF:GTBPL,1A0800,860599000773978,GL300,3.55,0,0.0,0,257.1,60.565437,56.818277,20161006070553,,,,,204.7,20161006071028,0C75$")); + + verifyAttributes(decoder, text( + "+RESP:GTTEM,1A0102,860599000000448,,3,33,0,5.8,0,33.4,117.201191,31.832502,20130109061410,0460,0000,5678,2079,,20130109061517,0091$")); + + verifyAttributes(decoder, text( + "+RESP:GTJDR,0A0102,135790246811220,,0,4.3,92,70.0,121.354335,31.222073,20090214013254,0460,0000,18d8,6141,00,20090214093254,11F0$")); + + verifyAttributes(decoder, text( + "+RESP:GTJDS,0A0102,135790246811220,,2,0,4.3,92,70.0,121.354335,31.222073,20090214013254,0460,0000,18d8,6141,00,20090214093254,11F0$")); + + verifyAttributes(decoder, text( + "+RESP:GTVER,1A0800,860599000773978,GL300,GL300,0A03,0103,20161007041531,10F8$")); verifyNothing(decoder, text( "+ACK:GTHBD,1A0401,135790246811220,,20100214093254,11F0")); -- cgit v1.2.3