diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-09-30 11:45:35 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-09-30 11:45:35 +1300 |
commit | 933f990cefb03d141508abd60681f5615e3db9e2 (patch) | |
tree | 2e433f5121b0949492f4af2bcb11701045e5dbb5 | |
parent | 6334866893bb4a66163e4e7a7a11431ff3b2038f (diff) | |
download | trackermap-server-933f990cefb03d141508abd60681f5615e3db9e2.tar.gz trackermap-server-933f990cefb03d141508abd60681f5615e3db9e2.tar.bz2 trackermap-server-933f990cefb03d141508abd60681f5615e3db9e2.zip |
Fix TK103 speed and time decoding
-rw-r--r-- | src/org/traccar/protocol/Tk103ProtocolDecoder.java | 34 | ||||
-rw-r--r-- | test/org/traccar/protocol/Tk103ProtocolDecoderTest.java | 3 |
2 files changed, 20 insertions, 17 deletions
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 21aa81bda..72fdc10b7 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -44,7 +44,7 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { "([NS]),?" + "(\\d{3})(\\d{2}\\.\\d+)" + // Longitude (DDDMM.MMMM) "([EW]),?" + - "(\\d+\\.\\d{1,2}),?" + // Speed + "(\\d+\\.\\d)(?:\\d*,)?" + // Speed "(\\d{2})(\\d{2})(\\d{2}),?" + // Time (HHMMSS) "(\\d+\\.?\\d{1,2}),?" + // Course "(?:([01]{8})|([0-9a-fA-F]{8}))?,?" + // State @@ -96,45 +96,45 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); if (parser.group(index++) == null) { - time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++))); - time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); - time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); + time.set(Calendar.YEAR, 2000 + Integer.parseInt(parser.group(index++))); + time.set(Calendar.MONTH, Integer.parseInt(parser.group(index++)) - 1); + time.set(Calendar.DAY_OF_MONTH, Integer.parseInt(parser.group(index++))); } else { - time.set(Calendar.DAY_OF_MONTH, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MONTH, Integer.valueOf(parser.group(index++)) - 1); - time.set(Calendar.YEAR, 2000 + Integer.valueOf(parser.group(index++))); + time.set(Calendar.DAY_OF_MONTH, Integer.parseInt(parser.group(index++))); + time.set(Calendar.MONTH, Integer.parseInt(parser.group(index++)) - 1); + time.set(Calendar.YEAR, 2000 + Integer.parseInt(parser.group(index++))); } // Validity position.setValid(parser.group(index++).compareTo("A") == 0); // Latitude - Double latitude = Double.valueOf(parser.group(index++)); - latitude += Double.valueOf(parser.group(index++)) / 60; + Double latitude = Double.parseDouble(parser.group(index++)); + latitude += Double.parseDouble(parser.group(index++)) / 60; if (parser.group(index++).compareTo("S") == 0) latitude = -latitude; position.setLatitude(latitude); // Longitude - Double longitude = Double.valueOf(parser.group(index++)); - longitude += Double.valueOf(parser.group(index++)) / 60; + Double longitude = Double.parseDouble(parser.group(index++)); + longitude += Double.parseDouble(parser.group(index++)) / 60; if (parser.group(index++).compareTo("W") == 0) longitude = -longitude; position.setLongitude(longitude); // Speed if (Context.getConfig().getBoolean(getProtocolName() + ".mph")) { - position.setSpeed(UnitsConverter.knotsFromMph(Double.valueOf(parser.group(index++)))); + position.setSpeed(UnitsConverter.knotsFromMph(Double.parseDouble(parser.group(index++)))); } else { - position.setSpeed(UnitsConverter.knotsFromKph(Double.valueOf(parser.group(index++)))); + position.setSpeed(UnitsConverter.knotsFromKph(Double.parseDouble(parser.group(index++)))); } // Time - time.set(Calendar.HOUR_OF_DAY, Integer.valueOf(parser.group(index++))); - time.set(Calendar.MINUTE, Integer.valueOf(parser.group(index++))); - time.set(Calendar.SECOND, Integer.valueOf(parser.group(index++))); + time.set(Calendar.HOUR_OF_DAY, Integer.parseInt(parser.group(index++))); + time.set(Calendar.MINUTE, Integer.parseInt(parser.group(index++))); + time.set(Calendar.SECOND, Integer.parseInt(parser.group(index++))); position.setTime(time.getTime()); // Course - position.setCourse(Double.valueOf(parser.group(index++))); + position.setCourse(Double.parseDouble(parser.group(index++))); // State String status = parser.group(index++); // binary status diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java index 452745189..4d43166ee 100644 --- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java @@ -12,6 +12,9 @@ public class Tk103ProtocolDecoderTest extends ProtocolDecoderTest { Tk103ProtocolDecoder decoder = new Tk103ProtocolDecoder(new Tk103Protocol()); verify(decoder.decode(null, null, + "(088047365460BP05354188047365460150929A3258.1754S02755.4323E009.4193927301.9000000000L00000000)")); + + verify(decoder.decode(null, null, "(088048003342BP05354188048003342150917A1352.9801N10030.9050E000.0103115265.5600010000L000003F9)")); verify(decoder.decode(null, null, |