File: cmd_get_sensor_thresholds.go

package info (click to toggle)
golang-github-bougou-go-ipmi 0.7.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,880 kB
  • sloc: makefile: 38
file content (85 lines) | stat: -rw-r--r-- 2,654 bytes parent folder | download
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
package ipmi

import (
	"context"
	"fmt"
)

// 35.9 Get Sensor Thresholds Command
type GetSensorThresholdsRequest struct {
	SensorNumber uint8
}

type GetSensorThresholdsResponse struct {
	// Readable thresholds mask
	UNR_Readable bool
	UCR_Readable bool
	UNC_Readable bool
	LNR_Readable bool
	LCR_Readable bool
	LNC_Readable bool

	// Threshold value
	LNC_Raw uint8
	LCR_Raw uint8
	LNR_Raw uint8
	UNC_Raw uint8
	UCR_Raw uint8
	UNR_Raw uint8
}

func (req *GetSensorThresholdsRequest) Command() Command {
	return CommandGetSensorThresholds
}

func (req *GetSensorThresholdsRequest) Pack() []byte {
	out := make([]byte, 1)
	packUint8(req.SensorNumber, out, 0)
	return out
}

func (res *GetSensorThresholdsResponse) Unpack(msg []byte) error {
	if len(msg) < 7 {
		return ErrUnpackedDataTooShortWith(len(msg), 7)
	}
	b, _, _ := unpackUint8(msg, 0)
	res.UNR_Readable = isBit5Set(b)
	res.UCR_Readable = isBit4Set(b)
	res.UNC_Readable = isBit3Set(b)
	res.LNR_Readable = isBit2Set(b)
	res.LCR_Readable = isBit1Set(b)
	res.LNC_Readable = isBit0Set(b)

	res.LNC_Raw, _, _ = unpackUint8(msg, 1)
	res.LCR_Raw, _, _ = unpackUint8(msg, 2)
	res.LNR_Raw, _, _ = unpackUint8(msg, 3)
	res.UNC_Raw, _, _ = unpackUint8(msg, 4)
	res.UCR_Raw, _, _ = unpackUint8(msg, 5)
	res.UNR_Raw, _, _ = unpackUint8(msg, 6)

	return nil
}

func (r *GetSensorThresholdsResponse) CompletionCodes() map[uint8]string {
	return map[uint8]string{}
}

func (res *GetSensorThresholdsResponse) Format() string {
	return "" +
		fmt.Sprintf("UNR Readable : %v%s\n", res.UNR_Readable, formatBool(res.UNR_Readable, fmt.Sprintf(", raw: %#02x", res.UNR_Raw), "")) +
		fmt.Sprintf("UCR Readable : %v%s\n", res.UCR_Readable, formatBool(res.UCR_Readable, fmt.Sprintf(", raw: %#02x", res.UCR_Raw), "")) +
		fmt.Sprintf("UNC Readable : %v%s\n", res.UNC_Readable, formatBool(res.UNC_Readable, fmt.Sprintf(", raw: %#02x", res.UNC_Raw), "")) +
		fmt.Sprintf("LNR Readable : %v%s\n", res.LNR_Readable, formatBool(res.LNR_Readable, fmt.Sprintf(", raw: %#02x", res.LNR_Raw), "")) +
		fmt.Sprintf("LCR Readable : %v%s\n", res.LCR_Readable, formatBool(res.LCR_Readable, fmt.Sprintf(", raw: %#02x", res.LCR_Raw), "")) +
		fmt.Sprintf("LNC Readable : %v%s\n", res.LNC_Readable, formatBool(res.LNC_Readable, fmt.Sprintf(", raw: %#02x", res.LNC_Raw), ""))
}

// This command retrieves the threshold for the given sensor.
func (c *Client) GetSensorThresholds(ctx context.Context, sensorNumber uint8) (response *GetSensorThresholdsResponse, err error) {
	request := &GetSensorThresholdsRequest{
		SensorNumber: sensorNumber,
	}
	response = &GetSensorThresholdsResponse{}
	err = c.Exchange(ctx, request, response)
	return
}