From f0c990d0cfc727b25f5de4b1097864d4afadb9cb Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Fri, 8 Apr 2016 16:16:05 +1200 Subject: Add support for TAIP attributes --- src/org/traccar/protocol/TaipProtocolDecoder.java | 50 ++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'src/org/traccar/protocol') diff --git a/src/org/traccar/protocol/TaipProtocolDecoder.java b/src/org/traccar/protocol/TaipProtocolDecoder.java index 202b9dd63..3611544d5 100644 --- a/src/org/traccar/protocol/TaipProtocolDecoder.java +++ b/src/org/traccar/protocol/TaipProtocolDecoder.java @@ -25,6 +25,7 @@ import org.traccar.helper.DateUtil; import org.traccar.helper.Parser; import org.traccar.helper.PatternBuilder; import org.traccar.helper.UnitsConverter; +import org.traccar.model.Event; import org.traccar.model.Position; public class TaipProtocolDecoder extends BaseProtocolDecoder { @@ -78,7 +79,6 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { String sentence = (String) msg; - // Find message start int beginIndex = sentence.indexOf('>'); if (beginIndex != -1) { sentence = sentence.substring(beginIndex + 1); @@ -138,6 +138,54 @@ public class TaipProtocolDecoder extends BaseProtocolDecoder { position.setCourse(parser.nextDouble()); position.setValid(parser.nextInt() != 0); + String[] attributes = null; + beginIndex = sentence.indexOf(';'); + if (beginIndex != -1) { + int endIndex = sentence.indexOf('<', beginIndex); + if (endIndex == -1) { + endIndex = sentence.length(); + } + attributes = sentence.substring(beginIndex, endIndex).split(";"); + } + + if (attributes != null) { + for (String attribute : attributes) { + int index = attribute.indexOf('='); + if (index != -1) { + String key = attribute.substring(0, index).toLowerCase(); + String value = attribute.substring(index + 1); + switch (key) { + + case "id": + if (!identify(value, channel, remoteAddress)) { + return null; + } + if (sendResponse && channel != null) { + channel.write(value); + } + break; + + case "sv": + position.set(Event.KEY_SATELLITES, value); + break; + + case "bl": + position.set(Event.KEY_BATTERY, value); + break; + + case "vo": + position.set(Event.KEY_ODOMETER, value); + break; + + default: + position.set(key, value); + break; + + } + } + } + } + return position; } -- cgit v1.2.3