-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestGPS.js
56 lines (47 loc) · 1.27 KB
/
testGPS.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
"use strict";
/**
* Nov 2020, problem reading the serial ports...
* See the README.md for workaround.
*/
console.log('To stop: Ctrl-C, or enter "quit" + [return] here in the console');
console.log("Usage: node " + __filename + " [raw]|fmt|auto");
global.displayMode = "raw";
if (process.argv.length > 2) {
if (process.argv[2] === 'fmt') {
global.displayMode = "fmt";
} else if (process.argv[2] === 'auto') {
global.displayMode = "auto";
}
}
let util = require('util');
let GPS = require('./SerialReader.js').NMEA;
// let serialPort = '/dev/tty.usbserial'; // On Mac
let serialPort = '/dev/ttyS80'; // On Linux (including Raspberry)
let gps = new GPS(serialPort, 4800);
// var gps = new GPS();
if (global.displayMode === 'fmt') {
gps.onPosition = function(pos) {
console.log("Position:", pos);
};
gps.onTime = function(epoch) {
console.log("Time: " + new Date(epoch));
};
}
let exit = () => {
gps.exit();
process.stdin.pause();
};
process.on('SIGINT', exit); // Ctrl C
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (text) {
//console.log('received data:', util.inspect(text));
if (text.startsWith('quit')) {
done();
}
});
let done = () => {
console.log("Bye now!");
exit();
process.exit();
};