diff --git a/B6-TCU/B6-2024-july.txt b/B6-TCU/B6-2024-july.txt index 10280dc8..43c5f446 100644 --- a/B6-TCU/B6-2024-july.txt +++ b/B6-TCU/B6-2024-july.txt @@ -4,4 +4,22 @@ -- endinclude -- include utils.lua --- endinclude \ No newline at end of file +-- 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 + diff --git a/B6-TCU/B6-temp-TCU-main-in-the-middle-new-approach-now-with-replacement.txt b/B6-TCU/B6-temp-TCU-main-in-the-middle-new-approach-now-with-replacement.txt index 64a3c20b..39daf597 100644 --- a/B6-TCU/B6-temp-TCU-main-in-the-middle-new-approach-now-with-replacement.txt +++ b/B6-TCU/B6-temp-TCU-main-in-the-middle-new-approach-now-with-replacement.txt @@ -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 () diff --git a/B6-TCU/can_ids.lua b/B6-TCU/can_ids.lua index 4a3ccb7c..dd62bbd1 100644 --- a/B6-TCU/can_ids.lua +++ b/B6-TCU/can_ids.lua @@ -20,9 +20,5 @@ MOTOR_INFO = 0x580 MOTOR_7 = 0x588 +Diagnose_1 = 2000 - - -ECU_BUS = 1 --- really 'not ECU' -TCU_BUS = 2 \ No newline at end of file diff --git a/B6-TCU/utils.lua b/B6-TCU/utils.lua index 447a9c9f..03279a6a 100644 --- a/B6-TCU/utils.lua +++ b/B6-TCU/utils.lua @@ -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 \ No newline at end of file