mirror of https://github.com/rusefi/rusefi.git
Lua code reuse
This commit is contained in:
parent
1b72ea0351
commit
4844edc682
|
@ -1,3 +1,7 @@
|
|||
/**
|
||||
* file lua_lib.h
|
||||
*/
|
||||
|
||||
#define ARRAY_EQUALS "function equals(data1, data2) \
|
||||
\
|
||||
local index = 1 \
|
||||
|
@ -38,3 +42,20 @@ end \
|
|||
data[offset + 2] = value & 0xff \
|
||||
end \
|
||||
"
|
||||
|
||||
// one day we shall get Preprocessor macros with C++11 raw string literals
|
||||
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55971
|
||||
#define GET_BIT_RANGE_LSB " \
|
||||
function getBitRange(data, bitIndex, bitWidth) \
|
||||
byteIndex = bitIndex >> 3 \
|
||||
shift = bitIndex - byteIndex * 8 \
|
||||
value = data[1 + byteIndex] \
|
||||
if (shift + bitWidth > 8) then \
|
||||
value = value + data[2 + byteIndex] * 256 \
|
||||
end \
|
||||
mask = (1 << bitWidth) - 1 \
|
||||
return (value >> shift) & mask \
|
||||
end \
|
||||
"
|
||||
|
||||
|
||||
|
|
|
@ -12,17 +12,6 @@
|
|||
return checksum \
|
||||
end "
|
||||
|
||||
#define GET_BIT_RANGE "function getBitRange(data, bitIndex, bitWidth) \
|
||||
byteIndex = bitIndex >> 3 \
|
||||
shift = bitIndex - byteIndex * 8 \
|
||||
value = data[1 + byteIndex] \
|
||||
if (shift + bitWidth > 8) then \
|
||||
value = value + data[2 + byteIndex] * 256 \
|
||||
end \
|
||||
mask = (1 << bitWidth) - 1 \
|
||||
return (value >> shift) & mask \
|
||||
end"
|
||||
|
||||
// https://github.com/HeinrichG-V12/E65_ReverseEngineering/blob/main/docs/0x3B4.md
|
||||
TEST(LuaE65, Battery) {
|
||||
const char* realdata = TWO_BYTES_LSB R"(
|
||||
|
@ -96,7 +85,7 @@ pedal = 50
|
|||
}
|
||||
|
||||
TEST(LuaE65, gearTorque) {
|
||||
const char* realdata = GET_BIT_RANGE R"(
|
||||
const char* realdata = GET_BIT_RANGE_LSB R"(
|
||||
|
||||
function testFunc()
|
||||
data = {0x9F, 0x01, 0x32, 0x20, 0x23, 0x30, 0xFF, 0x43}
|
||||
|
@ -107,7 +96,7 @@ TEST(LuaE65, gearTorque) {
|
|||
}
|
||||
|
||||
TEST(LuaE65, gearTorque2) {
|
||||
const char* realdata = GET_BIT_RANGE R"(
|
||||
const char* realdata = GET_BIT_RANGE_LSB R"(
|
||||
|
||||
function testFunc()
|
||||
data = {0x9F, 0x01, 0x32, 0x20, 0x23, 0x30, 0xFF, 0x43}
|
||||
|
@ -118,7 +107,7 @@ TEST(LuaE65, gearTorque2) {
|
|||
}
|
||||
|
||||
TEST(LuaE65, gearTorque3) {
|
||||
const char* realdata = GET_BIT_RANGE R"(
|
||||
const char* realdata = GET_BIT_RANGE_LSB R"(
|
||||
|
||||
function testFunc()
|
||||
data = {0x9F, 0xDF, 0x32, 0x20, 0x23, 0x30, 0xFF, 0x43}
|
||||
|
|
Loading…
Reference in New Issue