-
Notifications
You must be signed in to change notification settings - Fork 8
/
Device.js
69 lines (60 loc) · 1.86 KB
/
Device.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
export var ip = "192.168.1.";
export var C_device = 1;
export function randomMac()
{
const mac = [
(0x52).toString(16),
(0x54).toString(16),
(0x00).toString(16),
Math.floor((Math.random() * 0xff)).toString(16),
Math.floor((Math.random() * 0xff)).toString(16),
Math.floor((Math.random() * 0xff)).toString(16)
]
return mac.join(':')
}
export var list_devices = []; // stores the end devices
list_devices.push(-1);
export class End_device
{
constructor()
{
this.ipaddress = ip + C_device;
C_device ++;
this.mac_address = randomMac();
this.port = ["-1"];
this.message = "empty";
}
get_ipaddress()
{
return this.ipaddress;
}
get_mac_address()
{
return this.mac_address;
}
is_port_vacant()
{
if(this.port[0] != "-1")
{
return 0;
}
else
{
return 1;
}
}
}
export function create_end_device() // creates an end device
{
let device = new End_device();
list_devices.push(device);
}
export function get_val()
{
return (C_device);
}
export function reset_devices()
{
list_devices = ["-1"];
C_device = 1;
}