forked from jsimonetti/go-artnet
/
status2.go
107 lines (92 loc) · 2.35 KB
/
status2.go
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package code
// Status2 indicates Product capabilities
type Status2 uint8
// WithBrowser sets if product supports web browser configuration
func (s Status2) WithBrowser(enable bool) Status2 {
if enable {
return s | (1 << 0)
}
return s | (0 << 0)
}
// Browser indicates if product supports web browser configuration
func (s Status2) Browser() bool {
return s&(1<<0) > 0
}
// WithDHCP sets if product IP is DHCP configured
func (s Status2) WithDHCP(enable bool) Status2 {
if enable {
return s | (1 << 1)
}
return s | (0 << 1)
}
// DHCP indicates if product IP is DHCP configured
func (s Status2) DHCP() bool {
return s&(1<<1) > 0
}
// WithDHCPCapable sets if product is capable of DHCP
func (s Status2) WithDHCPCapable(enable bool) Status2 {
if enable {
return s | (1 << 2)
}
return s | (0 << 2)
}
// DHCPCapable indicates if product is capable of DHCP
func (s Status2) DHCPCapable() bool {
return s&(1<<2) > 0
}
// WithPort15 sets if product supports 15 bit Port-Address (Art-Net 3 or 4)
func (s Status2) WithPort15(enable bool) Status2 {
if enable {
return s | (1 << 3)
}
return s | (0 << 3)
}
// Port15 indicates if product supports 15 bit Port-Address (Art-Net 3 or 4)
func (s Status2) Port15() bool {
return s&(1<<3) > 0
}
// WithSwitch sets if product is able to switch between Art-Net and sACN
func (s Status2) WithSwitch(enable bool) Status2 {
if enable {
return s | (1 << 4)
}
return s | (0 << 4)
}
// Switch indicates if product is able to switch between Art-Net and sACN
func (s Status2) Switch() bool {
return s&(1<<4) > 0
}
// WithSquawk sets if product is squawking
func (s Status2) WithSquawk(enable bool) Status2 {
if enable {
return s | (1 << 5)
}
return s | (0 << 5)
}
// Squawk indicates if product is squawking
func (s Status2) Squawk() bool {
return s&(1<<5) > 0
}
// String returns a string representation of Status2
func (s Status2) String() string {
browser, dhcp, dhcpcap, port15, swtch, squawk := "no", "no", "no", "no", "no", "no"
if s.Browser() {
browser = "yes"
}
if s.DHCP() {
dhcp = "yes"
}
if s.DHCPCapable() {
dhcpcap = "yes"
}
if s.Port15() {
port15 = "yes"
}
if s.Switch() {
swtch = "yes"
}
if s.Squawk() {
squawk = "yes"
}
return "Status2: Browser: " + browser + ", DHCP: " + dhcp + ", DHCPCapable: " + dhcpcap + ", Port 15bit: " + port15 + ", CanSwitch: " + swtch + ", Squawking: " + squawk
}