From e9f466d5169fbbdea0e780a3a7b8221481035ec3 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Wed, 25 Sep 2013 20:17:11 +1200 Subject: Improve gps103 decoder --- src/org/traccar/protocol/Gps103ProtocolDecoder.java | 16 +++++++++++----- test/org/traccar/protocol/Gps103ProtocolDecoderTest.java | 4 ++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/org/traccar/protocol/Gps103ProtocolDecoder.java b/src/org/traccar/protocol/Gps103ProtocolDecoder.java index cd6dbdcd0..24a1c525d 100644 --- a/src/org/traccar/protocol/Gps103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gps103ProtocolDecoder.java @@ -38,7 +38,7 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { "(\\d+)," + // IMEI "([^,]+)," + // Alarm "(\\d{2})/?(\\d{2})/?(\\d{2})\\s?" + // Local Date - "(\\d{2}):?(\\d{2})," + // Local Time + "(\\d{2}):?(\\d{2})(?:\\d{2})?," + // Local Time "[^,]*," + "[FL]," + // F - full / L - low "(\\d{2})(\\d{2})(\\d{2})\\.(\\d{3})," + // Time UTC (HHMMSS.SSS) @@ -48,7 +48,8 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { "(\\d+)(\\d{2}\\.\\d+)," + // Longitude (DDDMM.MMMM) "([EW])?," + "(\\d+\\.?\\d*)," + // Speed - "(\\d+\\.\\d+)?" + // Course + "(\\d+\\.?\\d*)?(?:," + // Course + "(\\d+\\.?\\d*)?)?" + // Altitude ".*"); @Override @@ -145,9 +146,6 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { } position.setLongitude(longitude); - // Altitude - position.setAltitude(0.0); - // Speed position.setSpeed(Double.valueOf(parser.group(index++))); @@ -159,6 +157,14 @@ public class Gps103ProtocolDecoder extends BaseProtocolDecoder { position.setCourse(0.0); } + // Altitude + String altitude = parser.group(index++); + if (altitude != null) { + position.setAltitude(Double.valueOf(altitude)); + } else { + position.setAltitude(0.0); + } + // Extended info position.setExtendedInfo(extendedInfo.toString()); diff --git a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java index 46f79cacd..319ccba39 100644 --- a/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Gps103ProtocolDecoderTest.java @@ -91,6 +91,10 @@ public class Gps103ProtocolDecoderTest { assertNotNull(decoder.decode(null, null, "imei:863070012698733,tracker,1303092334,,F,193427.000,A,5139.0369,N,03907.2791,E,0.00,,")); + + assertNotNull(decoder.decode(null, null, + "imei:869039001186913,tracker,130925065533,0,F,065533.000,A,5604.11015,N,9232.12238,E,0.0,,329.0,")); + } } -- cgit v1.2.3