nissan BCM

This commit is contained in:
Andrey 2023-05-31 23:15:32 -04:00 committed by rusefillc
parent 7edbe65029
commit 965cdd466c
2 changed files with 18 additions and 0 deletions

View File

@ -38,8 +38,14 @@ function arrayToString(arr)
return str
end
function getTwoBytesLSB(data, offset, factor)
return (data[offset + 2] * 256 + data[offset + 1]) * factor
end
function onRpmData(bus, id, dlc, data)
-- print('onRpmData ' ..arrayToString(data))
rpm = getTwoBytesLSB(data, 3, 3.15)
print ('RPM ' .. rpm)
end
function onSpeedData(bus, id, dlc, data)

View File

@ -13,3 +13,15 @@ TEST(LuaNissan, wheelSpeed) {
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(script).value_or(0), 32.54);
}
TEST(LuaNissan, rpm) {
#define realRpmPacket "\ndata = { 0x63, 0x00, 0x00, 0x1B, 0x01, 0xCC, 0x00, 0x70}\n "
const char* script = TWO_BYTES_LSB realRpmPacket R"(
function testFunc()
engineTorque = getTwoBytesLSB(data, 3, 3.15)
return engineTorque
end
)";
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(script).value_or(0), 891.45);
}