aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2019-11-10 17:15:19 -0800
committerAnton Tananaev <anton.tananaev@gmail.com>2019-11-10 17:15:19 -0800
commit985c3a324a566f803ec83658680974a7f75b0b7d (patch)
tree7c75b18fbf6d842faab9d3d5fd586778d2d5c186 /src
parentaefc13c7e57d4c6c8c9a22cdd8203f8d1d9f0878 (diff)
downloadtrackermap-server-985c3a324a566f803ec83658680974a7f75b0b7d.tar.gz
trackermap-server-985c3a324a566f803ec83658680974a7f75b0b7d.tar.bz2
trackermap-server-985c3a324a566f803ec83658680974a7f75b0b7d.zip
Extend Plugin protocol support
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/PluginProtocolDecoder.java54
-rw-r--r--src/test/java/org/traccar/protocol/PluginProtocolDecoderTest.java5
2 files changed, 55 insertions, 4 deletions
diff --git a/src/main/java/org/traccar/protocol/PluginProtocolDecoder.java b/src/main/java/org/traccar/protocol/PluginProtocolDecoder.java
index b5d71854b..949c994ee 100644
--- a/src/main/java/org/traccar/protocol/PluginProtocolDecoder.java
+++ b/src/main/java/org/traccar/protocol/PluginProtocolDecoder.java
@@ -19,6 +19,7 @@ import io.netty.channel.Channel;
import org.traccar.BaseProtocolDecoder;
import org.traccar.DeviceSession;
import org.traccar.Protocol;
+import org.traccar.helper.BitUtil;
import org.traccar.helper.Parser;
import org.traccar.helper.PatternBuilder;
import org.traccar.helper.UnitsConverter;
@@ -47,10 +48,23 @@ public class PluginProtocolDecoder extends BaseProtocolDecoder {
.number("d+,") // type
.number("(d+.?d*),") // odometer
.number("(d+),") // status
- .expression("[^,]*,")
+ .number("(d+.?d*),") // fuel
.expression("[^,]*,")
.text("0")
.groupBegin()
+ .number(",(-?d+.?d*)") // temperature 1
+ .number(",(-?d+.?d*)") // temperature 2
+ .number(",d+") // oil level
+ .number(",(d+)") // rpm
+ .number(",(d+)") // obd speed
+ .number(",d+") // people up
+ .number(",d+") // people down
+ .number(",d+") // obd status
+ .number(",d+") // fuel intake air temperature
+ .number(",(d+)") // throttle
+ .number(",(d+)") // battery
+ .groupEnd("?")
+ .groupBegin()
.text(",+,")
.number("(d+),") // event
.groupEnd("?")
@@ -74,7 +88,6 @@ public class PluginProtocolDecoder extends BaseProtocolDecoder {
Position position = new Position(getProtocolName());
position.setDeviceId(deviceSession.getDeviceId());
- position.setValid(true);
position.setTime(parser.nextDateTime());
position.setLongitude(parser.nextDouble());
position.setLatitude(parser.nextDouble());
@@ -84,8 +97,41 @@ public class PluginProtocolDecoder extends BaseProtocolDecoder {
position.set(Position.KEY_SATELLITES, parser.nextInt());
position.set(Position.KEY_ODOMETER, (long) (parser.nextDouble() * 1000));
- position.set(Position.KEY_STATUS, parser.nextInt());
- position.set(Position.KEY_EVENT, parser.nextInt());
+
+ int status = parser.nextInt();
+ position.setValid(BitUtil.check(status, 0));
+ position.set(Position.KEY_IGNITION, BitUtil.check(status, 1));
+ for (int i = 0; i < 4; i++) {
+ position.set(Position.PREFIX_IN + (i + 1), BitUtil.check(status, 20 + i));
+ }
+ position.set(Position.KEY_STATUS, status);
+
+ position.set(Position.KEY_FUEL_LEVEL, parser.nextDouble());
+
+ if (parser.hasNext(6)) {
+ position.set(Position.PREFIX_TEMP + 1, parser.nextDouble());
+ position.set(Position.PREFIX_TEMP + 2, parser.nextDouble());
+ position.set(Position.KEY_RPM, parser.nextInt());
+ position.set(Position.KEY_OBD_SPEED, parser.nextInt());
+ position.set(Position.KEY_THROTTLE, parser.nextInt() * 0.1);
+ position.set(Position.KEY_POWER, parser.nextInt() * 0.1);
+ }
+
+ if (parser.hasNext()) {
+ int event = parser.nextInt();
+ switch (event) {
+ case 11317:
+ position.set(Position.KEY_ALARM, Position.ALARM_ACCELERATION);
+ break;
+ case 11319:
+ position.set(Position.KEY_ALARM, Position.ALARM_BRAKING);
+ break;
+ default:
+ break;
+
+ }
+ position.set(Position.KEY_EVENT, event);
+ }
return position;
}
diff --git a/src/test/java/org/traccar/protocol/PluginProtocolDecoderTest.java b/src/test/java/org/traccar/protocol/PluginProtocolDecoderTest.java
index d5c5a3b78..0fe3a3a01 100644
--- a/src/test/java/org/traccar/protocol/PluginProtocolDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/PluginProtocolDecoderTest.java
@@ -2,6 +2,7 @@ package org.traccar.protocol;
import org.junit.Test;
import org.traccar.ProtocolTest;
+import org.traccar.model.Position;
public class PluginProtocolDecoderTest extends ProtocolTest {
@@ -10,6 +11,10 @@ public class PluginProtocolDecoderTest extends ProtocolTest {
PluginProtocolDecoder decoder = new PluginProtocolDecoder(null);
+ verifyAttribute(decoder, text(
+ "$$STATUS,60925,20190829123115,28.254151,-25.860605,0.0,0,0,-1,2,0.000,13699,0.00,0,0,28.4,23.4,0,0,0,0,0,0,0,0,0"),
+ Position.PREFIX_TEMP + 1, 28.4);
+
verifyPosition(decoder, text(
"$$STATUS,60550,20191014084650,28.254258,-25.860355,0.0,236,0,-1,2,7472.967,13697,0.00,0,0,0.0,0.0,0,0,0,0,0,0,0,0,0"));