custom-board-bundle-sample-.../firmware/config/engines/bmw_n73.cpp

143 lines
4.1 KiB
C++
Raw Normal View History

2021-10-02 10:25:40 -07:00
/*
* bmw_n73.cpp
*
* @date Oct 2, 2021
* @author Andrey Belomutskiy, (c) 2012-2021
*/
#include "bmw_n73.h"
void setEngineProteusBMW_N73_GDI() {
2021-10-02 10:25:40 -07:00
}
2021-12-23 13:59:30 -08:00
void setEngineProteusGearboxManInTheMiddle() {
strncpy(config->luaScript, R"(
2021-12-24 14:35:27 -08:00
function twoBytes(data, offset, factor)
return (data[offset + 2] * 256 + data[offset + 1]) * factor
end
CAN_BMW_E90_TORQUE_1 = 0x0A8
CAN_BMW_E90_TORQUE_2 = 0x0A9
2021-12-23 22:40:31 -08:00
CAN_BMW_E90_RPM_THROTTLE = 0x0AA
CAN_BMW_E90_TORQUE_DEMAND = 0x0B6
CAN_BMW_E90_IGNITION_KEY = 0x130
CAN_BMW_E65_GEAR_SELECTOR = 0x192
CAN_BMW_E90_COOLANT = 0x1D0
2021-12-28 21:50:17 -08:00
CAN_BMW_E90_LOCKING = 0x2FC
2021-12-23 22:40:31 -08:00
CAN_BMW_E90_DASH_ON = 0x332
CAN_BMW_GEAR_TORQUE_DEMAND2 = 0x0B5
2021-12-23 20:24:36 -08:00
CAN_BMW_GEAR_TRANSMISSION_DATA = 0x0BA
2021-12-23 22:40:31 -08:00
CAN_BMW_GEAR_GEARBOX_DATA_2 = 0x1A2
2021-12-23 20:24:36 -08:00
CAN_BMW_GEAR_TRANSMISSION_DISP = 0x1D2
2021-12-23 22:40:31 -08:00
CAN_BMW_GEAR_GANG_STATUS = 0x304
CAN_BMW_GEAR_NETWORK = 0x498
CAN_BMW_GEAR_SERVICE = 0x598
2021-12-23 13:59:30 -08:00
ECU_BUS = 1
GEAR_BUS = 2
canRxAdd(CAN_BMW_E90_RPM_THROTTLE)
canRxAdd(CAN_BMW_E90_TORQUE_DEMAND)
canRxAdd(CAN_BMW_E90_IGNITION_KEY)
canRxAdd(CAN_BMW_E65_GEAR_SELECTOR)
canRxAdd(CAN_BMW_E90_COOLANT)
2021-12-28 21:50:17 -08:00
canRxAdd(CAN_BMW_E90_LOCKING)
2021-12-23 22:40:31 -08:00
canRxAdd(CAN_BMW_E90_DASH_ON)
canRxAdd(CAN_BMW_GEAR_TORQUE_DEMAND2)
canRxAdd(CAN_BMW_GEAR_TRANSMISSION_DATA)
canRxAdd(CAN_BMW_GEAR_GEARBOX_DATA_2)
2021-12-23 20:24:36 -08:00
canRxAdd(CAN_BMW_GEAR_TRANSMISSION_DISP)
canRxAdd(CAN_BMW_GEAR_GANG_STATUS)
2021-12-23 22:40:31 -08:00
canRxAdd(CAN_BMW_GEAR_NETWORK)
canRxAdd(CAN_BMW_GEAR_SERVICE)
2021-12-23 13:59:30 -08:00
2021-12-23 22:40:31 -08:00
txPayload = { }
2021-12-23 20:09:52 -08:00
2021-12-28 21:50:17 -08:00
function relayToTcu(id, data)
txCan(GEAR_BUS, id, 0, data) -- relay non-TCU message to TCU
end
function printDebug(msg)
print(msg)
end
2021-12-23 20:09:52 -08:00
function onCanRx(bus, id, dlc, data)
id = id % 2048
-- local output = string.format("%x", id)
if id == CAN_BMW_E90_IGNITION_KEY then
2021-12-28 21:50:17 -08:00
printDebug('!!!!!!!!!!!!! CAN_BMW_E90_IGNITION_KEY')
relayToTcu(id, data)
2021-12-24 14:35:27 -08:00
elseif id == CAN_BMW_E90_TORQUE_1 then
2021-12-28 21:50:17 -08:00
TORQ_AVL = 0.5 * (twoBytes(data, 1, 1) >> 4)
TORQ_AVL_DMEE = 0.5 * (twoBytes(data, 3, 1) >> 4)
2021-12-29 12:38:41 -08:00
print('CAN_BMW_E90_TORQUE_1 TORQ_AVL=' .. TORQ_AVL .. ' TORQ_AVL_DMEE=' .. TORQ_AVL_DMEE)
2021-12-28 21:50:17 -08:00
relayToTcu(id, data)
2021-12-24 14:35:27 -08:00
elseif id == CAN_BMW_E90_TORQUE_2 then
2021-12-28 21:50:17 -08:00
printDebug('CAN_BMW_E90_TORQUE_2')
relayToTcu(id, data)
2021-12-24 14:35:27 -08:00
elseif id == CAN_BMW_E90_TORQUE_DEMAND then
2021-12-28 21:50:17 -08:00
printDebug('CAN_BMW_E90_TORQUE_DEMAND')
relayToTcu(id, data)
2021-12-24 14:35:27 -08:00
elseif id == CAN_BMW_E90_DASH_ON then
2021-12-28 21:50:17 -08:00
printDebug('CAN_BMW_E90_DASH_ON')
relayToTcu(id, data)
2021-12-23 22:40:31 -08:00
elseif id == CAN_BMW_E65_GEAR_SELECTOR then
2021-12-28 21:50:17 -08:00
printDebug('CAN_BMW_E65_GEAR_SELECTOR')
relayToTcu(id, data)
2021-12-23 22:40:31 -08:00
elseif id == CAN_BMW_E65_GEAR_SELECTOR then
2021-12-28 21:50:17 -08:00
printDebug('CAN_BMW_E65_GEAR_SELECTOR')
relayToTcu(id, data)
2021-12-23 22:40:31 -08:00
elseif id == CAN_BMW_E90_RPM_THROTTLE then
2021-12-24 14:35:27 -08:00
rpm = twoBytes(data, 4, 0.25)
2021-12-29 12:38:41 -08:00
print('CAN_BMW_E90_RPM_THROTTLE rpm=' .. rpm)
2021-12-28 21:50:17 -08:00
relayToTcu(id, data)
2021-12-23 22:40:31 -08:00
elseif id == CAN_BMW_E90_COOLANT then
2021-12-28 21:50:17 -08:00
printDebug('CAN_BMW_E90_COOLANT')
relayToTcu(id, data)
elseif id == CAN_BMW_E90_LOCKING then
printDebug('CAN_BMW_E90_LOCKING')
relayToTcu(id, data)
2021-12-23 22:40:31 -08:00
elseif id == CAN_BMW_GEAR_TORQUE_DEMAND2 then
2021-12-28 21:50:17 -08:00
printDebug('*******CAN_BMW_GEAR_TORQUE_DEMAND2')
2021-12-23 22:40:31 -08:00
txCan(ECU_BUS, id, 0, data) -- relay TCU message to non-TCU
elseif id == CAN_BMW_GEAR_TRANSMISSION_DATA then
2021-12-28 21:50:17 -08:00
printDebug('*******CAN_BMW_GEAR_TRANSMISSION_DATA')
2021-12-23 22:40:31 -08:00
txCan(ECU_BUS, id, 0, data) -- relay TCU message to non-TCU
elseif id == CAN_BMW_GEAR_TRANSMISSION_DISP then
2021-12-28 21:50:17 -08:00
printDebug('*******CAN_BMW_GEAR_TRANSMISSION_DISP')
2021-12-23 22:40:31 -08:00
txCan(ECU_BUS, id, 0, data) -- relay TCU message to non-TCU
elseif id == CAN_BMW_GEAR_GANG_STATUS then
2021-12-28 21:50:17 -08:00
printDebug('*******CAN_BMW_GEAR_GANG_STATUS')
2021-12-23 22:40:31 -08:00
txCan(ECU_BUS, id, 0, data) -- relay TCU message to non-TCU
elseif id == CAN_BMW_GEAR_GEARBOX_DATA_2 then
2021-12-28 21:50:17 -08:00
printDebug('CAN_BMW_GEAR_GEARBOX_DATA_2')
2021-12-23 22:40:31 -08:00
txCan(ECU_BUS, id, 0, data) -- relay TCU message to non-TCU
elseif id == CAN_BMW_GEAR_NETWORK then
2021-12-28 21:50:17 -08:00
printDebug('CAN_BMW_GEAR_NETWORK')
2021-12-23 22:40:31 -08:00
txCan(ECU_BUS, id, 0, data) -- relay TCU message to non-TCU
elseif id == CAN_BMW_GEAR_SERVICE then
2021-12-28 21:50:17 -08:00
printDebug('CAN_BMW_GEAR_SERVICE')
2021-12-23 22:40:31 -08:00
txCan(ECU_BUS, id, 0, data) -- relay TCU message to non-TCU
2021-12-23 20:09:52 -08:00
else
2021-12-29 12:38:41 -08:00
print('No handler for ' .. id)
2021-12-23 20:09:52 -08:00
end
2021-12-29 12:38:41 -08:00
printDebug('got CAN id=' ..id ..' dlc=' ..dlc)
2021-12-23 22:40:31 -08:00
end
2021-12-23 20:09:52 -08:00
2021-12-23 13:59:30 -08:00
function onTick()
2021-12-23 22:40:31 -08:00
-- txCan(1, 0x611, 1, txPayload)
-- txCan(2, 0x612, 1, txPayload)
2021-12-23 13:59:30 -08:00
end
2021-12-23 22:40:31 -08:00
2021-12-23 13:59:30 -08:00
)", efi::size(config->luaScript));
}