commonGenesisCoupe CAN lua fix #5244

This commit is contained in:
rusefillc 2023-04-21 10:55:33 -04:00
parent 7dc06ccbe0
commit 27e4265ba9
1 changed files with 76 additions and 20 deletions

View File

@ -39,31 +39,87 @@ void setProteusHyundaiPb() {
static void commonGenesisCoupe() {
strncpy(config->luaScript, R"(
-- code outside of functions is invoked once on start-up
-- listen to CAN ID 0x4f0
canRxAdd(0x4f0)
setTickRate(100)
t = Timer.new()
t : reset()
-- todo: add payload logic
packet4f1 = { 0xFA, 0x54, 0x00, 0x0, 0x00, 0x51, 0x00, 0x00 }
local data_0x329 = { 0x2C, 0x96, 0x80, 0x0E, 0x11, 0x2E, 0x00, 0x14 }
local slowCounter = 0
local slowRoll = 0
function onCanRx(bus, id, dlc, data)
print('got CAN id=' .. id .. ' dlc=' .. dlc)
-- todo: add filtering logic if needed
local slowRollTable = { 0x0C, 0x4F, 0x80, 0xE3 }
rpm = getSensor("RPM")
-- handle nil RPM, todo: change firmware to avoid nil RPM
rpm = (rpm == nil and 0 or rpm)
if rpm > 800 then
-- at the moment we simply
txCan(1, 0x4f1, 0, packet4f1)
end
end
-- wakeup CAN messages
local data_0x382 = { 0x00, 0x3A, 0X44, 0x24, 0x00, 0x00, 0x00, 0x00 }
local data_0x0a0 = { 0x00, 0x68, 0x00, 0x00, 0x00, 0xFF, 0x01, 0x00 }
local data_0x0a1 = { 0x80, 0x80, 0x00, 0x00, 0xEC, 0x00, 0x00, 0x00 }
local data_0x18f = { 0xFA , 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
local data_0x545 = { 0xEC, 0x00, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00 }
local data_0xA1 = { 0x80, 0x80, 0x00, 0x00, 0xEC, 0x00, 0x00, 0x00 }
local data_0xA0 = { 0x00, 0x68, 0x00, 0x00, 0x00, 0xFF, 0x01, 0x00 }
local data_0x260 = { 0x01, 0x1A, 0x1A, 0x10, 0x00, 0xAB, 0x93, 0x00 }
local data_0x2A0 = { 0x00, 0x00, 0x04, 0x00, 0x78, 0x05, 0x0D, 0x01 }
function onTick()
-- empty function onTick we are not doing anything periodically so far
-- keep alives
txCan(1, 0x18f, 0, data_0x18f)
txCan(1, 0x545, 0, data_0x545)
-- more random can sends
txCan(1, 0x545, 0, data_0x545)
txCan(1, 0x382, 0, data_0x382)
txCan(1, 0xA0, 0, data_0xA0)
txCan(1, 0xA1, 0, data_0xA1)
txCan(1, 0x260, 0, data_0x260)
txCan(1, 0x2A0, 0, data_0x2A0)
local RPMread = math.floor(getSensor("RPM") + 0.5) * 4
local RPMhi = RPMread >> 8
local RPMlo = RPMread & 0xff
local CLTread = 50
if getSensor("CLT") then
CLTread = math.floor(getSensor("CLT") + 0.5)
else
CLTread = 50
end
local CLThi = CLTread
local CLTlo = CLTread * 256
canCLTpayloadNo = { 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
canCLTpayloadLo = { 0x00, 0x4C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
canCLTpayloadHi = { 0x00, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
canCLTpayloadHi2 = { 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
if slowCounter == 0 then
-- cycle through 0, 40, 80, c0
slowRoll = (slowRoll + 1) & 3
data_0x329[1] = slowRollTable[slowRoll + 1]
txCan(1, 0x329, 0, data_0x329)
slowCounter = 30
end
slowCounter = slowCounter -1
-- rpm fun stuff
if t : getElapsedSeconds() < 1.5 then
canRPMpayload = { 0x05, 0x1C, 0xFC, 0x7B, 0x1C, 0x2F, 0x00, 0x80 }
else
canRPMpayload = { 0x05, RPMlo, RPMhi, RPMhi, RPMlo, 0x2F, 0x00, 0x80 }
end
txCan(1, 0x316, 0, canRPMpayload)
if CLTread < 60 then
txCan(1, 0x608, 0, canCLTpayloadNo)
elseif CLTread >= 60 and CLTread < 85 then
txCan(1, 0x608, 0, canCLTpayloadLo)
elseif CLTread >= 85 and CLTread < 110 then
txCan(1, 0x608, 0, canCLTpayloadHi)
else
txCan(1, 0x608, 0, canCLTpayloadHi2)
end
end