37 setPPSInputs(PROTEUS_IN_ANALOG_VOLT_2, PROTEUS_IN_ANALOG_VOLT_11);
38 setTPS1Inputs(PROTEUS_IN_ANALOG_VOLT_4, PROTEUS_IN_ANALOG_VOLT_3);
43#if defined(HW_HELLEN_8CHAN)
112function getBitRange(data, bitIndex, bitWidth)
113 byteIndex = bitIndex >> 3
114 shift = bitIndex - byteIndex * 8
115 value = data[1 + byteIndex]
116 if (shift + bitWidth > 8) then
117 value = value + data[2 + byteIndex] * 256
119 mask = (1 << bitWidth) - 1
120 return (value >> shift) & mask
123hexstr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F" }
125function toHexString(num)
133 result = hexstr[n + 1] ..result
134 num = math.floor(num / 16)
139function arrayToString(arr)
142 while arr[index] ~= nil do
143 str = str.." "..toHexString(arr[index])
149STARTER_OUTPUT_INDEX = 0
150startPwm(STARTER_OUTPUT_INDEX, 100, 0)
153ECMEngineStatus = 0xC9
162function canIgnStatus(bus, id, dlc, data)
163 crankingBits = getBitRange(data, 2, 2)
164 isCranking = (crankingBits == 2)
165-- need special considerations to append boolean print('crankingBits ' .. crankingBits .. ', isCranking ' .. isCranking)
166 print('crankingBits ' .. crankingBits)
169function printAny(bus, id, dlc, data)
170 print('packet ' .. id)
173canRxAdd(IGN_STATUS, canIgnStatus)
174-- canRxAddMask(0, 0xFFFFFFF, printAny)
176-- todo: take VIN from configuration? encode VIN?
177canVin1 = { 0x47, 0x4E, 0x4C, 0x43, 0x32, 0x45, 0x30, 0x34 }
178canVin2 = { 0x42, 0x52, 0x32, 0x31, 0x36, 0x33, 0x36, 0x36 }
179dataECMEngineStatus = { 0x84, 0x09, 0x99, 0x0A, 0x00, 0x40, 0x08, 0x00 }
181-- todo: smarter loop code :)
201 txCan(1, VIN_Part1, 0, canVin1)
202 txCan(1, VIN_Part2, 0, canVin2)
204 -- good enough for fuel module!
205 txCan(1, ECMEngineStatus, 0, dataECMEngineStatus)
208 setPwmDuty(STARTER_OUTPUT_INDEX, 1)
210 setPwmDuty(STARTER_OUTPUT_INDEX, 0)