only:kia CAN

This commit is contained in:
Andrey 2023-07-07 23:25:13 -04:00
parent 1ac874bc72
commit 24763c4a62
2 changed files with 21 additions and 0 deletions

View File

@ -123,4 +123,15 @@ function setBitRange(data, totalBitIndex, bitWidth, value) \
end \
"
#define HYUNDAI_SUM_NIBBLES "\
function hyuindaiSumNibbles(seed) \
local sum = seed \
for i = 1, 7, 1 \
do \
b = data[i] \
sum = sum + (b % 16) + math.floor(b / 16) \
end \
return (16 - sum) % 16 \
end \
"

View File

@ -29,3 +29,13 @@ rpm = 990
)"
).value_or(0), 0);
}
TEST(LuaKia, calcSumOfNibbles) {
#define real81Packet "\ndata = { 0x40, 0x85, 0x5F, 0x00, 0x00, 0x00, 0x00, 0xED}\n "
const char* script = HYUNDAI_SUM_NIBBLES real81Packet R"(
function testFunc()
return hyuindaiSumNibbles(0xD)
end
)";
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(script).value_or(0), 0xE);
}