5 {
14
16
17#ifdef HW_SMALL_CAN_BOARD
19-- this controls onCanRx rate as well!
20setTickRate(300)
21
22timeout = 3000
23
24rpmSensor = Sensor.new("rpm")
25rpmSensor : setTimeout(timeout)
26
27ppsSensor = Sensor.new("AcceleratorPedal")
28ppsSensor : setTimeout(timeout)
29
30speedSensor = Sensor.new("VehicleSpeed")
31speedSensor : setTimeout(timeout)
32
33canTimer = Timer.new()
34canTimer : reset()
35
36hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
37
38function getTwoBytesMSB(data, offset, factor)
39 return (data[offset + 1] * 256 + data[offset + 2]) * factor
40end
41
42function getTwoBytesLSB(data, offset, factor)
43 return (data[offset + 2] * 256 + data[offset + 1]) * factor
44end
45
46function onPOWERTRAIN_DATA(bus, id, dlc, data)
47 canTimer : reset()
48-- print('onPOWERTRAIN_DATA ' ..arrayToString(data))
49
50 ppsValue = data[1] * 100.0 / 255
51 ppsSensor : set(ppsValue)
52
53 rpmValue = getTwoBytesMSB(data, 2, 1)
54 rpmSensor : set(rpmValue)
55-- print('onPOWERTRAIN_DATA ' .. rpmValue .. ' pedal ' .. ppsValue)
56end
57
58function onCAR_SPEED(bus, id, dlc, data)
59 canTimer : reset()
60 speedKph = getTwoBytesLSB(data, 1, 0.01)
61 print('onCAR_SPEED ' .. speedKph)
62 speedSensor : set(speedKph)
63
64 print('onPOWERTRAIN_DATA speed' .. speedKph .. ' ratio ' .. (speedKph / rpmValue))
65
66end
67
68canRxAdd(1, 0x17C, onPOWERTRAIN_DATA)
69canRxAdd(1, 0x309, onCAR_SPEED)
70
71commTimer = Timer.new()
72commTimer : reset()
73
74canDelay = 1
75commDelay = 20
76
77function onTick()
78 if getOutput("isUsbConnected") == 1 then
79 commTimer : reset()
80 end
81 if (canTimer : getElapsedSeconds() > canDelay) and (commTimer : getElapsedSeconds() > commDelay) then
82 mcu_standby()
83 end
84end
86#endif
87}
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