bit math is hard :(
This commit is contained in:
parent
282e79290d
commit
2ae59f6bd5
|
@ -29,7 +29,7 @@ function getBitRange(data, bitIndex, bitWidth)
|
||||||
byteIndex = bitIndex >> 3
|
byteIndex = bitIndex >> 3
|
||||||
shift = bitIndex - byteIndex * 8
|
shift = bitIndex - byteIndex * 8
|
||||||
value = data[1 + byteIndex]
|
value = data[1 + byteIndex]
|
||||||
if (shift + bitIndex > 8) then
|
if (shift + bitWidth > 8) then
|
||||||
value = value + data[2 + byteIndex] * 256
|
value = value + data[2 + byteIndex] * 256
|
||||||
end
|
end
|
||||||
mask = (1 << bitWidth) - 1
|
mask = (1 << bitWidth) - 1
|
||||||
|
|
|
@ -35,7 +35,7 @@ end \
|
||||||
byteIndex = bitIndex >> 3 \
|
byteIndex = bitIndex >> 3 \
|
||||||
shift = bitIndex - byteIndex * 8 \
|
shift = bitIndex - byteIndex * 8 \
|
||||||
value = data[1 + byteIndex] \
|
value = data[1 + byteIndex] \
|
||||||
if (shift + bitIndex > 8) then \
|
if (shift + bitWidth > 8) then \
|
||||||
value = value + data[2 + byteIndex] * 256 \
|
value = value + data[2 + byteIndex] * 256 \
|
||||||
end \
|
end \
|
||||||
mask = (1 << bitWidth) - 1 \
|
mask = (1 << bitWidth) - 1 \
|
||||||
|
@ -114,6 +114,17 @@ TEST(LuaE65, gearTorque) {
|
||||||
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(realdata).value_or(0), 800);
|
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(realdata).value_or(0), 800);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(LuaE65, gearTorque2) {
|
||||||
|
const char* realdata = GET_BIT_RANGE R"(
|
||||||
|
|
||||||
|
function testFunc()
|
||||||
|
data = {0x9F, 0x01, 0x32, 0x20, 0x23, 0x30, 0xFF, 0x43}
|
||||||
|
return getBitRange(data, 0, 16)
|
||||||
|
end)";
|
||||||
|
|
||||||
|
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(realdata).value_or(0), 0x019F);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(LuaE65, sumChecksum) {
|
TEST(LuaE65, sumChecksum) {
|
||||||
// checksum is first byte
|
// checksum is first byte
|
||||||
|
|
Loading…
Reference in New Issue