aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2014-04-25 15:20:55 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2014-04-25 15:20:55 +1200
commit11d6fe6eba842a4ed86d211f97d1c271b5654e5b (patch)
tree57f6b8ae98d503d16c26415af0af56ee10b005c6 /src/org/traccar
parentbd9d93b7731b6d5cc0c7fd4287a36f52d00dc05c (diff)
downloadtrackermap-server-11d6fe6eba842a4ed86d211f97d1c271b5654e5b.tar.gz
trackermap-server-11d6fe6eba842a4ed86d211f97d1c271b5654e5b.tar.bz2
trackermap-server-11d6fe6eba842a4ed86d211f97d1c271b5654e5b.zip
Extend TK103 decoder
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/protocol/Tk103ProtocolDecoder.java45
1 files changed, 27 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;