forked from bougou/go-ipmi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_get_sensor_event_enable.go
149 lines (131 loc) · 4.76 KB
/
cmd_get_sensor_event_enable.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package ipmi
import (
"fmt"
"strings"
)
// 35.11 Get Sensor Event Enable Command
type GetSensorEventEnableRequest struct {
SensorNumber uint8
}
// For event , true means the event has enabled.
type GetSensorEventEnableResponse struct {
EventMessagesDisabled bool
SensorScanningDisabled bool
SensorEventFlag
}
func (req *GetSensorEventEnableRequest) Command() Command {
return CommandGetSensorEventEnable
}
func (req *GetSensorEventEnableRequest) Pack() []byte {
out := make([]byte, 1)
packUint8(req.SensorNumber, out, 0)
return out
}
func (res *GetSensorEventEnableResponse) Unpack(msg []byte) error {
if len(msg) < 1 {
return ErrUnpackedDataTooShort
}
b1, _, _ := unpackUint8(msg, 0)
res.EventMessagesDisabled = !isBit7Set(b1)
res.SensorScanningDisabled = !isBit6Set(b1)
if len(msg) >= 2 {
b2, _, _ := unpackUint8(msg, 1)
res.SensorEvent_UNC_High_Assert = isBit7Set(b2)
res.SensorEvent_UNC_Low_Assert = isBit6Set(b2)
res.SensorEvent_LNR_High_Assert = isBit5Set(b2)
res.SensorEvent_LNR_Low_Assert = isBit4Set(b2)
res.SensorEvent_LCR_High_Assert = isBit3Set(b2)
res.SensorEvent_LCR_Low_Assert = isBit2Set(b2)
res.SensorEvent_LNC_High_Assert = isBit1Set(b2)
res.SensorEvent_LNC_Low_Assert = isBit0Set(b2)
res.SensorEvent_State_7_Assert = isBit7Set(b2)
res.SensorEvent_State_6_Assert = isBit6Set(b2)
res.SensorEvent_State_5_Assert = isBit5Set(b2)
res.SensorEvent_State_4_Assert = isBit4Set(b2)
res.SensorEvent_State_3_Assert = isBit3Set(b2)
res.SensorEvent_State_2_Assert = isBit2Set(b2)
res.SensorEvent_State_1_Assert = isBit1Set(b2)
res.SensorEvent_State_0_Assert = isBit0Set(b2)
}
if len(msg) >= 3 {
b3, _, _ := unpackUint8(msg, 2)
res.SensorEvent_UNR_High_Assert = isBit3Set(b3)
res.SensorEvent_UNR_Low_Assert = isBit2Set(b3)
res.SensorEvent_UCR_High_Assert = isBit1Set(b3)
res.SensorEvent_UCR_Low_Assert = isBit0Set(b3)
res.SensorEvent_State_14_Assert = isBit6Set(b3)
res.SensorEvent_State_13_Assert = isBit5Set(b3)
res.SensorEvent_State_12_Assert = isBit4Set(b3)
res.SensorEvent_State_11_Assert = isBit3Set(b3)
res.SensorEvent_State_10_Assert = isBit2Set(b3)
res.SensorEvent_State_9_Assert = isBit1Set(b3)
res.SensorEvent_State_8_Assert = isBit0Set(b3)
}
if len(msg) >= 4 {
b4, _, _ := unpackUint8(msg, 3)
res.SensorEvent_UNC_High_Deassert = isBit7Set(b4)
res.SensorEvent_UNC_Low_Deassert = isBit6Set(b4)
res.SensorEvent_LNR_High_Deassert = isBit5Set(b4)
res.SensorEvent_LNR_Low_Deassert = isBit4Set(b4)
res.SensorEvent_LCR_High_Deassert = isBit3Set(b4)
res.SensorEvent_LCR_Low_Deassert = isBit2Set(b4)
res.SensorEvent_LNC_High_Deassert = isBit1Set(b4)
res.SensorEvent_LNC_Low_Deassert = isBit0Set(b4)
res.SensorEvent_State_7_Deassert = isBit7Set(b4)
res.SensorEvent_State_6_Deassert = isBit6Set(b4)
res.SensorEvent_State_5_Deassert = isBit5Set(b4)
res.SensorEvent_State_4_Deassert = isBit4Set(b4)
res.SensorEvent_State_3_Deassert = isBit3Set(b4)
res.SensorEvent_State_2_Deassert = isBit2Set(b4)
res.SensorEvent_State_1_Deassert = isBit1Set(b4)
res.SensorEvent_State_0_Deassert = isBit0Set(b4)
}
if len(msg) >= 5 {
b5, _, _ := unpackUint8(msg, 4)
res.SensorEvent_UNR_High_Deassert = isBit3Set(b5)
res.SensorEvent_UNR_Low_Deassert = isBit2Set(b5)
res.SensorEvent_UCR_High_Deassert = isBit1Set(b5)
res.SensorEvent_UCR_Low_Deassert = isBit0Set(b5)
res.SensorEvent_State_14_Deassert = isBit6Set(b5)
res.SensorEvent_State_13_Deassert = isBit5Set(b5)
res.SensorEvent_State_12_Deassert = isBit4Set(b5)
res.SensorEvent_State_11_Deassert = isBit3Set(b5)
res.SensorEvent_State_10_Deassert = isBit2Set(b5)
res.SensorEvent_State_9_Deassert = isBit1Set(b5)
res.SensorEvent_State_8_Deassert = isBit0Set(b5)
}
return nil
}
func (r *GetSensorEventEnableResponse) CompletionCodes() map[uint8]string {
return map[uint8]string{}
}
func (res *GetSensorEventEnableResponse) Format() string {
all := res.SensorEventFlag.TrueEvents()
asserted := SensorEvents(all).FilterAssert()
deasserted := SensorEvents(all).FilterDeassert()
var assertedStr = []string{}
var deassertedStr = []string{}
for _, v := range asserted {
assertedStr = append(assertedStr, v.String())
}
for _, v := range deasserted {
deassertedStr = append(deassertedStr, v.String())
}
return fmt.Sprintf(`Event Messages Disabled : %v
Sensor Scanning Disabled : %v
Enabled Assert Event : %s
Enabled Desassert Event : %s`,
res.EventMessagesDisabled,
res.SensorScanningDisabled,
strings.Join(assertedStr, "\n - "),
strings.Join(deassertedStr, "\n - "),
)
}
func (c *Client) GetSensorEventEnable(sensorNumber uint8) (response *GetSensorEventEnableResponse, err error) {
request := &GetSensorEventEnableRequest{
SensorNumber: sensorNumber,
}
response = &GetSensorEventEnableResponse{}
err = c.Exchange(request, response)
return
}