-
Notifications
You must be signed in to change notification settings - Fork 1
/
renderer.js
346 lines (298 loc) · 16.5 KB
/
renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
const setVersion = async () => {
const version = await window.mainprocess.version()
document.getElementById('version').textContent = version;
}
setVersion()
const connectButton = document.getElementById('serialconnect');
const disconnectButton = document.getElementById('serialdisconnect');
const initDataContainer = document.getElementById('init-data-container');
const liveDataContainer = document.getElementById('live-data-container');
const faultCodeDataContainer = document.getElementById('fault-code-data-container');
let faultCodeType = 0;
const liveDataDot = document.getElementById('live-data-dot');
let liveDataTimeoutId = 0;
let firstLiveData = true;
const alert = new Alert(document.getElementById('alert'));
const initDataContainerMessage = document.getElementById('init-data-container-message');
const loadingSpinner = document.getElementById('spinner-overlay');
loadingSpinner.style.display = 'none';
const downloadButton = document.getElementById('download');
let liveDataDump = [];
downloadButton.addEventListener('click', () => {
const csvData = createCsvString(liveDataDump)
window.mainprocess.download(csvData);
});
const faultCodeFields = [
document.getElementById('fault-code-1'),
document.getElementById('fault-code-2'),
document.getElementById('fault-code-3'),
document.getElementById('fault-code-4'),
document.getElementById('fault-code-5'),
document.getElementById('fault-code-6'),
document.getElementById('fault-code-7'),
document.getElementById('fault-code-8'),
document.getElementById('fault-code-9'),
document.getElementById('fault-code-10'),
document.getElementById('fault-code-11'),
document.getElementById('fault-code-12'),
]
const faultCodeDescFields = [
document.getElementById('fault-code-desc-1'),
document.getElementById('fault-code-desc-2'),
document.getElementById('fault-code-desc-3'),
document.getElementById('fault-code-desc-4'),
document.getElementById('fault-code-desc-5'),
document.getElementById('fault-code-desc-6'),
document.getElementById('fault-code-desc-7'),
document.getElementById('fault-code-desc-8'),
document.getElementById('fault-code-desc-9'),
document.getElementById('fault-code-desc-10'),
document.getElementById('fault-code-desc-11'),
document.getElementById('fault-code-desc-12'),
]
const liveDataRpm = document.getElementById('data-rpm');
const liveDataSupplyVoltage = document.getElementById('data-supply-voltage');
const liveDataThrottle = document.getElementById('data-throttle');
const liveDataThrottleMode = document.getElementById('data-throttle-mode');
const liveDataCoolantTemp = document.getElementById('data-coolant-temp');
const liveDataCoolantTempSensor = document.getElementById('data-coolant-temp-sensor');
const liveDataAirTemp = document.getElementById('data-air-temp');
const liveDataAirTempSensor = document.getElementById('data-air-temp-sensor');
const liveDataEgr = document.getElementById('data-egr');
const liveDataEgrDutyCycle = document.getElementById('data-egr-duty-cycle');
const liveDataLambda1 = document.getElementById('data-lambda-1');
const liveDataLambda2 = document.getElementById('data-lambda-2');
const liveDataEgo = document.getElementById('data-ego');
const liveDataFuelPulsewidth = document.getElementById('data-fuel-pulsewidth');
const liveDataIgnitionTiming = document.getElementById('data-ignition-timing');
const liveDataSpeed = document.getElementById('data-speed');
const liveDataSpeedUnfiltered = document.getElementById('data-speed-unfiltered');
const liveDataAirCharge = document.getElementById('data-air-charge');
const liveDataBarometricPressure = document.getElementById('data-bp');
const liveDataManifoldAbsolutePressure = document.getElementById('data-map');
const liveDataCalibrationVoltage = document.getElementById('data-calibration-voltage');
const liveDataTransmissionOilTemperature = document.getElementById('data-transmission-oil-temperature');
const liveDataScap = document.getElementById('data-scap');
const liveDataAdaptiveFuelCorrection = document.getElementById('data-adaptive-fuel-correction');
const liveDataIdleSpeed = document.getElementById('data-idle-speed');
const liveDataDesiredRpm = document.getElementById('data-desired-rpm');
const liveDataRatch = document.getElementById('data-ratch');
const liveDataTimeSinceStartup = document.getElementById('data-time-since-startup');
const liveDataOcc = document.getElementById('data-occ');
const liveDataNeutralDriveInput = document.getElementById('data-neutral-drive-input');
const liveDataConverterClutch = document.getElementById('data-converter-clutch');
const liveDataCommandGear = document.getElementById('data-command-gear');
const liveDataEtvMonitorVoltage = document.getElementById('data-etv-monitor-voltage');
const liveDataEpcPressure = document.getElementById('data-epc-pressure');
const liveDataPrndlPosition = document.getElementById('data-prndl-position');
const liveDataAirFlowMeter = document.getElementById('data-air-flow-meter');
const liveDataBitmap0 = document.getElementById('data-bitmap-0');
const liveDataBitmap1 = document.getElementById('data-bitmap-1');
const liveDataNotUsed0A = document.getElementById('data-not-used-0A');
const liveDataNotUsed14 = document.getElementById('data-not-used-14');
const liveDataNotUsed16 = document.getElementById('data-not-used-16');
const liveDataNotUsed19 = document.getElementById('data-not-used-19');
const liveDataNotUsed1C = document.getElementById('data-not-used-1C');
const liveDataNotUsed1D = document.getElementById('data-not-used-1D');
const liveDataNotUsed26 = document.getElementById('data-not-used-26');
const liveDataNotUsed29 = document.getElementById('data-not-used-29');
const liveDataNotUsed2C = document.getElementById('data-not-used-2C');
const liveDataNotUsed31 = document.getElementById('data-not-used-31');
const liveDataNotUsed33 = document.getElementById('data-not-used-33');
const liveDataNotUsed34 = document.getElementById('data-not-used-34');
connectButton.addEventListener('click', serialConnect);
disconnectButton.addEventListener('click', serialDisconnect);
const serial = new Serial();
async function serialDisconnect() {
console.log("Disconnecting");
loadingSpinner.style.display = 'block';
await serial.disconnect();
loadingSpinner.style.display = 'none';
alert.showAndFade("EEC-IV-Reader disconnected");
connectButton.disabled = false;
disconnectButton.disabled = true;
initDataContainerMessage.innerHTML = 'Please connect EEC-IV Reader and click the Connect Button.';
loadingSpinner.style.display = 'none';
initDataContainer.style.display = 'flex';
faultCodeDataContainer.style.display = 'none';
liveDataContainer.style.display = 'none';
}
async function serialConnect() {
connectButton.disabled = true;
alert.show("Connecting to EEC-IV-Reader...");
initDataContainerMessage.innerHTML = '';
loadingSpinner.style.display = 'block';
console.log("Connecting");
const ports = await serial.getPorts();
liveDataDump = [];
if (ports.length == 0) {
alert.show("No ports found. Is Reader connected?", true);
connectButton.disabled = false;
disconnectButton.disabled = true;
initDataContainerMessage.innerHTML = 'Please connect EEC-IV Reader and click the Connect Button.';
loadingSpinner.style.display = 'none';
initDataContainer.style.display = 'flex';
faultCodeDataContainer.style.display = 'none';
liveDataContainer.style.display = 'none';
return;
}
console.log(ports);
// TODO check for ports, make select menu
const port = ports[0];
serial.connect(port, exception => {
console.log("Connection error");
console.log(exception);
alert.show("An error occured while connecting", true);
connectButton.disabled = false;
disconnectButton.disabled = true;
initDataContainerMessage.innerHTML = 'Please connect EEC-IV Reader and click the Connect Button.';
loadingSpinner.style.display = 'none';
initDataContainer.style.display = 'flex';
faultCodeDataContainer.style.display = 'none';
liveDataContainer.style.display = 'none';
}, () => {
console.log("Connected");
disconnectButton.disabled = false;
});
serial.onReaderOnline = () => {
alert.showAndFade("EEC-IV-Reader connected!");
initDataContainerMessage.innerHTML = 'Please select mode on EEC-IV-Reader';
loadingSpinner.style.display = 'none';
};
serial.onTimeoutError = () => {
alert.show("Reader could not connect to ECU. Is the ignition on?", true);
loadingSpinner.style.display = 'none';
}
serial.onReadingStarted = type => {
if (type == 0x01) {
alert.showAndFade("Fault Code Memory Reading started...");
loadingSpinner.style.display = 'block';
faultCodeFields.forEach((field) => field.innerHTML = "");
faultCodeDescFields.forEach((field) => field.innerHTML = "");
faultCodeDataContainer.style.opacity = 0.4;
initDataContainer.style.display = 'none';
faultCodeDataContainer.style.display = 'flex';
liveDataContainer.style.display = 'none';
faultCodeType = type;
} else if (type == 0x02) {
alert.showAndFade("KOEO/KOER Test started...");
loadingSpinner.style.display = 'block';
faultCodeFields.forEach((field) => field.innerHTML = "");
faultCodeDescFields.forEach((field) => field.innerHTML = "");
faultCodeDataContainer.style.opacity = 0.4;
initDataContainer.style.display = 'none';
faultCodeDataContainer.style.display = 'flex';
liveDataContainer.style.display = 'none';
faultCodeType = type;
} else if (type == 0x03) {
alert.showAndFade("Live Data Reading started...");
firstLiveData = true;
liveDataDot.classList.remove("go-red");
liveDataDot.classList.remove("green");
loadingSpinner.style.display = 'block';
liveDataContainer.style.opacity = 0.4;
initDataContainer.style.display = 'none';
faultCodeDataContainer.style.display = 'none';
liveDataContainer.style.display = 'flex';
} else {
alert.showAndFade("Unknown Reading started");
loadingSpinner.style.display = 'block';
initDataContainer.style.display = 'flex';
faultCodeDataContainer.style.display = 'none';
liveDataContainer.style.display = 'none';
}
}
serial.onFaultCodes = (data) => {
const eecIvDecoder = new EecIvDecoder();
faultCodeDataContainer.style.opacity = 1;
loadingSpinner.style.display = 'none';
if (faultCodeType == 0x02) {
alert.show("Received Fault Codes. Please turn Ignition off and on for further readings!");
} else {
alert.showAndFade("Received Fault Codes");
}
eecIvDecoder.getAllFaultCodes(data).forEach((code, i) => {
faultCodeFields[i].innerHTML = code;
faultCodeDescFields[i].innerHTML = eecIvDecoder.faultCodeDescription[code];
});
}
function updateGuiValue(value, updateHandler) {
if (value !== undefined && value !== null) {
updateHandler(value);
}
}
serial.onLiveData = (data) => {
clearTimeout(liveDataTimeoutId);
liveDataDot.classList.remove("go-red");
liveDataDot.classList.add("green");
liveDataTimeoutId = setTimeout(liveDataDot => {
liveDataDot.classList.remove("green");
liveDataDot.classList.add("go-red");
}, 2000, liveDataDot)
// only first time and fade out
if (firstLiveData) {
alert.showAndFade("Receiving Live Data");
firstLiveData = false;
}
liveDataContainer.style.opacity = 1;
loadingSpinner.style.display = 'none';
const eecIvDecoder = new EecIvDecoder();
let liveData = eecIvDecoder.getAllLiveData(data);
console.log(liveData);
let liveDataDumpLine = {
time: Date.now(),
data: liveData,
}
liveDataDump.push(liveDataDumpLine);
updateGuiValue(liveData.rpm, (rpm) => liveDataRpm.innerHTML = rpm);
updateGuiValue(liveData.supplyVoltage, (supplyVoltage) => liveDataSupplyVoltage.innerHTML = supplyVoltage.toFixed(2) + " V");
updateGuiValue(liveData.throttlePosition, (throttlePosition) => liveDataThrottle.innerHTML = throttlePosition + " A/D C.");
updateGuiValue(liveData.throttleMode, (throttleMode) => liveDataThrottleMode.innerHTML = throttleMode);
updateGuiValue(liveData.actCelsius, (actCelsius) => liveDataAirTemp.innerHTML = actCelsius.toFixed(2) + " °C");
updateGuiValue(liveData.act, (act) => liveDataAirTempSensor.innerHTML = act + " A/D C.");
updateGuiValue(liveData.ectCelsius, (ectCelsius) => liveDataCoolantTemp.innerHTML = ectCelsius.toFixed(2) + " °C");
updateGuiValue(liveData.ect, (ect) => liveDataCoolantTempSensor.innerHTML = ect + " A/D C.");
updateGuiValue(liveData.egr, (egr) => liveDataEgr.innerHTML = egr + " A/D C.");
updateGuiValue(liveData.egrDutyCycle, (egr) => liveDataEgrDutyCycle.innerHTML = egr + " A/D C.");
updateGuiValue(liveData.fuelPulsewidth, (fuelPulsewidth) => liveDataFuelPulsewidth.innerHTML = fuelPulsewidth + " Ticks");
updateGuiValue(liveData.totalSparkAdvance, (totalSparkAdvance) => liveDataIgnitionTiming.innerHTML = totalSparkAdvance + "°");
updateGuiValue(liveData.speed, (speed) => liveDataSpeed.innerHTML = speed.toFixed(1) + " km/h");
updateGuiValue(liveData.speedUnfiltered, (speed) => liveDataSpeedUnfiltered.innerHTML = speed.toFixed(1) + " km/h");
updateGuiValue(liveData.airCharge, (airCharge) => liveDataAirCharge.innerHTML = airCharge.toFixed(2) + " %");
updateGuiValue(liveData.lambda1, (lambda) => liveDataLambda1.innerHTML = lambda.toFixed(4));
updateGuiValue(liveData.lambda2, (lambda) => liveDataLambda2.innerHTML = lambda.toFixed(4));
updateGuiValue(liveData.ego1, (ego) => liveDataEgo.innerHTML = ego + " A/D C.");
updateGuiValue(liveData.barometricPressure, (bp) => liveDataBarometricPressure.innerHTML = bp + " inHg");
updateGuiValue(liveData.manifoldAbsolutePressure, (map) => liveDataManifoldAbsolutePressure.innerHTML = map + " inHg");
updateGuiValue(liveData.calibrationInputVoltage, (voltage) => liveDataCalibrationVoltage.innerHTML = voltage + " A/D C.");
updateGuiValue(liveData.transmissionOilTemperature, (temp) => liveDataTransmissionOilTemperature.innerHTML = temp + " A/D C.");
updateGuiValue(liveData.scap, (scap) => liveDataScap.innerHTML = scap + " A/D C.");
updateGuiValue(liveData.idleSpeedDutyCycle, (dutyCycle) => liveDataIdleSpeed.innerHTML = dutyCycle + " A/D C.");
updateGuiValue(liveData.adaptiveFuelCorrection, (correction) => liveDataAdaptiveFuelCorrection.innerHTML = correction.toFixed(4) + " A/F");
updateGuiValue(liveData.desiredRpm, (rpm) => liveDataDesiredRpm.innerHTML = rpm);
updateGuiValue(liveData.ratch, (ratch) => liveDataRatch.innerHTML = ratch);
updateGuiValue(liveData.timeSinceStartup, (time) => liveDataTimeSinceStartup.innerHTML = time + " s");
updateGuiValue(liveData.occ, (occ) => liveDataOcc.innerHTML = occ + " A/D C.");
updateGuiValue(liveData.neutralDriveInput, (input) => liveDataNeutralDriveInput.innerHTML = input + " A/D C.");
updateGuiValue(liveData.converterClutch, (clutch) => liveDataConverterClutch.innerHTML = clutch + " %");
updateGuiValue(liveData.commandGear, (gear) => liveDataCommandGear.innerHTML = gear);
updateGuiValue(liveData.etvMonitorVoltage, (voltage) => liveDataEtvMonitorVoltage.innerHTML = voltage + " V");
updateGuiValue(liveData.epcPressure, (pressure) => liveDataEpcPressure.innerHTML = pressure + " p.s.i");
updateGuiValue(liveData.prndlPosition, (position) => liveDataPrndlPosition.innerHTML = position);
updateGuiValue(liveData.airFlowMeter, (flow) => liveDataAirFlowMeter.innerHTML = flow + " A/D C.");
updateGuiValue(liveData.bitmap0, (bitmap) => liveDataBitmap0.innerHTML = bitmap);
updateGuiValue(liveData.bitmap1, (bitmap) => liveDataBitmap1.innerHTML = bitmap);
updateGuiValue(liveData.notUsed0A, (notUsed) => liveDataNotUsed0A.innerHTML = notUsed);
updateGuiValue(liveData.notUsed14, (notUsed) => liveDataNotUsed14.innerHTML = notUsed);
updateGuiValue(liveData.notUsed16, (notUsed) => liveDataNotUsed16.innerHTML = notUsed);
updateGuiValue(liveData.notUsed19, (notUsed) => liveDataNotUsed19.innerHTML = notUsed);
updateGuiValue(liveData.notUsed1C, (notUsed) => liveDataNotUsed1C.innerHTML = notUsed);
updateGuiValue(liveData.notUsed1D, (notUsed) => liveDataNotUsed1D.innerHTML = notUsed);
updateGuiValue(liveData.notUsed26, (notUsed) => liveDataNotUsed26.innerHTML = notUsed);
updateGuiValue(liveData.notUsed29, (notUsed) => liveDataNotUsed29.innerHTML = notUsed);
updateGuiValue(liveData.notUsed31, (notUsed) => liveDataNotUsed31.innerHTML = notUsed);
updateGuiValue(liveData.notUsed33, (notUsed) => liveDataNotUsed33.innerHTML = notUsed);
updateGuiValue(liveData.notUsed34, (notUsed) => liveDataNotUsed34.innerHTML = notUsed);
return;
}
}