diff options
-rw-r--r-- | src/org/traccar/protocol/Gl200ProtocolDecoder.java | 45 | ||||
-rw-r--r-- | test/org/traccar/protocol/Gl200ProtocolDecoderTest.java | 3 |
2 files changed, 36 insertions, 12 deletions
diff --git a/src/org/traccar/protocol/Gl200ProtocolDecoder.java b/src/org/traccar/protocol/Gl200ProtocolDecoder.java index 39fdcca78..942d6ef10 100644 --- a/src/org/traccar/protocol/Gl200ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gl200ProtocolDecoder.java @@ -34,21 +34,21 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { } private static final Pattern pattern = Pattern.compile( - "\\+RESP:GT...," + + "\\+(?:RESP|BUFF):GT...," + "[0-9a-fA-F]{6}," + // Protocol version "(\\d{15}),.*," + // IMEI "(\\d*)," + // GPS accuracy - "(\\d+.\\d)," + // Speed - "(\\d+)," + // Course - "(-?\\d+\\.\\d)," + // Altitude + "(\\d+.\\d)?," + // Speed + "(\\d+)?," + // Course + "(-?\\d+\\.\\d)?," + // Altitude "(-?\\d+\\.\\d+)," + // Longitude "(-?\\d+\\.\\d+)," + // Latitude "(\\d{4})(\\d{2})(\\d{2})" + // Date (YYYYMMDD) "(\\d{2})(\\d{2})(\\d{2})," + // Time (HHMMSS) - "(\\d{4})," + // MCC - "(\\d{4})," + // MNC - "(\\p{XDigit}{4})," + // LAC - "(\\p{XDigit}{4})," + // Cell + "(\\d{4})?," + // MCC + "(\\d{4})?," + // MNC + "(\\p{XDigit}{4})?," + // LAC + "(\\p{XDigit}{4})?," + // Cell "(?:.*,(\\d{1,3}),\\d{14},)?" + // Battery ".*"); @@ -83,10 +83,31 @@ public class Gl200ProtocolDecoder extends BaseProtocolDecoder { // Validity position.setValid(Integer.valueOf(parser.group(index++)) < 20); - // Position info - position.setSpeed(Double.valueOf(parser.group(index++))); - position.setCourse(Double.valueOf(parser.group(index++))); - position.setAltitude(Double.valueOf(parser.group(index++))); + // Speed + String speed = parser.group(index++); + if (speed != null) { + position.setSpeed(Double.valueOf(speed)); + } else { + position.setSpeed(0.0); + } + + // Course + String course = parser.group(index++); + if (speed != null) { + position.setCourse(Double.valueOf(course)); + } else { + position.setCourse(0.0); + } + + // Altitude + String altitude = parser.group(index++); + if (speed != null) { + position.setAltitude(Double.valueOf(altitude)); + } else { + position.setAltitude(0.0); + } + + // Coordinates position.setLongitude(Double.valueOf(parser.group(index++))); position.setLatitude(Double.valueOf(parser.group(index++))); diff --git a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java index cc1163227..585440fa3 100644 --- a/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gl200ProtocolDecoderTest.java @@ -85,6 +85,9 @@ public class Gl200ProtocolDecoderTest { verify(decoder.decode(null, null, "+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$")); + verify(decoder.decode(null, null, + "+BUFF:GTFRI,210101,863286020016706,,,10,1,1,,,,49.903915,40.391669,20140818105815,,,,,,,,,,,210100,,,,,000C$")); + } } |