diff --git a/firmware/util/efilib.cpp b/firmware/util/efilib.cpp index a4c4e4d2ef..75c0d605a7 100644 --- a/firmware/util/efilib.cpp +++ b/firmware/util/efilib.cpp @@ -238,7 +238,7 @@ void setBitRangeMsb(uint8_t data[], const int totalBitIndex, const int bitWidth, const int bitInByteIndex = totalBitIndex - byteIndex * 8; if (bitInByteIndex + leftBitWidh > 8) { const int bitsToHandleNow = 8 - bitInByteIndex; - setBitRangeMsb(data, totalBitIndex - bitsToHandleNow, leftBitWidh - bitsToHandleNow, value >> bitsToHandleNow); + setBitRangeMsb(data, (byteIndex - 1) * 8, leftBitWidh - bitsToHandleNow, value >> bitsToHandleNow); leftBitWidh = bitsToHandleNow; } const int mask = (1 << leftBitWidh) - 1; @@ -267,4 +267,4 @@ int getBitRangeMoto(const uint8_t data[], int bitIndex, int bitWidth) { void setBitRangeMoto(uint8_t data[], const int totalBitIndex, const int bitWidth, const int value) { const int b = motorolaMagicFromDbc(totalBitIndex, bitWidth); return setBitRangeMsb(data, b, bitWidth, value); -} \ No newline at end of file +} diff --git a/unit_tests/tests/lua/test_motorola_dbc.cpp b/unit_tests/tests/lua/test_motorola_dbc.cpp index 5526a25605..040ab46843 100644 --- a/unit_tests/tests/lua/test_motorola_dbc.cpp +++ b/unit_tests/tests/lua/test_motorola_dbc.cpp @@ -250,9 +250,9 @@ namespace { const int testValue = 0xB3; // 1011 0011 setBitRangeMoto(data.data(), bitStart, length, testValue); - const std::array unexpectedData = { 0x00, 0x00, 0xC2, 0x00, 0x00, 0x00, 0x00, 0x00 }; - EXPECT_THAT(data, testing::ElementsAreArray(unexpectedData)); // TODO: this check shouldn't pass!!! - EXPECT_EQ(getBitRangeMoto(data.data(), bitStart, length), 0x03); // TODO: this check shouldn't pass!!! + const std::array unexpectedData = { 0x00, 0x2C, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00 }; + EXPECT_THAT(data, testing::ElementsAreArray(unexpectedData)); + EXPECT_EQ(getBitRangeMoto(data.data(), bitStart, length), 0xB3); //// | Bit Positions //// | 7 6 5 4 3 2 1 0 @@ -266,9 +266,9 @@ namespace { //// u 6 | 0 0 0 0 0 0 0 0 //// m 7 | 0 0 0 0 0 0 0 0 //// . 8 | 0 0 0 0 0 0 0 0 - //const std::array expectedData = { 0x00, 0x00, 0x2C, 0xC0, 0x00, 0x00, 0x00, 0x00 }; // TODO: these are expected data!!! - //EXPECT_THAT(data, testing::ElementsAreArray(expectedData)); // TODO: this check shouldn't fail!!! - //EXPECT_EQ(getBitRangeMoto(data.data(), bitStart, length), testValue); // TODO: this check shouldn't fail!!! + const std::array expectedData = { 0x00, 0x2C, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00 }; + EXPECT_THAT(data, testing::ElementsAreArray(expectedData)); + EXPECT_EQ(getBitRangeMoto(data.data(), bitStart, length), testValue); // checkRange( // /* bitStart = */ 13, @@ -290,4 +290,4 @@ namespace { // /* expectedData = */ { 0x00, 0x00, 0x2C, 0xC0, 0x00, 0x00, 0x00, 0x00 } // ); } -} \ No newline at end of file +}