-
Notifications
You must be signed in to change notification settings - Fork 3
/
runServer.js
57 lines (47 loc) · 1.32 KB
/
runServer.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
var BB = require('./main');
const EOL = require('os').EOL;
console.log(`Choose Option: \n1. Bootloader Server \n2. TCP/IP Proxy Server`);
process.stdin.on('data', (data) => {
const result = data.toString();
if (result === `1${EOL}`) {
bootloaderServer();
process.stdin.removeAllListeners();
}
else if (result === `2${EOL}`) {
proxyServer();
process.stdin.removeAllListeners();
}
else console.log(`Choose a valid option.`);
});
const bootloaderServer = () => {
const emitter = BB.usbMassStorage();
console.log('Bootloader Server started');
console.log('Connect BeagleBone to get started');
emitter.on('progress', function (status) {
console.log(status);
});
emitter.on('error', function (error) {
console.log('Error: ' + error);
});
var lastServer;
emitter.on('ncStarted', function (server) {
lastServer = server;
});
process.stdin.setEncoding('ascii');
process.stdin.on('readable', () => {
let data = process.stdin.read();
if (data != null) {
if (lastServer) {
emitter.emit('ncin', lastServer, data);
}
}
});
};
const proxyServer = () => {
const emitter = BB.proxyServer();
console.log(`Proxy Server started`);
console.log(`Connect BeagleBone to get started`);
emitter.on('error', (error) => {
console.log(`Error: ${error}`);
});
};