15 {
20
22
25
31
32
33#if HW_PROTEUS
35
36 setPPSInputs(PROTEUS_IN_ANALOG_VOLT_2, PROTEUS_IN_ANALOG_VOLT_11);
37 setTPS1Inputs(PROTEUS_IN_ANALOG_VOLT_4, PROTEUS_IN_ANALOG_VOLT_3);
38
39
40#endif
41
42#if defined(HW_HELLEN_8CHAN)
51
58#endif
59
60#ifdef HW_HELLEN_UAEFI
63
65
67
73
75
77
78
81
84
85#endif
86
90
96
99
100
102
103function getBitRange(data, bitIndex, bitWidth)
104 byteIndex = bitIndex >> 3
105 shift = bitIndex - byteIndex * 8
106 value = data[1 + byteIndex]
107 if (shift + bitWidth > 8) then
108 value = value + data[2 + byteIndex] * 256
109 end
110 mask = (1 << bitWidth) - 1
111 return (value >> shift) & mask
112end
113
114hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
115
116function toHexString(num)
117 if num == 0 then
118 return '0'
119 end
120
121 local result = ""
122 while num > 0 do
123 local n = num % 16
124 result = hexstr[n + 1] ..result
125 num = math.floor(num / 16)
126 end
127 return result
128end
129
130function arrayToString(arr)
131 local str = ""
132 local index = 1
133 while arr[index] ~= nil do
134 str = str.." "..toHexString(arr[index])
135 index = index + 1
136 end
137 return str
138end
139
140STARTER_OUTPUT_INDEX = 0
141startPwm(STARTER_OUTPUT_INDEX, 100, 0)
142
143-- 201
144ECMEngineStatus = 0xC9
145IGN_STATUS = 0x1f1
146-- 0x514
147VIN_Part1 = 1300
148-- 04E1
149VIN_Part2 = 1249
150
151setTickRate(100)
152
153function canIgnStatus(bus, id, dlc, data)
154 crankingBits = getBitRange(data, 2, 2)
155 isCranking = (crankingBits == 2)
156-- need special considerations to append boolean print('crankingBits ' .. crankingBits .. ', isCranking ' .. isCranking)
157 print('crankingBits ' .. crankingBits)
158end
159
160function printAny(bus, id, dlc, data)
161 print('packet ' .. id)
162end
163
164canRxAdd(IGN_STATUS, canIgnStatus)
165-- canRxAddMask(0, 0xFFFFFFF, printAny)
166
167-- todo: take VIN from configuration? encode VIN?
168canVin1 = { 0x47, 0x4E, 0x4C, 0x43, 0x32, 0x45, 0x30, 0x34 }
169canVin2 = { 0x42, 0x52, 0x32, 0x31, 0x36, 0x33, 0x36, 0x36 }
170dataECMEngineStatus = { 0x84, 0x09, 0x99, 0x0A, 0x00, 0x40, 0x08, 0x00 }
171
172-- todo: smarter loop code :)
173canVin1[1] = vin(1)
174canVin1[2] = vin(2)
175canVin1[3] = vin(3)
176canVin1[4] = vin(4)
177canVin1[5] = vin(5)
178canVin1[6] = vin(6)
179canVin1[7] = vin(7)
180canVin1[8] = vin(8)
181
182canVin2[1] = vin(9)
183canVin2[2] = vin(10)
184canVin2[3] = vin(11)
185canVin2[4] = vin(12)
186canVin2[5] = vin(13)
187canVin2[6] = vin(14)
188canVin2[7] = vin(15)
189canVin2[8] = vin(16)
190
191function onTick()
192 txCan(1, VIN_Part1, 0, canVin1)
193 txCan(1, VIN_Part2, 0, canVin2)
194
195 -- good enough for fuel module!
196 txCan(1, ECMEngineStatus, 0, dataECMEngineStatus)
197
198 if isCranking then
199 setPwmDuty(STARTER_OUTPUT_INDEX, 1)
200 else
201 setPwmDuty(STARTER_OUTPUT_INDEX, 0)
202 end
203end
204
206
209}
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
air_pressure_sensor_type_e type
vehicle_info_t engineMake
angle_t globalTriggerAngleOffset
float fuelReferencePressure
float tChargeAirIncrLimit
ignition_mode_e ignitionMode
dc_function_e etbFunctions[ETB_COUNT]
cranking_parameters_s cranking
output_pin_e vvtPins[CAM_INPUTS_COUNT]
vvt_mode_e vvtMode[CAMS_PER_BANK]
output_pin_e injectionPins[MAX_CYLINDER_COUNT]
bool invertPrimaryTriggerSignal
float tChargeAirDecrLimit
float etbIdleThrottleRange
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]