diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-04-08 16:16:05 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-04-08 16:16:05 +1200 |
commit | f0c990d0cfc727b25f5de4b1097864d4afadb9cb (patch) | |
tree | 15c68b1e0e7e819ef4d2467327d59e5b9db634fc | |
parent | 62a584aea59666bd95d0a88e917f24fe5999df16 (diff) | |
download | trackermap-server-f0c990d0cfc727b25f5de4b1097864d4afadb9cb.tar.gz trackermap-server-f0c990d0cfc727b25f5de4b1097864d4afadb9cb.tar.bz2 trackermap-server-f0c990d0cfc727b25f5de4b1097864d4afadb9cb.zip |
Add support for TAIP attributes
-rw-r--r-- | src/org/traccar/protocol/TaipProtocolDecoder.java | 50 | ||||
-rw-r--r-- | test/org/traccar/protocol/TaipProtocolDecoderTest.java | 3 |
2 files changed, 52 insertions, 1 deletions
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; } diff --git a/test/org/traccar/protocol/TaipProtocolDecoderTest.java b/test/org/traccar/protocol/TaipProtocolDecoderTest.java index e64513ac5..871ec84b3 100644 --- a/test/org/traccar/protocol/TaipProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TaipProtocolDecoderTest.java @@ -11,6 +11,9 @@ public class TaipProtocolDecoderTest extends ProtocolTest { TaipProtocolDecoder decoder = new TaipProtocolDecoder(new TaipProtocol(), false); verifyPosition(decoder, text( + ">REV451891352379+0307152+1016143700000012;SV=8;BL=4416;VO=8055;ID=356612026322000<")); + + verifyPosition(decoder, text( ">RGP230615010248-2682523-065236820000003007F4101;ID=0005;#0002;*2A<"), position("2015-06-23 01:02:48.000", true, -26.82523, -65.23682)); |