forked from bougou/go-ipmi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_get_poh_counter.go
65 lines (52 loc) · 1.43 KB
/
cmd_get_poh_counter.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
package ipmi
import (
"fmt"
)
// 28.14 Get POH Counter Command
type GetPOHCounterRequest struct {
// empty
}
type GetPOHCounterResponse struct {
MinutesPerCount uint8
CounterReading uint32
}
func (res *GetPOHCounterResponse) Minutes() uint32 {
return res.CounterReading * uint32(res.MinutesPerCount)
}
func (req *GetPOHCounterRequest) Command() Command {
return CommandGetPOHCounter
}
func (req *GetPOHCounterRequest) Pack() []byte {
return []byte{}
}
func (res *GetPOHCounterResponse) Unpack(msg []byte) error {
if len(msg) < 5 {
return ErrUnpackedDataTooShort
}
res.MinutesPerCount, _, _ = unpackUint8(msg, 0)
res.CounterReading, _, _ = unpackUint32L(msg, 1)
return nil
}
func (r *GetPOHCounterResponse) CompletionCodes() map[uint8]string {
return map[uint8]string{}
}
func (res *GetPOHCounterResponse) Format() string {
totalMinutes := res.Minutes()
days := totalMinutes / 1440
minutes := totalMinutes - days*1440
hours := minutes / 60
return fmt.Sprintf(`POH Counter : %d days, %d hours
Minutes per count : %d
Counter reading : %d`,
days, hours,
res.MinutesPerCount,
res.CounterReading,
)
}
// This command returns the present reading of the POH (Power-On Hours) counter, plus the number of counts per hour.
func (c *Client) GetPOHCounter() (response *GetPOHCounterResponse, err error) {
request := &GetPOHCounterRequest{}
response = &GetPOHCounterResponse{}
err = c.Exchange(request, response)
return
}