-
Notifications
You must be signed in to change notification settings - Fork 2
/
DeviceInfo.js
56 lines (34 loc) · 1.13 KB
/
DeviceInfo.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
const Tasks = require('./Tasks'),
tVals = Object.values(Tasks);
class DeviceInfo{
constructor( data ){
if( typeof data != "object" )
data = {};
this.numPorts = parseInt(data.numPorts) || 0; // Nr ports supported by device
this.version = data.version ? String(data.version).substr(0, 64) : '???'; // Max 64 characters
this.hwversion = data.hwversion ? String(data.hwversion).substr(0, 64) : '???'; // Max 64 characters
this.custom = data.custom ? String(data.custom).substr(0, 256) : ''; // Custom data, max 256 characters
this.capabilities = {}; // taskName : true / false / "custom"
if( typeof data.capabilities === "object" ){
for( let i in data.capabilities ){
i = String(i).toLowerCase();
if( tVals.includes(i) ){
let val = String(data.capabilities[i]).toLowerCase();
if( val !== "custom" )
val = Boolean(val);
this.capabilities[i] = val;
}
}
}
}
export(){
return {
hwversion : this.hwversion,
numPorts : this.numPorts,
version : this.version,
custom : this.custom,
capabilities : this.capabilities,
};
}
}
module.exports = DeviceInfo;