rusefi/unit_tests/tests/lua/test_lua_e38.cpp

85 lines
2.5 KiB
C++
Raw Normal View History

2022-09-08 22:15:55 -07:00
#include "pch.h"
#include "rusefi_lua.h"
#include "lua_lib.h"
/**
* MSB bit conversion insanity
* data[1] means start offset 7
* data[2] means start offset 15
* data[3] means start offset 23
* data[4] means start offset 31
* data[5] means start offset 39
* data[6] means start offset 47
* data[7] means start offset 55
* data[8] means start offset 63
*/
#define ECMEngineStatus "\ndata = { 0x80, 0x20, 0x29, 0x16, 0x0F, 0x40, 0x08, 0x00}\n "
TEST(LuaE38, rpm) {
const char* script = TWO_BYTES_MSB ECMEngineStatus R"(
function testFunc()
rpm = getTwoBytesMSB(data, 2, 0.25)
return rpm
end
)";
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(script).value_or(0), 2629.5);
}
TEST(LuaE38, tps) {
const char* script = TWO_BYTES_MSB ECMEngineStatus R"(
function testFunc()
tps = data[5] * 0.3921
return tps
end
)";
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(script).value_or(0), 5.881);
}
2022-09-09 11:04:22 -07:00
2022-09-13 21:03:38 -07:00
TEST(LuaE38, packECMEngineStatus) {
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(
TWO_BYTES_MSB ARRAY_EQUALS PRINT_ARRAY R"(
tps = 5.881
function testFunc()
canEngine = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
canEngine[5] = tps / 0.3921
print(arrayToString(canEngine))
expected = { 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x00 }
return equals(canEngine, expected)
end
)"
).value_or(0), 0);
}
2022-09-09 11:04:22 -07:00
#define ECMEngineCoolantTemp "\ndata = { 0x00, 0xCA, 0x69, 0x3F, 0x6A, 0x00, 0x00, 0x00}\n "
TEST(LuaE38, clt) {
2022-09-13 20:44:38 -07:00
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(TWO_BYTES_MSB ECMEngineCoolantTemp R"(
2022-09-09 11:04:22 -07:00
function testFunc()
clt = data[3] -40
return clt
end
)"
2022-09-13 20:44:38 -07:00
).value_or(0), 65);
2022-09-09 11:04:22 -07:00
}
2022-09-13 20:44:38 -07:00
2022-09-13 21:03:38 -07:00
TEST(LuaE38, packECMEngineCoolantTemp) {
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(
TWO_BYTES_MSB ARRAY_EQUALS PRINT_ARRAY R"(
clt = 65
function testFunc()
canEngine = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
canEngine[3] = clt + 40
print(arrayToString(canEngine))
expected = { 0x00, 0x00, 0x69, 0x00, 0x00, 0x00, 0x00, 0x00 }
return equals(canEngine, expected)
end
)"
).value_or(0), 0);
}