forked from bougou/go-ipmi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_get_sensor_reading_factors.go
95 lines (74 loc) · 2.13 KB
/
cmd_get_sensor_reading_factors.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
package ipmi
import "fmt"
// 35.5 Get Sensor Reading Factors Command
type GetSensorReadingFactorsRequest struct {
SensorNumber uint8
Reading uint8
}
type GetSensorReadingFactorsResponse struct {
NextReading uint8
ReadingFactors
}
func (req *GetSensorReadingFactorsRequest) Command() Command {
return CommandGetSensorReadingFactors
}
func (req *GetSensorReadingFactorsRequest) Pack() []byte {
out := make([]byte, 2)
packUint8(req.SensorNumber, out, 0)
packUint8(req.Reading, out, 1)
return out
}
func (res *GetSensorReadingFactorsResponse) Unpack(msg []byte) error {
if len(msg) < 7 {
return ErrUnpackedDataTooShort
}
res.NextReading, _, _ = unpackUint8(msg, 0)
b1, _, _ := unpackUint8(msg, 1)
b2, _, _ := unpackUint8(msg, 2)
m := uint16(b2&0xc0)<<2 | uint16(b1)
res.M = int16(twosComplement(uint32(m), 10))
res.Tolerance = b2 & 0x3f
b3, _, _ := unpackUint8(msg, 3)
b4, _, _ := unpackUint8(msg, 4)
b5, _, _ := unpackUint8(msg, 5)
b := uint16(b4&0xc0)<<2 | uint16(b3)
res.B = int16(twosComplement(uint32(b), 10))
res.Accuracy = uint16(b5&0xf0)<<2 | uint16(b4&0x3f)
res.Accuracy_Exp = (b5 & 0x0c) >> 2
b6, _, _ := unpackUint8(msg, 6)
rExp := uint8((b6 & 0xf0) >> 4)
res.R_Exp = int8(twosComplement(uint32(rExp), 4))
bExp := uint8(b6 & 0x0f)
res.B_Exp = int8(twosComplement(uint32(bExp), 4))
return nil
}
func (r *GetSensorReadingFactorsResponse) CompletionCodes() map[uint8]string {
return map[uint8]string{}
}
func (res *GetSensorReadingFactorsResponse) Format() string {
return fmt.Sprintf(`M: %d
B: %d
B_Exp (K1): %d
R_Exp (K2): %d
Tolerance: %d
Accuracy: %d
AccuracyExp: %d`,
res.M,
res.B,
res.B_Exp,
res.R_Exp,
res.Tolerance,
res.Accuracy,
res.Accuracy_Exp,
)
}
// This command returns the Sensor Reading Factors fields for the specified reading value on the specified sensor.
func (c *Client) GetSensorReadingFactors(sensorNumber uint8, reading uint8) (response *GetSensorReadingFactorsResponse, err error) {
request := &GetSensorReadingFactorsRequest{
SensorNumber: sensorNumber,
Reading: reading,
}
response = &GetSensorReadingFactorsResponse{}
err = c.Exchange(request, response)
return
}