aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol/TrvProtocolDecoder.java
diff options
context:
space:
mode:
authorIvan Muratov <binakot@gmail.com>2017-10-24 14:52:48 +0300
committerGitHub <noreply@github.com>2017-10-24 14:52:48 +0300
commitdb02157dbb29539dda4b51a5e8b317293cfc536c (patch)
treeb974f082172406e16a92cb9da8136ef856f571a5 /src/org/traccar/protocol/TrvProtocolDecoder.java
parent09d3cf2b5416327700ad22b652cf4a0dca09aaf2 (diff)
parent96e15853b9c28bd31295ca2c014e226e4a50aaa1 (diff)
downloadtrackermap-server-db02157dbb29539dda4b51a5e8b317293cfc536c.tar.gz
trackermap-server-db02157dbb29539dda4b51a5e8b317293cfc536c.tar.bz2
trackermap-server-db02157dbb29539dda4b51a5e8b317293cfc536c.zip
Merge branch 'master' into master
Diffstat (limited to 'src/org/traccar/protocol/TrvProtocolDecoder.java')
-rw-r--r--src/org/traccar/protocol/TrvProtocolDecoder.java75
1 files changed, 52 insertions, 23 deletions
diff --git a/src/org/traccar/protocol/TrvProtocolDecoder.java b/src/org/traccar/protocol/TrvProtocolDecoder.java
index 88ac76134..918748f7b 100644
--- a/src/org/traccar/protocol/TrvProtocolDecoder.java
+++ b/src/org/traccar/protocol/TrvProtocolDecoder.java
@@ -53,8 +53,8 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder {
.number("(ddd)") // satellites
.number("(ddd)") // battery
.number("(d)") // acc
- .number("dd") // arm status
- .number("dd,") // working mode
+ .number("(dd)") // arm status
+ .number("(dd),") // working mode
.number("(d+),") // mcc
.number("(d+),") // mnc
.number("(d+),") // lac
@@ -71,9 +71,41 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder {
.number("(d)") // acc
.number("(dd)") // arm status
.number("(dd)") // working mode
+ .groupBegin()
+ .number("(ddd)") // interval
+ .number("d") // vibration alarm
+ .number("ddd") // vibration sensitivity
+ .number("d") // automatic arm
+ .number("dddd") // automatic arm time
+ .number("(d)") // blocked
+ .number("(d)") // power status
+ .number("(d)") // movement status
+ .groupEnd("?")
.any()
.compile();
+ private Boolean decodeOptionalValue(Parser parser, int activeValue) {
+ int value = parser.nextInt();
+ if (value != 0) {
+ return value == activeValue;
+ }
+ return null;
+ }
+
+ private void decodeCommon(Position position, Parser parser) {
+
+ position.set(Position.KEY_RSSI, parser.nextInt());
+ position.set(Position.KEY_SATELLITES, parser.nextInt());
+ position.set(Position.KEY_BATTERY, parser.nextInt());
+ position.set(Position.KEY_IGNITION, decodeOptionalValue(parser, 1));
+ position.set(Position.KEY_ARMED, decodeOptionalValue(parser, 1));
+
+ int mode = parser.nextInt();
+ if (mode != 0) {
+ position.set("mode", mode);
+ }
+ }
+
@Override
protected Object decode(
Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
@@ -84,11 +116,14 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder {
String type = sentence.substring(id.length(), id.length() + 4);
if (channel != null) {
+ String responseHeader = id + (char) (type.charAt(0) + 1) + type.substring(1);
if (type.equals("AP00") && id.equals("IW")) {
String time = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
- channel.write(id + (char) (type.charAt(0) + 1) + type.substring(1) + "," + time + ",0#");
+ channel.write(responseHeader + "," + time + ",0#");
+ } else if (type.equals("AP14")) {
+ channel.write(responseHeader + ",0.000,0.000#");
} else {
- channel.write(id + (char) (type.charAt(0) + 1) + type.substring(1) + "#");
+ channel.write(responseHeader + "#");
}
}
@@ -115,13 +150,13 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder {
getLastLocation(position, null);
- position.set(Position.KEY_RSSI, parser.nextInt(0));
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
- position.set(Position.KEY_BATTERY, parser.nextInt(0));
- position.set(Position.KEY_IGNITION, parser.nextInt(0) != 0);
+ decodeCommon(position, parser);
- position.set("arm", parser.nextInt(0));
- position.set("mode", parser.nextInt(0));
+ if (parser.hasNext(3)) {
+ position.set(Position.KEY_BLOCKED, decodeOptionalValue(parser, 2));
+ position.set(Position.KEY_CHARGE, decodeOptionalValue(parser, 1));
+ position.set(Position.KEY_MOTION, decodeOptionalValue(parser, 1));
+ }
return position;
@@ -137,31 +172,25 @@ public class TrvProtocolDecoder extends BaseProtocolDecoder {
position.setDeviceId(deviceSession.getDeviceId());
DateBuilder dateBuilder = new DateBuilder()
- .setDate(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
+ .setDate(parser.nextInt(), parser.nextInt(), parser.nextInt());
position.setValid(parser.next().equals("A"));
position.setLatitude(parser.nextCoordinate());
position.setLongitude(parser.nextCoordinate());
- position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble(0)));
+ position.setSpeed(UnitsConverter.knotsFromKph(parser.nextDouble()));
- dateBuilder.setTime(parser.nextInt(0), parser.nextInt(0), parser.nextInt(0));
+ dateBuilder.setTime(parser.nextInt(), parser.nextInt(), parser.nextInt());
position.setTime(dateBuilder.getDate());
- position.setCourse(parser.nextDouble(0));
+ position.setCourse(parser.nextDouble());
- int rssi = parser.nextInt(0);
- position.set(Position.KEY_SATELLITES, parser.nextInt(0));
- position.set(Position.KEY_BATTERY, parser.nextInt(0));
-
- int acc = parser.nextInt(0);
- if (acc != 0) {
- position.set(Position.KEY_IGNITION, acc == 1);
- }
+ decodeCommon(position, parser);
position.setNetwork(new Network(CellTower.from(
- parser.nextInt(0), parser.nextInt(0), parser.nextInt(0), parser.nextInt(0), rssi)));
+ parser.nextInt(), parser.nextInt(), parser.nextInt(), parser.nextInt())));
return position;
+
}
return null;