15 {
19
20#if HW_PROTEUS
22
23 setPPSInputs(PROTEUS_IN_ANALOG_VOLT_2, PROTEUS_IN_ANALOG_VOLT_11);
24 setTPS1Inputs(PROTEUS_IN_ANALOG_VOLT_4, PROTEUS_IN_ANALOG_VOLT_3);
25
26
27#endif
28
29#if defined(HW_HELLEN_8CHAN)
38
45#endif
46
50
55
58
59
61
62function getBitRange(data, bitIndex, bitWidth)
63 byteIndex = bitIndex >> 3
64 shift = bitIndex - byteIndex * 8
65 value = data[1 + byteIndex]
66 if (shift + bitWidth > 8) then
67 value = value + data[2 + byteIndex] * 256
68 end
69 mask = (1 << bitWidth) - 1
70 return (value >> shift) & mask
71end
72
73hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
74
75function toHexString(num)
76 if num == 0 then
77 return '0'
78 end
79
80 local result = ""
81 while num > 0 do
82 local n = num % 16
83 result = hexstr[n + 1] ..result
84 num = math.floor(num / 16)
85 end
86 return result
87end
88
89function arrayToString(arr)
90 local str = ""
91 local index = 1
92 while arr[index] ~= nil do
93 str = str.." "..toHexString(arr[index])
94 index = index + 1
95 end
96 return str
97end
98
99STARTER_OUTPUT_INDEX = 0
100startPwm(STARTER_OUTPUT_INDEX, 100, 0)
101
102-- 201
103ECMEngineStatus = 0xC9
104IGN_STATUS = 0x1f1
105-- 0x514
106VIN_Part1 = 1300
107-- 04E1
108VIN_Part2 = 1249
109
110setTickRate(100)
111
112function canIgnStatus(bus, id, dlc, data)
113 crankingBits = getBitRange(data, 2, 2)
114 isCranking = (crankingBits == 2)
115-- need special considerations to append boolean print('crankingBits ' .. crankingBits .. ', isCranking ' .. isCranking)
116 print('crankingBits ' .. crankingBits)
117end
118
119function printAny(bus, id, dlc, data)
120 print('packet ' .. id)
121end
122
123canRxAdd(IGN_STATUS, canIgnStatus)
124-- canRxAddMask(0, 0xFFFFFFF, printAny)
125
126-- todo: take VIN from configuration? encode VIN?
127canVin1 = { 0x47, 0x4E, 0x4C, 0x43, 0x32, 0x45, 0x30, 0x34 }
128canVin2 = { 0x42, 0x52, 0x32, 0x31, 0x36, 0x33, 0x36, 0x36 }
129dataECMEngineStatus = { 0x84, 0x09, 0x99, 0x0A, 0x00, 0x40, 0x08, 0x00 }
130
131-- todo: smarter loop code :)
132canVin1[1] = vin(1)
133canVin1[2] = vin(2)
134canVin1[3] = vin(3)
135canVin1[4] = vin(4)
136canVin1[5] = vin(5)
137canVin1[6] = vin(6)
138canVin1[7] = vin(7)
139canVin1[8] = vin(8)
140
141canVin2[1] = vin(9)
142canVin2[2] = vin(10)
143canVin2[3] = vin(11)
144canVin2[4] = vin(12)
145canVin2[5] = vin(13)
146canVin2[6] = vin(14)
147canVin2[7] = vin(15)
148canVin2[8] = vin(16)
149
150function onTick()
151 txCan(1, VIN_Part1, 0, canVin1)
152 txCan(1, VIN_Part2, 0, canVin2)
153
154 -- good enough for fuel module!
155 txCan(1, ECMEngineStatus, 0, dataECMEngineStatus)
156
157 if isCranking then
158 setPwmDuty(STARTER_OUTPUT_INDEX, 1)
159 else
160 setPwmDuty(STARTER_OUTPUT_INDEX, 0)
161 end
162end
163
165
168}
void setTPS1Calibration(uint16_t tpsMin, uint16_t tpsMax)
void setPPSInputs(adc_channel_e pps1, adc_channel_e pps2)
void setTPS1Inputs(adc_channel_e tps1, adc_channel_e tps2)
void setPPSCalibration(float primaryUp, float primaryDown, float secondaryUp, float secondaryDown)
void setLeftRightBanksNeedBetterName()
static constexpr persistent_config_s * config
static constexpr engine_configuration_s * engineConfiguration
air_pressure_sensor_config_s sensor
vehicle_info_t engineMake
angle_t globalTriggerAngleOffset
float fuelReferencePressure
float tChargeAirIncrLimit
dc_function_e etbFunctions[ETB_COUNT]
output_pin_e vvtPins[CAM_INPUTS_COUNT]
output_pin_e injectionPins[MAX_CYLINDER_COUNT]
float tChargeAirDecrLimit
brain_input_pin_e triggerInputPins[TRIGGER_INPUT_PIN_COUNT]
injector_compensation_mode_e injectorCompensationMode
firing_order_e firingOrder
vehicle_info_t engineCode
brain_input_pin_e camInputs[CAM_INPUTS_COUNT]
output_pin_e ignitionPins[MAX_CYLINDER_COUNT]