aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2013-08-23 00:16:28 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2013-08-23 00:16:28 +1200
commit243ac7b40aa7c40749ea781100f4709d26981e6f (patch)
treec85139b1eb7f5de684e05c519e728c19dd93b3de
parentaf665d2ea2420b3efb54c5ff91986772b6b5a025 (diff)
downloadtrackermap-server-243ac7b40aa7c40749ea781100f4709d26981e6f.tar.gz
trackermap-server-243ac7b40aa7c40749ea781100f4709d26981e6f.tar.bz2
trackermap-server-243ac7b40aa7c40749ea781100f4709d26981e6f.zip
Add status to tlt2h (fix #364)
-rw-r--r--src/org/traccar/protocol/Tlt2hProtocolDecoder.java26
1 files changed, 23 insertions, 3 deletions
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<Position> positions = new LinkedList<Position>();
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);
}