new skeleton

This commit is contained in:
rusEFI LLC 2024-06-30 16:41:04 -04:00
parent 2003b22275
commit a72efe47f7
4 changed files with 40 additions and 33 deletions

View File

@ -5,3 +5,21 @@
-- include utils.lua
-- endinclude
setTickRate(100)
canRxAdd(ECU_BUS, Diagnose_1, silentlyRelayFromECU)
canRxAddMask(ECU_BUS, 0, 0, silentlyRelayFromECU)
canRxAddMask(TCU_BUS, 0, 0, silentlyRelayFromTCU)
everySecondTimer = Timer.new()
function onTick()
if everySecondTimer : getElapsedSeconds() > 1 then
everySecondTimer : reset()
print("Total from ECU " ..totalEcuMessages .. " totalTcuMessages " .. totalTcuMessages)
end
end

View File

@ -79,33 +79,8 @@ fakeTorque = 0
rpm = 0
tps = 0
function xorChecksum(data, targetIndex)
local index = 1
local result = 0
while data[index] ~= nil do
if index ~= targetIndex then
result = result ~ data[index]
end
index = index + 1
end
data[targetIndex] = result
return result
end
function setBitRange(data, totalBitIndex, bitWidth, value)
local byteIndex = totalBitIndex >> 3
local bitInByteIndex = totalBitIndex - byteIndex * 8
if (bitInByteIndex + bitWidth > 8) then
bitsToHandleNow = 8 - bitInByteIndex
setBitRange(data, totalBitIndex + bitsToHandleNow, bitWidth - bitsToHandleNow, value >> bitsToHandleNow)
bitWidth = bitsToHandleNow
end
mask = (1 << bitWidth) - 1
data[1 + byteIndex] = data[1 + byteIndex] & (~(mask << bitInByteIndex))
maskedValue = value & mask
shiftedValue = maskedValue << bitInByteIndex
data[1 + byteIndex] = data[1 + byteIndex] | shiftedValue
end
-- include utils.lua
-- endinclude
function relayFromECU(bus, id, dlc, data)
onEcuTimer : reset ()

View File

@ -20,9 +20,5 @@ MOTOR_INFO = 0x580
MOTOR_7 = 0x588
Diagnose_1 = 2000
ECU_BUS = 1
-- really 'not ECU'
TCU_BUS = 2

View File

@ -1,3 +1,16 @@
ECU_BUS = 1
-- really 'not ECU'
TCU_BUS = 2
totalEcuMessages = 0
totalTcuMessages = 0
function relayFromTCU(bus, id, dlc, data)
totalTcuMessages = totalTcuMessages + 1
-- print("Relaying to ECU " .. id)
txCan(ECU_BUS, id, 0, data) -- relay non-ECU message to ECU
end
function xorChecksum(data, targetIndex)
local index = 1
local result = 0
@ -78,3 +91,8 @@ function silentlyRelayFromECU(bus, id, dlc, data)
totalEcuMessages = totalEcuMessages + 1
txCan(TCU_BUS, id, 0, data)
end
function silentlyRelayFromTCU(bus, id, dlc, data)
totalTcuMessages = totalTcuMessages + 1
txCan(ECU_BUS, id, 0, data) -- relay non-ECU message to ECU
end