2021-12-24 13:56:17 -08:00
|
|
|
#include "pch.h"
|
|
|
|
#include "rusefi_lua.h"
|
|
|
|
|
2021-12-24 14:35:27 -08:00
|
|
|
#define TWO_BYTES "function twoBytes(data, offset, factor) \
|
|
|
|
return (data[offset + 2] * 256 + data[offset + 1]) * factor \
|
|
|
|
end"
|
|
|
|
|
|
|
|
// https://github.com/HeinrichG-V12/E65_ReverseEngineering/blob/main/docs/0x3B4.md
|
2021-12-24 13:56:17 -08:00
|
|
|
TEST(LuaE65, Battery) {
|
2021-12-24 14:35:27 -08:00
|
|
|
const char* realdata = TWO_BYTES R"(
|
2021-12-24 13:56:17 -08:00
|
|
|
|
|
|
|
function testFunc()
|
|
|
|
data = {0xdc, 0x03, 0x00, 0x53, 0xFE, 0xD3, 0x04, 0x00}
|
2021-12-24 14:35:27 -08:00
|
|
|
return twoBytes(data, 0, 0.0147)
|
|
|
|
end)";
|
2021-12-24 13:56:17 -08:00
|
|
|
|
|
|
|
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(realdata).value_or(0), 14.5236);
|
2021-12-24 14:35:27 -08:00
|
|
|
}
|
2021-12-24 13:56:17 -08:00
|
|
|
|
2021-12-24 14:35:27 -08:00
|
|
|
// http://loopybunny.co.uk/CarPC/can/0AA.html
|
|
|
|
TEST(LuaE65, Rpm) {
|
|
|
|
const char* realdata = TWO_BYTES R"(
|
|
|
|
|
|
|
|
function testFunc()
|
|
|
|
data = {0x5F, 0x59, 0xFF, 0x00, 0x34, 0x0D, 0x80, 0x99}
|
|
|
|
return twoBytes(data, 4, 0.25)
|
|
|
|
end)";
|
2021-12-24 13:56:17 -08:00
|
|
|
|
2021-12-24 14:35:27 -08:00
|
|
|
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(realdata).value_or(0), 845);
|
2021-12-24 13:56:17 -08:00
|
|
|
}
|
2021-12-26 11:48:00 -08:00
|
|
|
|
|
|
|
TEST(LuaE65, sumChecksum) {
|
|
|
|
// checksum is first byte
|
|
|
|
// id = A8, packet:
|
|
|
|
// 12 AD 05 A0 05 0F 00 02
|
|
|
|
|
|
|
|
const char* realdata = R"(
|
|
|
|
|
|
|
|
function testFunc()
|
|
|
|
canID = 0xA8
|
|
|
|
data = { 0xAD, 0x05, 0xA0, 0x05, 0x0F, 0x00, 0x02 }
|
|
|
|
checksum = data[1] + data[2] + data[3] + data[4] + data[5] + data[6] + data[7] + canID
|
|
|
|
checksum = math.floor (checksum / 0x100) + (checksum & 0xff)
|
|
|
|
return checksum;
|
|
|
|
end)";
|
|
|
|
|
|
|
|
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(realdata).value_or(0), 0x12);
|
|
|
|
}
|