From f26304bf414e86c00ea85cce143226084434cacc Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 20 Apr 2015 23:10:00 +1200 Subject: Add new GPS103 format (fix #1177) --- .../traccar/protocol/Gps103ProtocolDecoder.java | 25 ++++++++++++++++------ .../protocol/Gps103ProtocolDecoderTest.java | 6 ++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index 90b170cff..0d8257e55 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -48,10 +48,12 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { "(?:(\\d{2})(\\d{2})(\\d{2})\\.(\\d+)|" + // Time UTC (HHMMSS.SSS) "(?:\\d{1,5}\\.\\d+))," + "([AV])," + // Validity + "(?:([NS]),)?" + "(\\d+)(\\d{2}\\.\\d+)," + // Latitude (DDMM.MMMM) - "([NS])," + + "(?:([NS]),)?" + + "(?:([EW]),)?" + "(\\d+)(\\d{2}\\.\\d+)," + // Longitude (DDDMM.MMMM) - "([EW])?," + + "(?:([EW])?,)?" + "(\\d+\\.?\\d*)?,?" + // Speed "(\\d+\\.?\\d*)?,?" + // Course "(\\d+\\.?\\d*)?,?" + // Altitude @@ -150,17 +152,28 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { position.setValid(parser.group(index++).compareTo("A") == 0); // Latitude + String hemisphere = parser.group(index++); Double latitude = Double.valueOf(parser.group(index++)); latitude += Double.valueOf(parser.group(index++)) / 60; - if (parser.group(index++).compareTo("S") == 0) latitude = -latitude; + if (parser.group(index) != null) { + hemisphere = parser.group(index); + } + index++; + if (hemisphere.compareTo("S") == 0) { + latitude = -latitude; + } position.setLatitude(latitude); // Longitude + hemisphere = parser.group(index++); Double longitude = Double.valueOf(parser.group(index++)); longitude += Double.valueOf(parser.group(index++)) / 60; - String hemisphere = parser.group(index++); - if (hemisphere != null) { - if (hemisphere.compareTo("W") == 0) longitude = -longitude; + if (parser.group(index) != null) { + hemisphere = parser.group(index); + } + index++; + if (hemisphere != null && hemisphere.compareTo("W") == 0) { + longitude = -longitude; } position.setLongitude(longitude); diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java index 3b7b2285f..53a092598 100644 --- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java @@ -112,6 +112,12 @@ public class Gps103ProtocolDecoderTest { verify(decoder.decode(null, null, null, "imei:353552045375005,tracker,150401165832,61.0,F,31.0,A,1050.73696,N,10636.49489,E,8.0,,22.0,")); + + verify(decoder.decode(null, null, null, + "imei:353552045403597,tracker,150420050648,53.0,F,0.0,A,N,5306.64155,E,00700.77848,0.0,,1.0,;")); + + verify(decoder.decode(null, null, null, + "imei:353552045403597,tracker,150420051153,53.0,F,0.0,A,5306.64155,N,00700.77848,E,0.0,,1.0,;")); } -- cgit v1.2.3