-
Notifications
You must be signed in to change notification settings - Fork 363
/
Copy pathlinker.html
97 lines (93 loc) · 3.65 KB
/
linker.html
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
<script>
const { PythonShell } = require('python-shell');
const { ipcRenderer } = require('electron');
const loadBalancer = require('electron-load-balancer');
const { oscilloscopeXYProcessor, oscilloscopeVoltageProcessor, LAProcessor } = require('../utils/preProcessor.js');
const log = require('electron-log');
ipcRenderer.invoke('GET_SCRIPT_PATH', 'bridge.py').then((bridgePath) => {
const pyshell = new PythonShell(bridgePath);
log.info('Python spawned:', pyshell && pyshell.command);
loadBalancer.job(
ipcRenderer,
'linker',
() => {
loadBalancer.onReceiveData(ipcRenderer, 'linker', args => {
log.info({ args });
pyshell.send(JSON.stringify(args));
});
pyshell.on('stderr', function(stderr) {
log.error(stderr);
});
pyshell.on('message', function(results) {
log.info({ results });
try {
const parsedJSON = JSON.parse(results);
switch (parsedJSON['type']) {
case 'START_OSC':
if (parsedJSON.isFFT) {
parsedOutput = oscilloscopeVoltageProcessor(parsedJSON);
parsedJSON['fitType'] !== null &&
ipcRenderer.send('OSC_FIT_DATA', {
fitOutput1Sine: parsedJSON['fitOutput1Sine'],
fitOutput2Sine: parsedJSON['fitOutput2Sine'],
fitOutput1Square: parsedJSON['fitOutput1Square'],
fitOutput2Square: parsedJSON['fitOutput2Square'],
});
ipcRenderer.send('OSC_FFT_DATA', { data: parsedOutput });
}
else if( parsedJSON.isXYPlot ){
parsedOutput = oscilloscopeXYProcessor(parsedJSON);
ipcRenderer.send('OSC_XY_PLOT_DATA', { data: parsedOutput });
}
else {
parsedOutput = oscilloscopeVoltageProcessor(parsedJSON);
ipcRenderer.send('OSC_VOLTAGE_DATA', { data: parsedOutput });
}
break;
case 'START_LA':
parsedOutput = LAProcessor(parsedJSON)
ipcRenderer.send('LA_DATA', {
data: parsedOutput
});
break;
case 'SENSORS_SCAN':
ipcRenderer.send('SENSORS_SCAN', { data: parsedJSON.data });
break;
case 'START_MUL_MET':
ipcRenderer.send('MUL_MET_DATA', { data: parsedJSON.data, prefix: parsedJSON.prefix });
break;
case 'GET_CONFIG_PWR_SRC':
ipcRenderer.send('PWR_SRC_CONFIG', parsedJSON);
break;
case 'GET_CONFIG_OSC':
ipcRenderer.send('OSC_CONFIG', parsedJSON);
break;
case 'GET_CONFIG_LA':
ipcRenderer.send('LA_CONFIG', parsedJSON);
break;
case 'GET_CONFIG_MUL_MET':
ipcRenderer.send('MUL_MET_CONFIG', parsedJSON);
break;
case 'GET_CONFIG_WAV_GEN':
ipcRenderer.send('WAV_GEN_CONFIG', parsedJSON);
break;
case 'DEVICE_CONNECTION_STATUS':
ipcRenderer.send('CONNECTION_STATUS', parsedJSON);
break;
case 'DATA_WRITING_STATUS':
ipcRenderer.send('DATA_WRITING_STATUS', parsedJSON);
break;
default:
break;
}
} catch (error) {
log.error(error);
}
});
},
() => {
pyshell.terminate();
},
);
});
</script>