diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2014-04-25 15:20:55 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2014-04-25 15:20:55 +1200 |
commit | 11d6fe6eba842a4ed86d211f97d1c271b5654e5b (patch) | |
tree | 57f6b8ae98d503d16c26415af0af56ee10b005c6 | |
parent | bd9d93b7731b6d5cc0c7fd4287a36f52d00dc05c (diff) | |
download | trackermap-server-11d6fe6eba842a4ed86d211f97d1c271b5654e5b.tar.gz trackermap-server-11d6fe6eba842a4ed86d211f97d1c271b5654e5b.tar.bz2 trackermap-server-11d6fe6eba842a4ed86d211f97d1c271b5654e5b.zip |
Extend TK103 decoder
-rw-r--r-- | src/org/traccar/protocol/Tk103ProtocolDecoder.java | 45 | ||||
-rw-r--r-- | test/org/traccar/protocol/Tk103ProtocolDecoderTest.java | 6 |
2 files changed, 33 insertions, 18 deletions
diff --git a/src/org/traccar/protocol/Tk103ProtocolDecoder.java b/src/org/traccar/protocol/Tk103ProtocolDecoder.java index 6120d483a..fbcc702b8 100644 --- a/src/org/traccar/protocol/Tk103ProtocolDecoder.java +++ b/src/org/traccar/protocol/Tk103ProtocolDecoder.java @@ -34,20 +34,20 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { } private static final Pattern pattern = Pattern.compile( - "(\\d{12})" + // Device ID - ".{4}" + // Command - "\\d*" + // IMEI (?) - "(\\d{2})(\\d{2})(\\d{2})" + // Date (YYMMDD) - "([AV])" + // Validity - "(\\d{2})(\\d{2}\\.\\d{4})" + // Latitude (DDMM.MMMM) - "([NS])" + - "(\\d{3})(\\d{2}\\.\\d{4})" + // Longitude (DDDMM.MMMM) - "([EW])" + - "(\\d+\\.\\d)" + // Speed - "(\\d{2})(\\d{2})(\\d{2})" + // Time (HHMMSS) - "(\\d+\\.?\\d+)" + // Course - "([0-9a-fA-F]{8})" + // State - "L([0-9a-fA-F]+)"); // Milage + "(\\d+)(,)?" + // Device ID + ".{4},?" + // Command + "\\d*" + // IMEI (?) + "(\\d{2})(\\d{2})(\\d{2}),?" + // Date (YYMMDD) + "([AV]),?" + // Validity + "(\\d{2})(\\d{2}\\.\\d{4})" + // Latitude (DDMM.MMMM) + "([NS]),?" + + "(\\d{3})(\\d{2}\\.\\d{4})" + // Longitude (DDDMM.MMMM) + "([EW]),?" + + "(\\d+\\.\\d)(?:\\d*,)?" + // Speed + "(\\d{2})(\\d{2})(\\d{2}),?" + // Time (HHMMSS) + "(\\d+\\.?\\d+)" + // Course + "([0-9a-fA-F]{8})?" + // State + "(?:L([0-9a-fA-F]+))?"); // Milage @Override protected Object decode( @@ -102,9 +102,15 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { // Date Calendar time = Calendar.getInstance(TimeZone.getTimeZone("UTC")); time.clear(); - 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++))); + 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++))); + } 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++))); + } // Validity position.setValid(parser.group(index++).compareTo("A") == 0); @@ -140,7 +146,10 @@ public class Tk103ProtocolDecoder extends BaseProtocolDecoder { extendedInfo.set("state", parser.group(index++)); // Milage - extendedInfo.set("milage", Integer.parseInt(parser.group(index++), 16)); + String milage = parser.group(index++); + if (milage != null) { + extendedInfo.set("milage", Integer.parseInt(milage, 16)); + } position.setExtendedInfo(extendedInfo.toString()); return position; diff --git a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java index ab2dc2c19..d9c71c9b6 100644 --- a/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java +++ b/test/org/traccar/protocol/Tk103ProtocolDecoderTest.java @@ -41,6 +41,12 @@ public class Tk103ProtocolDecoderTest { verify(decoder.decode(null, null, "(012345678901BR00130520A3439.9629S05826.3504W000.1175622323.8700000000L000450AC")); + + verify(decoder.decode(null, null, + "(352606090042050,BP05,240414,V,0000.0000N,00000.0000E,000.0,193133,000.0")); + + verify(decoder.decode(null, null, + "(352606090042050,BP05,240414,A,4527.3513N,00909.9758E,4.80,112825,155.49")); } |