From 243ac7b40aa7c40749ea781100f4709d26981e6f Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 23 Aug 2013 00:16:28 +1200 Subject: Add status to tlt2h (fix #364) --- src/org/traccar/protocol/Tlt2hProtocolDecoder.java | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/org') diff --git a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java index 79a33f0ef..0dc3f1c7c 100644 --- a/src/org/traccar/protocol/Tlt2hProtocolDecoder.java +++ b/src/org/traccar/protocol/Tlt2hProtocolDecoder.java @@ -35,7 +35,14 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { super(serverManager); } - static private Pattern pattern = Pattern.compile( + static private Pattern patternHeader = Pattern.compile( + "#(\\d+)#" + // IMEI + "[^#]+#" + + "\\d+#" + + "([^#]+)#" + // Status + "\\d+"); // Number of records + + static private Pattern patternPosition = Pattern.compile( "#([0-9a-f]+)?" + // Cell info "\\$GPRMC," + "(\\d{2})(\\d{2})(\\d{2})\\.(\\d+)," + // Time (HHMMSS.SSS) @@ -56,8 +63,15 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { String sentence = (String) msg; + // Decode header + String header = sentence.substring(0, sentence.indexOf('\r')); + Matcher parser = patternHeader.matcher(header); + if (!parser.matches()) { + return null; + } + // Get device identifier - String imei = sentence.substring(1, sentence.indexOf('#', 1)); + String imei = parser.group(1); long deviceId; try { deviceId = getDataManager().getDeviceByImei(imei).getId(); @@ -66,11 +80,14 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { return null; } + // Get status + String status = parser.group(2); + String[] messages = sentence.substring(sentence.indexOf('\n') + 1).split("\r\n"); List positions = new LinkedList(); for (String message : messages) { - Matcher parser = pattern.matcher(message); + parser = patternPosition.matcher(message); if (parser.matches()) { Position position = new Position(); ExtendedInfoFormatter extendedInfo = new ExtendedInfoFormatter("tlt2h"); @@ -129,6 +146,9 @@ public class Tlt2hProtocolDecoder extends BaseProtocolDecoder { // Altitude position.setAltitude(0.0); + // Status + extendedInfo.set("status", status); + position.setExtendedInfo(extendedInfo.toString()); positions.add(position); } -- cgit v1.2.3