This commit is contained in:
Andrey 2022-11-23 23:45:25 -05:00
parent 7717acb14d
commit 3b7b8e3f33
3 changed files with 29 additions and 4 deletions

View File

@ -1,6 +1,9 @@
// by definition this should be a copy-paste of https://github.com/rusefi/rusefi/blob/master/firmware/controllers/lua/examples/350z-ac.txt
strncpy(config->luaScript, R"(
canRxAdd(0x35d)
IN_284 = 0x284 -- 644
IN_285 = 0x285
IN_35D = 0x35d
OUT_1F9 = 0x1F9 -- 505
OUT_233 = 0x233 -- 563
@ -13,6 +16,10 @@ t : reset()
globalAcOut = 0
function getTwoBytesMSB(data, offset, factor)
return (data[offset + 1] * 256 + data[offset + 2]) * factor
end
function onTick()
local MAF = getSensor("MAF")
MAF = (MAF == nil and 0 or MAF)
@ -81,8 +88,11 @@ function onTick()
-- print('CLT temp' ..cltValue)
end
function onCanRxAbs1(bus, id, dlc, data)
kph = getTwoBytesMSB(data, 0, 0.005)
end
function onCanRx(bus, id, dlc, data)
function onCanRxAc(bus, id, dlc, data)
--print('got CAN id=' ..id ..' dlc=' ..dlc)
--print('ac value is= '..data[1])
if data[1] == 193 then
@ -96,4 +106,8 @@ function onCanRx(bus, id, dlc, data)
end
end
canRxAdd(IN_35D, onCanRxAbs1)
canRxAdd(IN_35D, onCanRxAc)
)", efi::size(config->luaScript));

View File

@ -83,7 +83,10 @@ static time_msecs_t mph_ctr;
#define NISSAN_VEHICLE_SPEED_280 0x280
// wheel speed see "102 CAN Communication decoded"
// 19500 value would be 100 kph
#define NISSAN_WHEEL_SPEED 0x285
// 644
#define NISSAN_WHEEL_SPEED1 0x284
// 645
#define NISSAN_WHEEL_SPEED2 0x285
// 670
#define NISSAN_UNKNOWN_4 0x29E

View File

@ -2,6 +2,14 @@
#include "rusefi_lua.h"
#include "lua_lib.h"
TEST(LuaNissan, pedalIdle) {
TEST(LuaNissan, wheelSpeed) {
#define realWheelPacket "\ndata = { 0x19, 0x6c, 0x19, 0x68, 0x0e, 0xb0, 0x37, 0x81}\n "
const char* script = TWO_BYTES_MSB realWheelPacket R"(
function testFunc()
engineTorque = getTwoBytesMSB(data, 0, 0.005)
return engineTorque
end
)";
EXPECT_NEAR_M3(testLuaReturnsNumberOrNil(script).value_or(0), 32.54);
}