16 {
21
23
26
32
33
34#if HW_PROTEUS
36
37 setPPSInputs(PROTEUS_IN_ANALOG_VOLT_2, PROTEUS_IN_ANALOG_VOLT_11);
38 setTPS1Inputs(PROTEUS_IN_ANALOG_VOLT_4, PROTEUS_IN_ANALOG_VOLT_3);
39
40
41#endif
42
43#if defined(HW_HELLEN_8CHAN)
52
59#endif
60
61#ifdef HW_HELLEN_UAEFI121
63
64
69
71
73#endif
74
75#ifdef HW_HELLEN_UAEFI
78
80
82
88
90
92
93
96
99
100#endif
101
105
113
119
122
123
125
126function getBitRange(data, bitIndex, bitWidth)
127 byteIndex = bitIndex >> 3
128 shift = bitIndex - byteIndex * 8
129 value = data[1 + byteIndex]
130 if (shift + bitWidth > 8) then
131 value = value + data[2 + byteIndex] * 256
132 end
133 mask = (1 << bitWidth) - 1
134 return (value >> shift) & mask
135end
136
137hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
138
139function toHexString(num)
140 if num == 0 then
141 return '0'
142 end
143
144 local result = ""
145 while num > 0 do
146 local n = num % 16
147 result = hexstr[n + 1] ..result
148 num = math.floor(num / 16)
149 end
150 return result
151end
152
153function arrayToString(arr)
154 local str = ""
155 local index = 1
156 while arr[index] ~= nil do
157 str = str.." "..toHexString(arr[index])
158 index = index + 1
159 end
160 return str
161end
162
163STARTER_OUTPUT_INDEX = 0
164startPwm(STARTER_OUTPUT_INDEX, 100, 0)
165
166-- 201
167ECMEngineStatus = 0xC9
168IGN_STATUS = 0x1f1
169-- 0x514
170VIN_Part1 = 1300
171-- 04E1
172VIN_Part2 = 1249
173
174setTickRate(100)
175
176function canIgnStatus(bus, id, dlc, data)
177 crankingBits = getBitRange(data, 2, 2)
178 isCranking = (crankingBits == 2)
179-- need special considerations to append boolean print('crankingBits ' .. crankingBits .. ', isCranking ' .. isCranking)
180 print('crankingBits ' .. crankingBits)
181end
182
183function printAny(bus, id, dlc, data)
184 print('packet ' .. id)
185end
186
187canRxAdd(IGN_STATUS, canIgnStatus)
188-- canRxAddMask(0, 0xFFFFFFF, printAny)
189
190-- todo: take VIN from configuration? encode VIN?
191canVin1 = { 0x47, 0x4E, 0x4C, 0x43, 0x32, 0x45, 0x30, 0x34 }
192canVin2 = { 0x42, 0x52, 0x32, 0x31, 0x36, 0x33, 0x36, 0x36 }
193dataECMEngineStatus = { 0x84, 0x09, 0x99, 0x0A, 0x00, 0x40, 0x08, 0x00 }
194
195-- todo: smarter loop code :)
196canVin1[1] = vin(1)
197canVin1[2] = vin(2)
198canVin1[3] = vin(3)
199canVin1[4] = vin(4)
200canVin1[5] = vin(5)
201canVin1[6] = vin(6)
202canVin1[7] = vin(7)
203canVin1[8] = vin(8)
204
205canVin2[1] = vin(9)
206canVin2[2] = vin(10)
207canVin2[3] = vin(11)
208canVin2[4] = vin(12)
209canVin2[5] = vin(13)
210canVin2[6] = vin(14)
211canVin2[7] = vin(15)
212canVin2[8] = vin(16)
213
214function onTick()
215 txCan(1, VIN_Part1, 0, canVin1)
216 txCan(1, VIN_Part2, 0, canVin2)
217
218 -- good enough for fuel module!
219 txCan(1, ECMEngineStatus, 0, dataECMEngineStatus)
220
221 if isCranking then
222 setPwmDuty(STARTER_OUTPUT_INDEX, 1)
223 else
224 setPwmDuty(STARTER_OUTPUT_INDEX, 0)
225 end
226end
227
228 )");
229
232}
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 engine_configuration_s * engineConfiguration
void setLuaScript(const char *luaScript)
air_pressure_sensor_config_s sensor
air_pressure_sensor_type_e type
vehicle_info_t engineMake
angle_t globalTriggerAngleOffset
float fuelReferencePressure
float tChargeAirIncrLimit
float tpsDecelEnleanmentThreshold
float tpsAccelFractionDivisor
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
float tpsAccelEnrichmentThreshold
vehicle_info_t engineCode
brain_input_pin_e camInputs[CAM_INPUTS_COUNT]
output_pin_e ignitionPins[MAX_CYLINDER_COUNT]
scaled_channel< uint8_t, 20, 1 > tpsAccelLookback
int16_t tpsAccelFractionPeriod