-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoverage.js
94 lines (80 loc) · 2.71 KB
/
coverage.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
const fs = require('fs');
const tetra = require('./tetraterminal');
const program = require('commander');
program
.version('0.1.0')
.option('-p, --port <portname>', 'Serial port e.g /dev/ttyusb')
.option('-b, --baud [baudrate]', 'Baudrate (default 38400')
.option('-f, --filename [filename]', 'Filename to output coverage data to (default report.txt)')
.option('-i --interval <number>', 'Interval in seconds to get reports')
.parse(process.argv);
// Check parameters and set defaults
let portName;
if (typeof program.port !== 'undefined') {
portName = '/dev/cu.usbserial-FTF4Y8HO'
} else {
console.log("Portname missing\n");
program.outputHelp();
process.exit(1);
}
let baudrate = typeof program.baudrate !== 'undefined' ? program.baudrate : 38400;
let filename = typeof program.filename !== 'undefined' ? program.filename : "report.txt";
let interval = typeof program.interval !== 'undefined' ? program.interval * 1000 : null;
let radio = new tetra.Motorola(portName, baudrate);
let issi, manufacturer, serialnumber, model;
start();
async function start() {
try {
issi = await radio.getIssi();
console.log(`ISSI: ${issi}`);
model = await radio.getModel();
console.log(`Model: ${model}`);
serialnumber = await radio.getSerialnumber();
console.log(`Serial: ${serialnumber}`);
manufacturer = await radio.getManufacturer();
console.log(`Manufacturer: ${manufacturer}`);
} catch (err) {
console.log("Error retrieving radio info: " + err);
process.exit(1);
}
radio.initializeTerminal().then(
async ()=>{
await getReport();
if (interval) {
setInterval( async function () {
await getReport();
}, interval);
} else {
process.exit();
}
});
}
async function getReport() {
try {
rssi = await radio.getRSSI();
location = await radio.getLocation();
cell = await radio.getCellInfo();
report = {
issi: issi,
signal: {
rssi: rssi,
c1: undefined,
},
currentcell: cell,
neighbourcells: undefined,
location: {
lat: location.lat,
lon: location.lon,
satellites: location.satellites,
timestamp: location.timestamp,
},
}
fs.appendFile(filename, JSON.stringify(report) + '\n', (err) => {
if (err) throw err;
})
console.log(JSON.stringify(report));
radio.setDisplayMessage("Dekning", `RSSI: ${rssi} dBm lagret`, 5 ,4);
} catch (err) {
console.log(`Unable to get signalreport: ${err}`);
}
}