it's impossible to receive AcceleratorPedal sensor via CAN/Lua #4369
This commit is contained in:
parent
51bb97181d
commit
d320dd589c
|
@ -0,0 +1,27 @@
|
|||
|
||||
canRxAdd(0x201)
|
||||
setTickRate(20)
|
||||
|
||||
ppsSensor = Sensor.new("AcceleratorPedal")
|
||||
|
||||
function getTwoBytesMSB(data, offset, factor)
|
||||
return (data[offset + 1] * 256 + data[offset + 2]) * factor
|
||||
end
|
||||
|
||||
function onCanRx(bus, id, dlc, data)
|
||||
packet = getTwoBytesMSB(data, 6, 1)
|
||||
if packet < 0x7f or packet > 0xC8FF then
|
||||
ppsSensor : invalidate()
|
||||
else
|
||||
ppsSensor : set(packet / 512)
|
||||
end
|
||||
end
|
||||
|
||||
function onTick()
|
||||
ppsValue = getSensor("AcceleratorPedal")
|
||||
if ppsValue == nil then
|
||||
print ("PPS not defined")
|
||||
else
|
||||
print ("PPS " ..ppsValue)
|
||||
end
|
||||
end
|
|
@ -12,7 +12,8 @@
|
|||
return checksum \
|
||||
end "
|
||||
|
||||
#define TWO_BYTES "function getTwoBytes(data, offset, factor) \
|
||||
// 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"
|
||||
|
||||
|
@ -30,23 +31,34 @@ end"
|
|||
|
||||
// https://github.com/HeinrichG-V12/E65_ReverseEngineering/blob/main/docs/0x3B4.md
|
||||
TEST(LuaE65, Battery) {
|
||||
const char* realdata = TWO_BYTES R"(
|
||||
const char* realdata = TWO_BYTES_LSB R"(
|
||||
|
||||
function testFunc()
|
||||
data = {0xdc, 0x03, 0x00, 0x53, 0xFE, 0xD3, 0x04, 0x00}
|
||||
return getTwoBytes(data, 0, 0.0147)
|
||||
return getTwoBytesLSB(data, 0, 0.0147)
|
||||
end)";
|
||||
|
||||
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(realdata).value_or(0), 14.5236);
|
||||
}
|
||||
|
||||
TEST(LuaE65, testTwoBytes) {
|
||||
const char* realdata = TWO_BYTES_LSB R"(
|
||||
|
||||
function testFunc()
|
||||
data = {0xdc, 0x03}
|
||||
return getTwoBytesLSB(data, 0, 1)
|
||||
end)";
|
||||
|
||||
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(realdata).value_or(0), 0x03dc);
|
||||
}
|
||||
|
||||
// https://github.com/HeinrichG-V12/E65_ReverseEngineering/blob/main/docs/0x0A8.md
|
||||
TEST(LuaE65, extractTorqueFromA8) {
|
||||
const char* realdata = TWO_BYTES R"(
|
||||
const char* realdata = TWO_BYTES_LSB R"(
|
||||
|
||||
function testFunc()
|
||||
data = { 0x42, 0x89, 0x10, 0x80, 0x10, 0x0F, 0x00, 0x60 }
|
||||
return 0.5 * (getTwoBytes(data, 1, 1) >> 4)
|
||||
return 0.5 * (getTwoBytesLSB(data, 1, 1) >> 4)
|
||||
end
|
||||
)";
|
||||
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(realdata).value_or(0), 0x108 / 2);
|
||||
|
@ -54,18 +66,18 @@ end
|
|||
|
||||
// http://loopybunny.co.uk/CarPC/can/0AA.html
|
||||
TEST(LuaE65, Rpm) {
|
||||
const char* realdata = TWO_BYTES R"(
|
||||
const char* realdata = TWO_BYTES_LSB R"(
|
||||
|
||||
function testFunc()
|
||||
data = {0x5F, 0x59, 0xFF, 0x00, 0x34, 0x0D, 0x80, 0x99}
|
||||
return getTwoBytes(data, 4, 0.25)
|
||||
return getTwoBytesLSB(data, 4, 0.25)
|
||||
end)";
|
||||
|
||||
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(realdata).value_or(0), 845);
|
||||
}
|
||||
|
||||
TEST(LuaE65, gear) {
|
||||
const char* realdata = TWO_BYTES R"(
|
||||
const char* realdata = R"(
|
||||
|
||||
function testFunc()
|
||||
data = {0x58}
|
||||
|
@ -76,7 +88,7 @@ TEST(LuaE65, gear) {
|
|||
}
|
||||
|
||||
TEST(LuaE65, repackAA) {
|
||||
const char* realdata = ARRAY_EQUALS TWO_BYTES R"(
|
||||
const char* realdata = ARRAY_EQUALS R"(
|
||||
|
||||
function testFunc()
|
||||
rpm = 673.75
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
#include "pch.h"
|
||||
#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"(
|
||||
|
||||
function testFunc()
|
||||
data = {0x0e, 0x8f, 0x7d, 0x90, 0x27, 0x10, 0x00, 0x7d}
|
||||
return getTwoBytesMSB(data, 6, 1)
|
||||
end)";
|
||||
|
||||
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(realdata).value_or(0), 0x7d);
|
||||
}
|
||||
|
||||
TEST(LuaFordFocusII, PPS_high) {
|
||||
const char* realdata = TWO_BYTES_MSB R"(
|
||||
|
||||
function testFunc()
|
||||
data = {0x0e, 0x8f, 0x7d, 0x90, 0x27, 0x10, 0xC8, 0x80}
|
||||
return getTwoBytesMSB(data, 6, 1)
|
||||
end)";
|
||||
|
||||
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(realdata).value_or(0), 0xC880);
|
||||
}
|
|
@ -33,6 +33,7 @@ TESTS_SRC_CPP = \
|
|||
tests/lua/test_lua_basic.cpp \
|
||||
tests/lua/test_lookup.cpp \
|
||||
tests/lua/test_lua_e65.cpp \
|
||||
tests/lua/test_lua_ford.cpp \
|
||||
tests/lua/test_lua_vag.cpp \
|
||||
tests/lua/test_lua_with_engine.cpp \
|
||||
tests/lua/test_lua_hooks.cpp \
|
||||
|
|
Loading…
Reference in New Issue