From 7645bfe0e7fd048bd6bdbb03c0dc5076896901c7 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 21 Sep 2023 22:06:44 -0400 Subject: [PATCH] only:canam only:proteus_f7 --- firmware/config/engines/canam.cpp | 24 +------------------ firmware/config/engines/canam_2021.lua | 23 ++++++++++++++++++ .../lua/examples/man-in-the-middle.txt | 7 +++++- 3 files changed, 30 insertions(+), 24 deletions(-) create mode 100644 firmware/config/engines/canam_2021.lua diff --git a/firmware/config/engines/canam.cpp b/firmware/config/engines/canam.cpp index 4945af7840..14af830403 100644 --- a/firmware/config/engines/canam.cpp +++ b/firmware/config/engines/canam.cpp @@ -27,29 +27,7 @@ void setMaverickX3() { #endif // HW_PROTEUS #if HW_PROTEUS - strncpy(config->luaScript, GET_BIT_RANGE_LSB TWO_BYTES_LSB PRINT_ARRAY SET_TWO_BYTES_LSB R"( - - -isUseful = Timer.new() -isUseful : reset() - -function onTick() - -rpm = getSensor("RPM") -vbat = getSensor("BatteryVoltage") - --- print (vbat .. " " .. rpm) -if (vbat < 8) or (rpm > 200) then --- keep alive if USB hooked up -isUseful : reset() -end - - if (isUseful : getElapsedSeconds() > 17) then - mcu_standby() - end -end - -)", efi::size(config->luaScript)); + #include "canam_2021.lua" #endif // HW_PROTEUS } \ No newline at end of file diff --git a/firmware/config/engines/canam_2021.lua b/firmware/config/engines/canam_2021.lua new file mode 100644 index 0000000000..b0d2d2bf52 --- /dev/null +++ b/firmware/config/engines/canam_2021.lua @@ -0,0 +1,23 @@ + strncpy(config->luaScript, GET_BIT_RANGE_LSB TWO_BYTES_LSB PRINT_ARRAY SET_TWO_BYTES_LSB R"( + + +isUseful = Timer.new() +isUseful : reset() + +function onTick() + +rpm = getSensor("RPM") +vbat = getSensor("BatteryVoltage") + +-- print (vbat .. " " .. rpm) +if (vbat < 8) or (rpm > 200) then +-- keep alive if USB hooked up +isUseful : reset() +end + + if (isUseful : getElapsedSeconds() > 17) then + mcu_standby() + end +end + +)", efi::size(config->luaScript)); \ No newline at end of file diff --git a/firmware/controllers/lua/examples/man-in-the-middle.txt b/firmware/controllers/lua/examples/man-in-the-middle.txt index 31d705b6df..45a5742101 100644 --- a/firmware/controllers/lua/examples/man-in-the-middle.txt +++ b/firmware/controllers/lua/examples/man-in-the-middle.txt @@ -36,13 +36,17 @@ end totalEcuMessages = 0 totalTcuMessages = 0 +totalDropped = 0 +totalReplaced = 0 function printAndDrop(bus, id, dlc, data) print('Dropping ' ..arrayToString(data)) + totalDropped = totalDropped + 1 end function onAnythingFromECU(bus, id, dlc, data) totalEcuMessages = totalEcuMessages + 1 + print('from ECU ' .. id .. " " .. arrayToString(data) .. " dropped=" .. totalDropped .. " replaced " .. totalReplaced) txCan(TCU_BUS, id, 0, data) -- relay non-TCU message to TCU end @@ -54,6 +58,7 @@ end MOTOR_1 = 0x282 function interceptAndReplaceContent(bus, id, dlc, data) + totalReplaced = totalReplaced + 1 rpm = 200 data[3] = rpm -- send adjusted packet into the other bus @@ -73,6 +78,6 @@ everySecondTimer = Timer.new() function onTick() if everySecondTimer:getElapsedSeconds() > 1 then everySecondTimer:reset() - print("Total from ECU " .. totalEcuMessages .. " from TCU " .. totalTcuMessages) + print("Total from ECU " .. totalEcuMessages .. " from TCU " .. totalTcuMessages .. " dropped=" .. totalDropped .. " replaced " .. totalReplaced) end end