diff --git a/firmware/controllers/lua/examples/ECU-to-DynoLog.txt b/firmware/controllers/lua/examples/ECU-to-DynoLog.txt new file mode 100644 index 0000000000..dc51b6c765 --- /dev/null +++ b/firmware/controllers/lua/examples/ECU-to-DynoLog.txt @@ -0,0 +1,23 @@ + +DYNOLOG_BASE = 0x680 + +setTickRate(5) -- set tick rate to 5hz + +protocolPacket = { 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } +protocolBase1 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } + +function setTwoBytesMsb(data, offset, value) + value = math.floor(value) + data[offset + 1] = value >> 8 + data[offset + 2] = value & 0xff +end + +function onTick() + local RPM = getSensor("RPM") + local MAP = getSensor("MAP") + local TPS = getSensor("TPS1") + local IAT = getSensor("IAT") + + + txCan(1, DYNOLOG_BASE + 0, 0, protocolPacket) +end diff --git a/firmware/controllers/lua/lua_lib.h b/firmware/controllers/lua/lua_lib.h index bb5d90002b..64b7e8d30d 100644 --- a/firmware/controllers/lua/lua_lib.h +++ b/firmware/controllers/lua/lua_lib.h @@ -14,10 +14,27 @@ end \ " +// LSB (Least Significant Byte comes first) "Intel" +#define TWO_BYTES_LSB "function getTwoBytesLSB(data, offset, factor) \ + return (data[offset + 2] * 256 + data[offset + 1]) * factor \ + end" +// Little-endian System, "Intel" #define SET_TWO_BYTES " function setTwoBytes(data, offset, value) \ value = math.floor(value) \ data[offset + 2] = value >> 8 \ data[offset + 1] = value & 0xff \ end \ " + +// MOTOROLA order, MSB (Most Significant Byte/Big Endian) comes first. +#define TWO_BYTES_MSB "function getTwoBytesMSB(data, offset, factor) \ + return (data[offset + 1] * 256 + data[offset + 2]) * factor \ + end" + +#define SET_TWO_BYTES_MSB " function setTwoBytesMsb(data, offset, value) \ + value = math.floor(value) \ + data[offset + 1] = value >> 8 \ + data[offset + 2] = value & 0xff \ + end \ + " diff --git a/unit_tests/tests/lua/test_lua_e65.cpp b/unit_tests/tests/lua/test_lua_e65.cpp index bc51c1ccf8..f2b4eb6736 100644 --- a/unit_tests/tests/lua/test_lua_e65.cpp +++ b/unit_tests/tests/lua/test_lua_e65.cpp @@ -12,12 +12,6 @@ return checksum \ end " -// LSB (Least Significant Byte comes first) -#define TWO_BYTES_LSB "function getTwoBytesLSB(data, offset, factor) \ - return (data[offset + 2] * 256 + data[offset + 1]) * factor \ - end" - - #define GET_BIT_RANGE "function getBitRange(data, bitIndex, bitWidth) \ byteIndex = bitIndex >> 3 \ shift = bitIndex - byteIndex * 8 \ diff --git a/unit_tests/tests/lua/test_lua_ford.cpp b/unit_tests/tests/lua/test_lua_ford.cpp index 768a640407..d2e1a1e39e 100644 --- a/unit_tests/tests/lua/test_lua_ford.cpp +++ b/unit_tests/tests/lua/test_lua_ford.cpp @@ -2,12 +2,6 @@ #include "rusefi_lua.h" #include "lua_lib.h" - -// MOTOROLA order, MSB (Most Significant Byte/Big Endian) comes first. -#define TWO_BYTES_MSB "function getTwoBytesMSB(data, offset, factor) \ - return (data[offset + 1] * 256 + data[offset + 2]) * factor \ - end" - TEST(LuaFordFocusII, PPS_low) { const char* realdata = TWO_BYTES_MSB R"( diff --git a/unit_tests/tests/lua/test_lua_vag.cpp b/unit_tests/tests/lua/test_lua_vag.cpp index 8e7364a087..b2c993100b 100644 --- a/unit_tests/tests/lua/test_lua_vag.cpp +++ b/unit_tests/tests/lua/test_lua_vag.cpp @@ -19,6 +19,7 @@ TEST(LuaVag, Checksum) { EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(realdata).value_or(0), 0x60); } +// LSB (Least Significant Byte comes first) "Intel" TEST(LuaVag, packMotor1) { const char* realdata = ARRAY_EQUALS SET_TWO_BYTES R"(