diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2016-02-06 09:50:45 +1000 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2016-02-06 09:50:45 +1000 |
commit | a8c6a98f80858f2e04753086c1877c75f5abcf80 (patch) | |
tree | f877c103f94a72b46d69598ba25586d26b683f7a | |
parent | 3418c67ac44d7d53ca6855e0d453b1b0d4d0f401 (diff) | |
download | trackermap-server-a8c6a98f80858f2e04753086c1877c75f5abcf80.tar.gz trackermap-server-a8c6a98f80858f2e04753086c1877c75f5abcf80.tar.bz2 trackermap-server-a8c6a98f80858f2e04753086c1877c75f5abcf80.zip |
Support TRV protocol heartbeats
-rw-r--r-- | src/org/traccar/protocol/TrvProtocolDecoder.java | 39 | ||||
-rw-r--r-- | test/org/traccar/protocol/TrvProtocolDecoderTest.java | 3 |
2 files changed, 40 insertions, 2 deletions
diff --git a/src/org/traccar/protocol/TrvProtocolDecoder.java b/src/org/traccar/protocol/TrvProtocolDecoder.java index 26f432464..62cdd230c 100644 --- a/src/org/traccar/protocol/TrvProtocolDecoder.java +++ b/src/org/traccar/protocol/TrvProtocolDecoder.java @@ -58,6 +58,18 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder { .any() .compile(); + private static final Pattern PATTERN_HEATRBEAT = new PatternBuilder() + .text("TRV") + .text("CP01,") + .number("(ddd)") // gsm + .number("(ddd)") // gps + .number("(ddd)") // battery + .number("(d)") // acc + .number("(dd)") // arm status + .number("(dd)") // working mode + .any() + .compile(); + @Override protected Object decode( Channel channel, SocketAddress remoteAddress, Object msg) throws Exception { @@ -66,7 +78,7 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder { String type = sentence.substring(3, 7); if (channel != null) { - channel.write("B" + type.substring(1)); // response + channel.write((char) (type.charAt(0) + 1) + type.substring(1)); // response } if (type.equals("AP00")) { @@ -78,7 +90,30 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder { return null; } - if (type.equals("AP01") || type.equals("AP10")) { + if (type.equals("CP01")) { + + Parser parser = new Parser(PATTERN_HEATRBEAT, sentence); + if (!parser.matches()) { + return null; + } + + Position position = new Position(); + position.setProtocol(getProtocolName()); + position.setDeviceId(getDeviceId()); + + getLastLocation(position, null); + + position.set(Event.KEY_GSM, parser.nextInt()); + position.set(Event.KEY_SATELLITES, parser.nextInt()); + position.set(Event.KEY_BATTERY , parser.nextInt()); + position.set(Event.KEY_IGNITION, parser.nextInt() != 0); + + position.set("arm", parser.nextInt()); + position.set("mode", parser.nextInt()); + + return position; + + } else if (type.equals("AP01") || type.equals("AP10")) { Parser parser = new Parser(PATTERN, sentence); if (!parser.matches()) { diff --git a/test/org/traccar/protocol/TrvProtocolDecoderTest.java b/test/org/traccar/protocol/TrvProtocolDecoderTest.java index 5a0160cab..037254486 100644 --- a/test/org/traccar/protocol/TrvProtocolDecoderTest.java +++ b/test/org/traccar/protocol/TrvProtocolDecoderTest.java @@ -13,6 +13,9 @@ public class TrvProtocolDecoderTest extends ProtocolTest { verifyNothing(decoder, text( "TRVAP00353456789012345")); + verifyAttributes(decoder, text( + "TRVCP01,06000908000102")); + verifyPosition(decoder, text( "TRVAP01080524A2232.9806N11404.9355E000.1061830323.8706000908000102,460,0,9520,3671")); |