aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-02-06 09:50:45 +1000
committerAnton Tananaev <anton.tananaev@gmail.com>2016-02-06 09:50:45 +1000
commita8c6a98f80858f2e04753086c1877c75f5abcf80 (patch)
treef877c103f94a72b46d69598ba25586d26b683f7a /src/org
parent3418c67ac44d7d53ca6855e0d453b1b0d4d0f401 (diff)
downloadtrackermap-server-a8c6a98f80858f2e04753086c1877c75f5abcf80.tar.gz
trackermap-server-a8c6a98f80858f2e04753086c1877c75f5abcf80.tar.bz2
trackermap-server-a8c6a98f80858f2e04753086c1877c75f5abcf80.zip
Support TRV protocol heartbeats
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/protocol/TrvProtocolDecoder.java39
1 files changed, 37 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()) {