aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEvgeny S Maksimov <me@vragam.net>2019-01-25 23:23:24 +0300
committerEvgeny S Maksimov <me@vragam.net>2019-01-25 23:23:24 +0300
commit95285d6f8c93d4a9c8e03d634b0a503695fe4449 (patch)
tree81706de9111d982c8723b7ad6af9fe4447030297 /src
parent5cb6d4bc0f2254379391a44cd7d56fb9b85e353e (diff)
downloadtrackermap-server-95285d6f8c93d4a9c8e03d634b0a503695fe4449.tar.gz
trackermap-server-95285d6f8c93d4a9c8e03d634b0a503695fe4449.tar.bz2
trackermap-server-95285d6f8c93d4a9c8e03d634b0a503695fe4449.zip
Bit field traversing refactoring
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/protocol/NavisProtocolDecoder.java10
1 files 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];
}
}