-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwifiChannels.js
executable file
·59 lines (52 loc) · 2.07 KB
/
wifiChannels.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
class WifiChannels {
constructor() {
this.self = this;
this.regdb = require('./regdb.json');
this.channels = require('./channels.json');
this.dfs_regs = {
0: "UNSET",
1: "FCC",
2: "ETSI",
3: "JP"
};
}
getAllIso2Codes() {
return Object.keys(this.regdb);
}
getDfsRegion(iso2Code) {
let rec = this.regdb[iso2Code];
if (!rec) throw new Error("No record for " + iso2Code + ".");
return this.dfs_regs[rec.dfs_region];
}
getPermissions(iso2Code) {
let rec = this.regdb[iso2Code];
if (!rec) throw new Error('No record for ' + iso2Code + '.');
return this.regdb[iso2Code]._permissions;
}
isValidBand(band) {
return Object.keys(this.channels).find((b) => b === band.toLowerCase());
}
getPermittedChannels(iso2Code, band) {
if (!this.isValidBand(band)) throw new Error('Invalid band \'' + band + '\'.');
let permissions = this.getPermissions(iso2Code);
let resultChannels = [];
Object.keys(this.channels[band.toLowerCase()]).forEach((key) => {
const chan = this.channels[band.toLowerCase()][key];
permissions.forEach((perm) => {
if ((perm.freqband.start <= chan.lower) && (perm.freqband.end >= chan.upper))
resultChannels.push({
channel: key,
lower: chan.lower,
upper: chan.upper,
maxbw: perm.freqband.maxbw,
maxantgain: perm.power.max_ant_gain,
no_outdoor: ((perm.textflags) && (perm.textflags.includes("NO-OUTDOOR"))),
no_ir: ((perm.textflags) && (perm.textflags.includes("NO-IR"))),
dfs_required: ((perm.textflags) && (perm.textflags.includes("DFS")))
});
})
});
return resultChannels;
}
}
module.exports = new (WifiChannels);