aboutsummaryrefslogtreecommitdiff
path: root/src/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-09-08 05:44:29 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2017-09-08 05:44:29 +1200
commit179373c6b3d619922a5daf98220ffe831f56fba2 (patch)
tree8107b91c0c3c316295ae6041c78bcdff26c5a329 /src/org
parent3aebd92cc3781b417ded6260d1300434b1418e7e (diff)
downloadtraccar-server-179373c6b3d619922a5daf98220ffe831f56fba2.tar.gz
traccar-server-179373c6b3d619922a5daf98220ffe831f56fba2.tar.bz2
traccar-server-179373c6b3d619922a5daf98220ffe831f56fba2.zip
Improve TRV decoder logic
Diffstat (limited to 'src/org')
-rw-r--r--src/org/traccar/model/ExtendedModel.java4
-rw-r--r--src/org/traccar/protocol/TrvProtocolDecoder.java68
2 files changed, 50 insertions, 22 deletions
diff --git a/src/org/traccar/model/ExtendedModel.java b/src/org/traccar/model/ExtendedModel.java
index 2ce503eea..8353d0e66 100644
--- a/src/org/traccar/model/ExtendedModel.java
+++ b/src/org/traccar/model/ExtendedModel.java
@@ -31,7 +31,9 @@ public class ExtendedModel extends BaseModel {
}
public void set(String key, Boolean value) {
- attributes.put(key, value);
+ if (value != null) {
+ attributes.put(key, value);
+ }
}
public void set(String key, Byte value) {
diff --git a/src/org/traccar/protocol/TrvProtocolDecoder.java b/src/org/traccar/protocol/TrvProtocolDecoder.java
index 1783bce73..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 {
@@ -118,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;
@@ -140,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;