17#ifdef HW_SMALL_CAN_BOARD
19-- this controls onCanRx rate as well!
24rpmSensor = Sensor.new("rpm")
25rpmSensor : setTimeout(timeout)
27ppsSensor = Sensor.new("AcceleratorPedal")
28ppsSensor : setTimeout(timeout)
30speedSensor = Sensor.new("VehicleSpeed")
31speedSensor : setTimeout(timeout)
36hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
38function getTwoBytesMSB(data, offset, factor)
39 return (data[offset + 1] * 256 + data[offset + 2]) * factor
42function getTwoBytesLSB(data, offset, factor)
43 return (data[offset + 2] * 256 + data[offset + 1]) * factor
46function onPOWERTRAIN_DATA(bus, id, dlc, data)
48-- print('onPOWERTRAIN_DATA ' ..arrayToString(data))
50 ppsValue = data[1] * 100.0 / 255
51 ppsSensor : set(ppsValue)
53 rpmValue = getTwoBytesMSB(data, 2, 1)
54 rpmSensor : set(rpmValue)
55-- print('onPOWERTRAIN_DATA ' .. rpmValue .. ' pedal ' .. ppsValue)
58function onCAR_SPEED(bus, id, dlc, data)
60 speedKph = getTwoBytesLSB(data, 1, 0.01)
61 print('onCAR_SPEED ' .. speedKph)
62 speedSensor : set(speedKph)
64 print('onPOWERTRAIN_DATA speed' .. speedKph .. ' ratio ' .. (speedKph / rpmValue))
68canRxAdd(1, 0x17C, onPOWERTRAIN_DATA)
69canRxAdd(1, 0x309, onCAR_SPEED)
71commTimer = Timer.new()
78 if getOutput("isUsbConnected") == 1 then
81 if (canTimer : getElapsedSeconds() > canDelay) and (commTimer : getElapsedSeconds() > commDelay) then
void setBodyControlUnit()
static constexpr persistent_config_s * config
static constexpr engine_configuration_s * engineConfiguration
scaled_channel< uint16_t, 100, 1 > gearRatio[TCU_GEAR_COUNT]
bool isBoostControlEnabled