-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·89 lines (68 loc) · 2.42 KB
/
cli.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
#!/usr/bin/env node
'use strict'
let chalk = require('chalk')
let logUpdate = require('log-update')
let source = require('./index')
let fmt = require('./formatters')
const INTERVAL = 1000
// https://support.metageek.com/hc/en-us/articles/201955754-Acceptable-Wi-Fi-Signal-Strengths
//https://support.bluesound.com/hc/en-us/articles/201940663-What-should-my-Wireless-Signal-Strength-be-for-best-performance-
//http://www.watchguard.com/help/docs/wsm/xtm_11/en-US/index.html#cshid=en-US/wireless/ap_wireless_signalstrength_c.html
//SNR
//http://www.enterprisenetworkingplanet.com/netsp/article.php/3747656/WiFi-Define-Minimum-SNR-Values-for-Signal-Coverage.htm
//
let activity = false
function aniTitle(title, n) {
// TODO: when abstracting this, activity should be a clojure value for this func
//let f = title.slice(0,1)
let f = chalk.magenta(title.slice(0,n))
let t = chalk.magenta(title.slice(n))
f = activity ? chalk.inverse(f) : f;
return f + t;
}
function template(data) {
return `\
${aniTitle(data.title, 4)}
Signal ${data.signalMarkers} ${data.signal || 'no data'} dBm | ${data.quality || 'no data'} %
SNR ${data.snrMarkers} ${data.snr || 'no data'} dBm
Detail
------
Quality[%]: ${data.quality || 'no data'}
Signal[dBm]: ${data.signal || 'no data'}
Noise[dBm]: ${data.noise || 'no data'}
SNR[dBm]: ${data.snr || 'no data'}
Rate[Mbs]: ${chalk.inverse(data.rate || 'no data')}
Info
----
SNR: Signal To noise Ratio (difference)
SNR = S - N [dBm]
Quality: Quality of the signal based on the power with which the signal is percived
Quality = 2 * (Signal + 100)
`
}
function render() {
activity = !activity
let data = source()
let signalPer = fmt.getPercentage(data.signal, -100, -50)
let signalMarkers = fmt.getColor(signalPer)(fmt.getMarkers(signalPer))
let snrPer = fmt.getPercentage(data.snr, 4, 25)
let snrMarkers = fmt.getColor(snrPer)(fmt.getMarkers(snrPer))
let qualityPer = fmt.getPercentage(data.quality)
let qualityMarkers = fmt.getColor(qualityPer)(fmt.getMarkers(qualityPer))
let title = 'SITH: Wifi Signal Strength Analyzer'
Object.assign(data, {
title,
signalMarkers,
qualityMarkers,
snrMarkers
})
logUpdate(template(data))
}
function sithCli() {
render()
setInterval( _ => render(), 1000)
}
// Render in a cleared screen
process.stdout.cursorTo(0, 0);
process.stdout.clearScreenDown();
sithCli();