aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-02-27 02:51:17 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2017-02-27 02:51:17 +1300
commit61a1bae779f876bcdb9b83a8f950e678a170afb0 (patch)
tree2774770815c81b9fc3e9e0341d301a5db638dcdd
parent1858afe0af539e7892bd7a48c2fa2aa7f43f968a (diff)
downloadtrackermap-server-61a1bae779f876bcdb9b83a8f950e678a170afb0.tar.gz
trackermap-server-61a1bae779f876bcdb9b83a8f950e678a170afb0.tar.bz2
trackermap-server-61a1bae779f876bcdb9b83a8f950e678a170afb0.zip
Improve Teltonika parameters decoding
-rw-r--r--src/org/traccar/protocol/TeltonikaProtocolDecoder.java49
-rw-r--r--test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java3
2 files changed, 27 insertions, 25 deletions
diff --git a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
index 993029ddb..a9679f764 100644
--- a/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
+++ b/src/org/traccar/protocol/TeltonikaProtocolDecoder.java
@@ -71,57 +71,56 @@ public class TeltonikaProtocolDecoder extends BaseProtocolDecoder {
}
+ private long readValue(ChannelBuffer buf, int length, boolean signed) {
+ switch (length) {
+ case 1:
+ return signed ? buf.readByte() : buf.readUnsignedByte();
+ case 2:
+ return signed ? buf.readShort() : buf.readUnsignedShort();
+ case 4:
+ return signed ? buf.readInt() : buf.readUnsignedInt();
+ default:
+ return buf.readLong();
+ }
+ }
+
private void decodeParameter(Position position, int id, ChannelBuffer buf, int length) {
switch (id) {
case 1:
case 2:
case 3:
case 4:
- position.set("di" + id, buf.readUnsignedByte());
+ position.set("di" + id, readValue(buf, length, false));
break;
case 9:
- position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
+ position.set(Position.PREFIX_ADC + 1, readValue(buf, length, false));
break;
case 66:
- position.set(Position.KEY_POWER, buf.readUnsignedShort() + "mV");
+ position.set(Position.KEY_POWER, readValue(buf, length, false) + "mV");
break;
case 67:
- position.set(Position.KEY_BATTERY, buf.readUnsignedShort() + "mV");
+ position.set(Position.KEY_BATTERY, readValue(buf, length, false) + "mV");
break;
case 70:
- position.set(Position.KEY_DEVICE_TEMP, (length == 4 ? buf.readInt() : buf.readShort()) * 0.1);
+ position.set(Position.KEY_DEVICE_TEMP, readValue(buf, length, true) * 0.1);
break;
case 72:
- position.set(Position.PREFIX_TEMP + 1, buf.readInt() * 0.1);
+ position.set(Position.PREFIX_TEMP + 1, readValue(buf, length, true) * 0.1);
break;
case 73:
- position.set(Position.PREFIX_TEMP + 2, buf.readInt() * 0.1);
+ position.set(Position.PREFIX_TEMP + 2, readValue(buf, length, true) * 0.1);
break;
case 74:
- position.set(Position.PREFIX_TEMP + 3, buf.readInt() * 0.1);
+ position.set(Position.PREFIX_TEMP + 3, readValue(buf, length, true) * 0.1);
break;
case 78:
- position.set(Position.KEY_RFID, buf.readLong());
+ position.set(Position.KEY_RFID, readValue(buf, length, false));
break;
case 182:
- position.set(Position.KEY_HDOP, buf.readUnsignedShort() * 0.1);
+ position.set(Position.KEY_HDOP, readValue(buf, length, false) * 0.1);
break;
default:
- switch (length) {
- case 1:
- position.set(Position.PREFIX_IO + id, buf.readUnsignedByte());
- break;
- case 2:
- position.set(Position.PREFIX_IO + id, buf.readUnsignedShort());
- break;
- case 4:
- position.set(Position.PREFIX_IO + id, buf.readUnsignedInt());
- break;
- case 8:
- default:
- position.set(Position.PREFIX_IO + id, buf.readLong());
- break;
- }
+ position.set(Position.PREFIX_IO + id, readValue(buf, length, false));
break;
}
}
diff --git a/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java b/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java
index 289a4f28d..d1c669328 100644
--- a/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java
+++ b/test/org/traccar/protocol/TeltonikaProtocolDecoderTest.java
@@ -14,6 +14,9 @@ public class TeltonikaProtocolDecoderTest extends ProtocolTest {
"000F313233343536373839303132333435"));
verifyPositions(decoder, false, binary(
+ "00000000000002cb08080000015a71ccbec00002fc9bfc1e53a1e00016004cf80005001914150216056500ee00ef00f0009d029e029f02a002a102a202a302a402a502a602020003000164d20003480100c6000ac500ce02c80000654ec700004ee8000000015a725aaac80002fc933c1e539d4000150049f80000001914150116056500ee00ef00f0009d029e029f02a002a102a202a302a402a502a602020003000164d200034800f4c6000ac500ce02c80000654ec700004ee8000000015a75a42c900002fc97d01e539640001d0008020000001914150016056500ee00ef00f0009d029e029f02a002a102a202a302a402a502a602020003000164d200034800f8c6000ac500ce02c80006ba5ac700004ee8000000015a75a440180002fc931c1e539b60001d00b9020001001914150016056500ee00ef00f0009d029e029f02a002a102a202a302a402a502a602020003000164d200034800fac6000ac500ce02c80006ba5ac700004ee8000000015a75a453a00002fc93601e539cc0001d015d0c0000001914150016056500ee00ef00f0009d029e029f02a002a102a202a302a402a502a602020003000164d200034800f9c6000ac500ce02c80006ba5ac700004ee8000000015a75a467280002fc93801e539cc0001d013c0c0000001914150016056500ee00ef00f0009d029e029f02a002a102a202a302a402a502a602020003000164d200034800f9c6000ac500ce02c80006ba5ac700004ee8000000015a75a47ab00002fc92cc1e539c80001d00b00c0000001914150016056500ee00ef00f0009d029e029f02a002a102a202a302a402a502a602020003000164d200034800f8c60004c5000a02c800003085c70006ba5a000000015a75a48e380002fc92ec1e539c40001d00410c0000001914150116056500ee00ef00f0009d029e029f02a002a102a202a302a402a502a602020003000164d200034800f8c6000ac500ce02c80000c83dc700004ee800080000e0b2"));
+
+ verifyPositions(decoder, false, binary(
"0000000000000000080100000113fc208dff00209cca800f14f650006f00d60400040004030101150316030001460000015d000100000000")); // invalid length and checksum
verifyPositions(decoder, false, binary(