From 95285d6f8c93d4a9c8e03d634b0a503695fe4449 Mon Sep 17 00:00:00 2001 From: Evgeny S Maksimov Date: Fri, 25 Jan 2019 23:23:24 +0300 Subject: Bit field traversing refactoring --- src/org/traccar/protocol/NavisProtocolDecoder.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/org/traccar/protocol/NavisProtocolDecoder.java b/src/org/traccar/protocol/NavisProtocolDecoder.java index 8eda868b1..65c425053 100644 --- a/src/org/traccar/protocol/NavisProtocolDecoder.java +++ b/src/org/traccar/protocol/NavisProtocolDecoder.java @@ -317,6 +317,12 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { return positions; } + private boolean checkFlexBitfield(int index) { + int byteIndex = Math.floorDiv(index, 8); + int bitIndex = Math.floorMod(index, 8); + return BitUtil.check(flexBitfield[byteIndex], 7 - bitIndex); + } + private void skipFlexField(int index, ByteBuf buf) { if (index < FLEX_FIELDS_SIZES.length) { buf.skipBytes(FLEX_FIELDS_SIZES[index]); @@ -335,7 +341,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { short output = 0; for (int i = 0; i < flexBitfieldDataSize; i++) { - if ((flexBitfield[(int) (i / 8)] & (0x80 >> i % 8)) == 0) { + if (!checkFlexBitfield(i)) { // Skip FLEX field continue; } @@ -597,7 +603,7 @@ public class NavisProtocolDecoder extends BaseProtocolDecoder { flexDataSize = 0; for (int i = 0; i < flexBitfieldDataSize; i++) { - if ((flexBitfield[(int) (i / 8)] & (0x80 >> i % 8)) != 0) { + if (checkFlexBitfield(i)) { flexDataSize += FLEX_FIELDS_SIZES[i]; } } -- cgit v1.2.3