forked from bougou/go-ipmi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_get_device_sdr_info.go
102 lines (85 loc) · 2.66 KB
/
cmd_get_device_sdr_info.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
package ipmi
import "fmt"
// 35.2 Get Device SDR Info Command
type GetDeviceSDRInfoRequest struct {
// true: Get SDR count. This returns the total number of SDRs in the device.
// false: Get Sensor count. This returns the number of sensors implemented on LUN this command was addressed to.
GetSDRCount bool
}
type GetDeviceSDRInfoResponse struct {
getSDRCount bool
Count uint8
// 0b = static sensor population. The number of sensors handled by this
// device is fixed, and a query shall return records for all sensors.
//
// 1b = dynamic sensor population. This device may have its sensor
// population vary during "run time" (defined as any time other that
// when an install operation is in progress).
DynamicSensorPopulation bool
LUN3HasSensors bool
LUN2HasSensors bool
LUN1HasSensors bool
LUN0HasSensors bool
// Four byte timestamp, or counter. Updated or incremented each time the
// sensor population changes. This field is not provided if the flags indicate a
// static sensor population.
SensorPopulationChangeIndicator uint32
}
func (req *GetDeviceSDRInfoRequest) Command() Command {
return CommandGetDeviceSDRInfo
}
func (req *GetDeviceSDRInfoRequest) Pack() []byte {
var b uint8
if req.GetSDRCount {
b = setBit0(b)
}
return []byte{b}
}
func (res *GetDeviceSDRInfoResponse) Unpack(msg []byte) error {
if len(msg) < 2 {
return ErrUnpackedDataTooShort
}
res.Count, _, _ = unpackUint8(msg, 0)
b, _, _ := unpackUint8(msg, 1)
res.DynamicSensorPopulation = isBit7Set(b)
res.LUN3HasSensors = isBit3Set(b)
res.LUN2HasSensors = isBit2Set(b)
res.LUN1HasSensors = isBit1Set(b)
res.LUN0HasSensors = isBit0Set(b)
if res.DynamicSensorPopulation {
if len(msg) < 6 {
return ErrUnpackedDataTooShort
}
res.SensorPopulationChangeIndicator, _, _ = unpackUint32L(msg, 2)
}
return nil
}
func (r *GetDeviceSDRInfoResponse) CompletionCodes() map[uint8]string {
return map[uint8]string{}
}
func (res *GetDeviceSDRInfoResponse) Format() string {
return fmt.Sprintf(`
Count : %d (%s)
Dynamic Population : %v
LUN 0 has sensors : %v
LUN 1 has sensors : %v
LUN 2 has sensors : %v
LUN 3 has sensors : %v
`,
res.Count, formatBool(res.getSDRCount, "SDRs", "Sensors"),
res.DynamicSensorPopulation,
res.LUN0HasSensors,
res.LUN1HasSensors,
res.LUN2HasSensors,
res.LUN3HasSensors,
)
}
// This command returns general information about the collection of sensors in a Dynamic Sensor Device.
func (c *Client) GetDeviceSDRInfo(getSDRCount bool) (response *GetDeviceSDRInfoResponse, err error) {
request := &GetDeviceSDRInfoRequest{
GetSDRCount: getSDRCount,
}
response = &GetDeviceSDRInfoResponse{}
err = c.Exchange(request, response)
return
}