diff options
-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")); } |