From 2e52618a0b122f226646dc48436ca7dc6ec8cc39 Mon Sep 17 00:00:00 2001 From: Yuriy Piskarev Date: Tue, 26 Sep 2023 23:33:21 +0300 Subject: fix PR #4839: - before "case 5" delete blank line; - field 15 conversion to meters; - fields 53, 66 (check 15 bit, value 0-14 bits); - field 54 check negative, conversion to liters; - field 57 conversion to meters; - fields 207-255 fix field num check (I didn't compare the index correctly) --- .../protocol/NavtelecomProtocolDecoder.java | 33 +++++++++++----------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java b/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java index 2e857b212..9272b9e0b 100644 --- a/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java @@ -196,9 +196,10 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { for (int j = 0; j < bits.length(); j++) { if (bits.get(j)) { + int bitNum = j + 1; int value; - switch (j + 1) { + switch (bitNum) { case 1: position.set(Position.KEY_INDEX, buf.readUnsignedIntLE()); break; @@ -216,7 +217,6 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { int guardMode = BitUtil.between(value, 3, 4); position.set(Position.KEY_ARMED, (0 < guardMode) && (guardMode < 3)); break; - case 5: value = buf.readUnsignedByte(); position.set(Position.KEY_ROAMING, BitUtil.check(value, 6) ? true : null); @@ -245,7 +245,7 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { position.setCourse(buf.readUnsignedShortLE()); break; case 15: - position.set(Position.KEY_ODOMETER, buf.readFloatLE()); + position.set(Position.KEY_ODOMETER, buf.readFloatLE() * 1000); break; case 19: position.set(Position.KEY_POWER, buf.readShortLE() * 0.001); @@ -313,15 +313,16 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { case 53: value = buf.readUnsignedShortLE(); if (value != 0x7FFF) { - if (BitUtil.check(value, 7)) { - position.set("obdFuelLevel", BitUtil.to(value, 6)); + if (BitUtil.check(value, 15)) { + position.set("obdFuelLevel", BitUtil.to(value, 14)); } else { - position.set("obdFuel", BitUtil.to(value, 6) / 10); + position.set("obdFuel", BitUtil.to(value, 14) / 10); } } break; case 54: - position.set(Position.KEY_FUEL_USED, buf.readFloatLE()); + double dValue = buf.readFloatLE() * 0.5; + position.set(Position.KEY_FUEL_USED, (dValue >= 0) ? (dValue * 0.5) : null); break; case 55: value = buf.readUnsignedShortLE(); @@ -332,7 +333,7 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { position.set(Position.KEY_COOLANT_TEMP, (value != (byte) 0x80) ? value : null); break; case 57: - position.set(Position.KEY_OBD_ODOMETER, buf.readFloatLE()); + position.set(Position.KEY_OBD_ODOMETER, buf.readFloatLE() * 1000); break; case 58: case 59: @@ -357,10 +358,10 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { case 66: value = buf.readUnsignedShortLE(); if (value != 0x7FFF) { - if (BitUtil.check(value, 7)) { - position.set("obdAdBlueLevel", BitUtil.to(value, 6)); + if (BitUtil.check(value, 15)) { + position.set("obdAdBlueLevel", BitUtil.to(value, 14)); } else { - position.set("obdAdBlue", BitUtil.to(value, 6) / 10); + position.set("obdAdBlue", BitUtil.to(value, 14) / 10); } } break; @@ -407,16 +408,16 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { position.set("diagnostic", buf.readUnsignedIntLE()); break; default: - if ((207 <= j) && (j <= 222)) { + if ((207 <= bitNum) && (bitNum <= 222)) { position.set("user1Byte" + (j + 2 - 207), buf.readUnsignedByte()); - } else if ((223 <= j) && (j <= 237)) { + } else if ((223 <= bitNum) && (bitNum <= 237)) { position.set("user2Byte" + (j + 2 - 223), buf.readUnsignedShortLE()); - } else if ((238 <= j) && (j <= 252)) { + } else if ((238 <= bitNum) && (bitNum <= 252)) { position.set("user4Byte" + (j + 2 - 238), buf.readUnsignedIntLE()); - } else if ((253 <= j) && (j <= 255)) { + } else if ((253 <= bitNum) && (bitNum <= 255)) { position.set("user8Byte" + (j + 2 - 253), buf.readLongLE()); } else { - buf.skipBytes(getItemLength(j + 1)); + buf.skipBytes(getItemLength(bitNum)); } break; } -- cgit v1.2.3 From 2fbf2734f3d6d2dcd6dbb44eb92defb25e01671f Mon Sep 17 00:00:00 2001 From: Yuriy Piskarev Date: Wed, 27 Sep 2023 23:29:32 +0300 Subject: fix after tests: - fields 53, 66 (fix for liters); - field 54 fix extra multiplier. --- src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java b/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java index 9272b9e0b..1a64cedcb 100644 --- a/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java @@ -316,13 +316,13 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(value, 15)) { position.set("obdFuelLevel", BitUtil.to(value, 14)); } else { - position.set("obdFuel", BitUtil.to(value, 14) / 10); + position.set("obdFuel", BitUtil.to(value, 14) / 10.0); } } break; case 54: double dValue = buf.readFloatLE() * 0.5; - position.set(Position.KEY_FUEL_USED, (dValue >= 0) ? (dValue * 0.5) : null); + position.set(Position.KEY_FUEL_USED, (dValue >= 0) ? dValue : null); break; case 55: value = buf.readUnsignedShortLE(); @@ -361,7 +361,7 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(value, 15)) { position.set("obdAdBlueLevel", BitUtil.to(value, 14)); } else { - position.set("obdAdBlue", BitUtil.to(value, 14) / 10); + position.set("obdAdBlue", BitUtil.to(value, 14) / 10.0); } } break; -- cgit v1.2.3 From cd179377a28b5d8e09e4f7304f6f5a03a6a05de2 Mon Sep 17 00:00:00 2001 From: Yuriy Piskarev Date: Thu, 28 Sep 2023 22:30:23 +0300 Subject: minor edits: - j starts from 1; - fixed increments for all mentions of j. --- .../protocol/NavtelecomProtocolDecoder.java | 43 +++++++++++----------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java b/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java index 1a64cedcb..2dca220ed 100644 --- a/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java @@ -193,13 +193,12 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { Position position = new Position(getProtocolName()); position.setDeviceId(deviceSession.getDeviceId()); - for (int j = 0; j < bits.length(); j++) { - if (bits.get(j)) { + for (int j = 1; j <= bits.length(); j++) { + if (bits.get(j - 1)) { - int bitNum = j + 1; int value; - switch (bitNum) { + switch (j) { case 1: position.set(Position.KEY_INDEX, buf.readUnsignedIntLE()); break; @@ -259,7 +258,7 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { case 24: case 25: case 26: - position.set(Position.PREFIX_ADC + (j + 2 - 21), buf.readUnsignedShortLE() * 0.001); + position.set(Position.PREFIX_ADC + (j + 1 - 21), buf.readUnsignedShortLE() * 0.001); break; case 29: value = buf.readUnsignedByte(); @@ -275,11 +274,11 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { break; case 33: case 34: - position.set(Position.PREFIX_COUNT + (j + 2 - 33), buf.readUnsignedIntLE()); + position.set(Position.PREFIX_COUNT + (j + 1 - 33), buf.readUnsignedIntLE()); break; case 35: case 36: - position.set("freq" + (j + 2 - 35), buf.readUnsignedShortLE()); + position.set("freq" + (j + 1 - 35), buf.readUnsignedShortLE()); break; case 37: position.set(Position.KEY_HOURS, buf.readUnsignedIntLE() * 1000); @@ -292,7 +291,7 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { case 43: value = buf.readUnsignedShortLE(); position.set( - Position.KEY_FUEL_LEVEL + (j + 2 - 38), (value < 65500) ? value : null); + Position.KEY_FUEL_LEVEL + (j + 1 - 38), (value < 65500) ? value : null); break; case 44: value = buf.readUnsignedShortLE(); @@ -308,7 +307,7 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { case 52: value = buf.readByte(); position.set( - Position.PREFIX_TEMP + (j + 2 - 45), (value != (byte) 0x80) ? value : null); + Position.PREFIX_TEMP + (j + 1 - 45), (value != (byte) 0x80) ? value : null); break; case 53: value = buf.readUnsignedShortLE(); @@ -341,7 +340,7 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { case 61: case 62: value = buf.readUnsignedShortLE(); - position.set("axleWeight" + (j + 2 - 58), (value != 0xFFFF) ? value : null); + position.set("axleWeight" + (j + 1 - 58), (value != 0xFFFF) ? value : null); break; case 63: value = buf.readUnsignedByte(); @@ -386,7 +385,7 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { case 81: case 82: case 83: - position.set("fuelTemp" + (j + 2 - 78), (int) buf.readByte()); + position.set("fuelTemp" + (j + 1 - 78), (int) buf.readByte()); break; case 163: case 164: @@ -394,7 +393,7 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { case 166: value = buf.readShortLE(); position.set( - Position.PREFIX_TEMP + (j + 2 + 8 - 163), + Position.PREFIX_TEMP + (j + 1 + 8 - 163), (value != (short) 0x8000) ? value * 0.05 : null); break; case 167: @@ -402,22 +401,22 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { case 169: case 170: value = buf.readUnsignedByte(); - position.set("humidity" + (j + 2 - 167), (value != 0xFF) ? value * 0.5 : null); + position.set("humidity" + (j + 1 - 167), (value != 0xFF) ? value * 0.5 : null); break; case 206: position.set("diagnostic", buf.readUnsignedIntLE()); break; default: - if ((207 <= bitNum) && (bitNum <= 222)) { - position.set("user1Byte" + (j + 2 - 207), buf.readUnsignedByte()); - } else if ((223 <= bitNum) && (bitNum <= 237)) { - position.set("user2Byte" + (j + 2 - 223), buf.readUnsignedShortLE()); - } else if ((238 <= bitNum) && (bitNum <= 252)) { - position.set("user4Byte" + (j + 2 - 238), buf.readUnsignedIntLE()); - } else if ((253 <= bitNum) && (bitNum <= 255)) { - position.set("user8Byte" + (j + 2 - 253), buf.readLongLE()); + if ((207 <= j) && (j <= 222)) { + position.set("user1Byte" + (j + 1 - 207), buf.readUnsignedByte()); + } else if ((223 <= j) && (j <= 237)) { + position.set("user2Byte" + (j + 1 - 223), buf.readUnsignedShortLE()); + } else if ((238 <= j) && (j <= 252)) { + position.set("user4Byte" + (j + 1 - 238), buf.readUnsignedIntLE()); + } else if ((253 <= j) && (j <= 255)) { + position.set("user8Byte" + (j + 1 - 253), buf.readLongLE()); } else { - buf.skipBytes(getItemLength(bitNum)); + buf.skipBytes(getItemLength(j)); } break; } -- cgit v1.2.3 From 8edfd96b0e14df98b817ed1b4f8edab77562d632 Mon Sep 17 00:00:00 2001 From: Yuriy Piskarev Date: Fri, 29 Sep 2023 22:27:21 +0300 Subject: minor fixes: - field 54 rename; - field 53, 66 corrections. --- src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java b/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java index 2dca220ed..0d085c871 100644 --- a/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java @@ -315,13 +315,13 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(value, 15)) { position.set("obdFuelLevel", BitUtil.to(value, 14)); } else { - position.set("obdFuel", BitUtil.to(value, 14) / 10.0); + position.set("obdFuel", BitUtil.to(value, 14) * 0.1); } } break; case 54: double dValue = buf.readFloatLE() * 0.5; - position.set(Position.KEY_FUEL_USED, (dValue >= 0) ? dValue : null); + position.set("fuelUsed", (dValue >= 0) ? dValue : null); break; case 55: value = buf.readUnsignedShortLE(); @@ -360,7 +360,7 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { if (BitUtil.check(value, 15)) { position.set("obdAdBlueLevel", BitUtil.to(value, 14)); } else { - position.set("obdAdBlue", BitUtil.to(value, 14) / 10.0); + position.set("obdAdBlue", BitUtil.to(value, 14) * 0.1); } } break; -- cgit v1.2.3 From db169dab28ac661adc3eb10e3f395c5b2296d9cc Mon Sep 17 00:00:00 2001 From: Yuriy Piskarev Date: Fri, 29 Sep 2023 23:03:20 +0300 Subject: field 54: restore key, rename variable --- src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java b/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java index 0d085c871..ffcaa0c6c 100644 --- a/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java +++ b/src/main/java/org/traccar/protocol/NavtelecomProtocolDecoder.java @@ -320,8 +320,8 @@ public class NavtelecomProtocolDecoder extends BaseProtocolDecoder { } break; case 54: - double dValue = buf.readFloatLE() * 0.5; - position.set("fuelUsed", (dValue >= 0) ? dValue : null); + double fuelUsed = buf.readFloatLE() * 0.5; + position.set(Position.KEY_FUEL_USED, (fuelUsed >= 0) ? fuelUsed : null); break; case 55: value = buf.readUnsignedShortLE(); -- cgit v1.2.3