aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-09-27 00:49:33 +1300
committerGitHub <noreply@github.com>2017-09-27 00:49:33 +1300
commit17d5fbb60d859abe366d52137ae2c3cea2de1f5a (patch)
treec957116ab5bf8098034c44617970a22a24528f6a
parentb5fc7e0899475547da99c06319ede5cc68f647e4 (diff)
parent5a515b9e2995602a686436106922362910b8a5c1 (diff)
downloadtrackermap-server-17d5fbb60d859abe366d52137ae2c3cea2de1f5a.tar.gz
trackermap-server-17d5fbb60d859abe366d52137ae2c3cea2de1f5a.tar.bz2
trackermap-server-17d5fbb60d859abe366d52137ae2c3cea2de1f5a.zip
Merge pull request #3547 from Abyss777/teltonika_io
Improve Teltonika IO decoding
-rw-r--r--src/org/traccar/model/CellTower.java6
-rw-r--r--src/org/traccar/model/Position.java1
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolDecoder.java120
-rw-r--r--test/org/traccar/ProtocolTest.java8
-rw-r--r--test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java6
5 files changed, 127 insertions, 14 deletions
diff --git a/src/org/traccar/model/CellTower.java b/src/org/traccar/model/CellTower.java
index 2eb56dd33..6d1dfbd7f 100644
--- a/src/org/traccar/model/CellTower.java
+++ b/src/org/traccar/model/CellTower.java
@@ -106,4 +106,10 @@ public class CellTower {
this.signalStrength = signalStrength;
}
+ public void setOperator(long operator) {
+ String operatorString = String.valueOf(operator);
+ mobileCountryCode = Integer.parseInt(operatorString.substring(0, 3));
+ mobileNetworkCode = Integer.parseInt(operatorString.substring(3));
+ }
+
}
diff --git a/src/org/traccar/model/Position.java b/src/org/traccar/model/Position.java
index 31af3d38a..93456b1b0 100644
--- a/src/org/traccar/model/Position.java
+++ b/src/org/traccar/model/Position.java
@@ -30,6 +30,7 @@ public class Position extends Message {
public static final String KEY_SATELLITES_VISIBLE = "satVisible";
public static final String KEY_RSSI = "rssi";
public static final String KEY_GPS = "gps";
+ public static final String KEY_ROAMING = "roaming";
public static final String KEY_EVENT = "event";
public static final String KEY_ALARM = "alarm";
public static final String KEY_STATUS = "status";
diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
index 4700350d4..ddc113816 100644
--- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -93,7 +93,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
}
}
- private void decodeParameter(Position position, int id, ChannelBuffer buf, int length) {
+ private void decodeOtherParameter(Position position, int id, ChannelBuffer buf, int length) {
switch (id) {
case 1:
case 2:
@@ -113,15 +113,15 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
case 19:
position.set("axisZ", readValue(buf, length, true));
break;
+ case 21:
+ position.set(Position.KEY_RSSI, readValue(buf, length, false));
+ break;
case 66:
position.set(Position.KEY_POWER, readValue(buf, length, false) * 0.001);
break;
case 67:
position.set(Position.KEY_BATTERY, readValue(buf, length, false) * 0.001);
break;
- case 70:
- position.set(Position.KEY_DEVICE_TEMP, readValue(buf, length, true) * 0.1);
- break;
case 72:
position.set(Position.PREFIX_TEMP + 1, readValue(buf, length, true) * 0.1);
break;
@@ -134,15 +134,100 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
case 78:
position.set(Position.KEY_DRIVER_UNIQUE_ID, String.valueOf(readValue(buf, length, false)));
break;
+ case 80:
+ position.set("workMode", readValue(buf, length, false));
+ break;
+ case 179:
+ position.set(Position.PREFIX_OUT + 1, readValue(buf, length, false) == 1);
+ break;
+ case 180:
+ position.set(Position.PREFIX_OUT + 2, readValue(buf, length, false) == 1);
+ break;
+ case 181:
+ position.set(Position.KEY_PDOP, readValue(buf, length, false) * 0.1);
+ break;
case 182:
position.set(Position.KEY_HDOP, readValue(buf, length, false) * 0.1);
break;
+ case 239:
+ position.set(Position.KEY_IGNITION, readValue(buf, length, false) == 1);
+ break;
+ case 240:
+ position.set(Position.KEY_MOTION, readValue(buf, length, false) == 1);
+ break;
+ case 241:
+ position.set(Position.KEY_OPERATOR, readValue(buf, length, false));
+ break;
+ default:
+ position.set(Position.PREFIX_IO + id, readValue(buf, length, false));
+ break;
+ }
+ }
+
+ private void decodeGh3000Parameter(Position position, int id, ChannelBuffer buf, int length) {
+ switch (id) {
+ case 1:
+ position.set(Position.KEY_BATTERY_LEVEL, readValue(buf, length, false));
+ break;
+ case 2:
+ position.set("usbConnected", readValue(buf, length, false) == 1);
+ break;
+ case 5:
+ position.set("uptime", readValue(buf, length, false));
+ break;
+ case 20:
+ position.set(Position.KEY_HDOP, readValue(buf, length, false) * 0.1);
+ break;
+ case 21:
+ position.set(Position.KEY_VDOP, readValue(buf, length, false) * 0.1);
+ break;
+ case 22:
+ position.set(Position.KEY_PDOP, readValue(buf, length, false) * 0.1);
+ break;
+ case 67:
+ position.set(Position.KEY_BATTERY, readValue(buf, length, false) * 0.001);
+ break;
+ case 221:
+ position.set("button", readValue(buf, length, false));
+ break;
+ case 222:
+ if (readValue(buf, length, false) == 1) {
+ position.set(Position.KEY_ALARM, Position.ALARM_SOS);
+ }
+ break;
+ case 240:
+ position.set(Position.KEY_MOTION, readValue(buf, length, false) == 1);
+ break;
+ case 244:
+ position.set(Position.KEY_ROAMING, readValue(buf, length, false) == 1);
+ break;
default:
position.set(Position.PREFIX_IO + id, readValue(buf, length, false));
break;
}
}
+ private void decodeParameter(Position position, int id, ChannelBuffer buf, int length, int codec) {
+ if (codec == CODEC_GH3000) {
+ decodeGh3000Parameter(position, id, buf, length);
+ } else {
+ decodeOtherParameter(position, id, buf, length);
+ }
+ }
+
+ private void decodeNetwork(Position position) {
+ long cid = position.getLong(Position.PREFIX_IO + 205);
+ int lac = position.getInteger(Position.PREFIX_IO + 206);
+ if (cid != 0 && lac != 0) {
+ CellTower cellTower = CellTower.fromLacCid(lac, cid);
+ long operator = position.getInteger(Position.KEY_OPERATOR);
+ if (operator != 0) {
+ cellTower.setOperator(operator);
+ }
+ position.setNetwork(new Network(cellTower));
+ }
+ }
+
private void decodeLocation(Position position, ChannelBuffer buf, int codec) {
int globalMask = 0x0f;
@@ -189,14 +274,19 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
cellTower.setSignalStrength((int) buf.readUnsignedByte());
}
- position.setNetwork(new Network(cellTower));
+ if (BitUtil.check(locationMask, 7)) {
+ cellTower.setOperator(buf.readUnsignedInt());
+ }
- } else if (BitUtil.check(locationMask, 6)) {
- position.set(Position.KEY_RSSI, buf.readUnsignedByte());
- }
+ position.setNetwork(new Network(cellTower));
- if (BitUtil.check(locationMask, 7)) {
- position.set(Position.KEY_OPERATOR, buf.readUnsignedInt());
+ } else {
+ if (BitUtil.check(locationMask, 6)) {
+ position.set(Position.KEY_RSSI, buf.readUnsignedByte());
+ }
+ if (BitUtil.check(locationMask, 7)) {
+ position.set(Position.KEY_OPERATOR, buf.readUnsignedInt());
+ }
}
} else {
@@ -233,7 +323,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
if (BitUtil.check(globalMask, 1)) {
int cnt = buf.readUnsignedByte();
for (int j = 0; j < cnt; j++) {
- decodeParameter(position, buf.readUnsignedByte(), buf, 1);
+ decodeParameter(position, buf.readUnsignedByte(), buf, 1, codec);
}
}
@@ -241,7 +331,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
if (BitUtil.check(globalMask, 2)) {
int cnt = buf.readUnsignedByte();
for (int j = 0; j < cnt; j++) {
- decodeParameter(position, buf.readUnsignedByte(), buf, 2);
+ decodeParameter(position, buf.readUnsignedByte(), buf, 2, codec);
}
}
@@ -249,7 +339,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
if (BitUtil.check(globalMask, 3)) {
int cnt = buf.readUnsignedByte();
for (int j = 0; j < cnt; j++) {
- decodeParameter(position, buf.readUnsignedByte(), buf, 4);
+ decodeParameter(position, buf.readUnsignedByte(), buf, 4, codec);
}
}
@@ -257,7 +347,7 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
if (codec == CODEC_FM4X00) {
int cnt = buf.readUnsignedByte();
for (int j = 0; j < cnt; j++) {
- decodeParameter(position, buf.readUnsignedByte(), buf, 8);
+ decodeOtherParameter(position, buf.readUnsignedByte(), buf, 8);
}
}
@@ -269,6 +359,8 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
}
}
+ decodeNetwork(position);
+
}
private List<Position> parseData(
diff --git a/test/org/traccar/ProtocolTest.java b/test/org/traccar/ProtocolTest.java
index 7bff41acd..1daefabd6 100644
--- a/test/org/traccar/ProtocolTest.java
+++ b/test/org/traccar/ProtocolTest.java
@@ -257,6 +257,14 @@ public class ProtocolTest extends BaseTest {
Assert.assertTrue(attributes.get(Position.KEY_DRIVER_UNIQUE_ID) instanceof String);
}
+ if (attributes.containsKey(Position.KEY_STEPS)) {
+ Assert.assertTrue(attributes.get(Position.KEY_STEPS) instanceof Number);
+ }
+
+ if (attributes.containsKey(Position.KEY_ROAMING)) {
+ Assert.assertTrue(attributes.get(Position.KEY_ROAMING) instanceof Boolean);
+ }
+
if (position.getNetwork() != null && position.getNetwork().getCellTowers() != null) {
for (CellTower cellTower : position.getNetwork().getCellTowers()) {
checkInteger(cellTower.getMobileCountryCode(), 0, 999);
diff --git a/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java b/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java
index a945178a1..beae48d67 100644
--- a/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java
@@ -59,6 +59,12 @@ public class TeltonikaProtocolDecoderTest extends ProtocolTest {
verifyPositions(decoder, binary(
"00000000000000a608010000013f14a1d1ce000f0eb790209a778000ab010c0500000000000000000100003390"));
+ verifyPositions(decoder, binary(
+ "000000000000004508010000015eb70a86d00024089d4d21dee3860137005f12005f000e06ef01f00150011503c800450108b5000bb6000642382718005fcd057ace19d3430f57440000000001000002bf"));
+
+ verifyPositions(decoder, binary(
+ "000000000000004a08010000015ebc1da508002411926621f15246010b00b913005e000f06ef01f00150011505c800450108b5000bb6000642381b18005ecd0318ce19cd430f5844000001f1000061a900010000c8e1"));
+
decoder.setExtended(true);
verifyPositions(decoder, false, binary(