-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource_linux.js
More file actions
53 lines (37 loc) · 1 KB
/
source_linux.js
File metadata and controls
53 lines (37 loc) · 1 KB
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
'use strict';
let execSync = require('child_process').execSync
let utils = require('./utils')
function get_data_linux() {
let res, signal, noise, rate;
let snr = false;
let quality = false;
try {
res = execSync("cat /proc/net/wireless")
} catch (e) {
throw `SITH panicked: ${e}`
}
try {
// Redirect stderr to avoid useless printing to terminal
rate = execSync("iwconfig 2> /dev/null")
} catch (e) {
throw `SITH panicked: ${e}`
}
res = res.toString();
try {
res = res.split('\n')[2].split(/\s+/)
signal = parseInt(res[3], 10)
noise = parseInt(res[4], 10)
} catch (e) {
throw `SITH panicked! could not parse signal or noice data ${e}`
}
rate = rate.toString()
try {
rate = parseInt(rate.match(/(?:Bit Rate=)([\d]*)/)[1],10)
} catch(e) {
throw `SITH panicked! could not parse rate data ${e}`
}
snr = signal - noise
quality = utils.dbmToQuality(signal)
return {signal, noise, rate, snr, quality}
}
module.exports = get_data_linux