diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-02-27 02:51:17 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2017-02-27 02:51:17 +1300 |
commit | 61a1bae779f876bcdb9b83a8f950e678a170afb0 (patch) | |
tree | 2774770815c81b9fc3e9e0341d301a5db638dcdd /src | |
parent | 1858afe0af539e7892bd7a48c2fa2aa7f43f968a (diff) | |
download | trackermap-server-61a1bae779f876bcdb9b83a8f950e678a170afb0.tar.gz trackermap-server-61a1bae779f876bcdb9b83a8f950e678a170afb0.tar.bz2 trackermap-server-61a1bae779f876bcdb9b83a8f950e678a170afb0.zip |
Improve Teltonika parameters decoding
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/protocol/TeltonikaProtocolDecoder.java | 49 |
1 files changed, 24 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; } } |