File: cmd_get_sensor_type.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 (56 lines) | stat: -rw-r--r-- 1,353 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
package ipmi

import (
	"context"
	"fmt"
)

// GetSensorTypeRequest (31.2)
type GetSensorTypeRequest struct {
	SensorNumber uint8
}

type GetSensorTypeResponse struct {
	SensorType       SensorType
	EventReadingType EventReadingType
}

func (req *GetSensorTypeRequest) Command() Command {
	return CommandGetSensorType
}

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

func (res *GetSensorTypeResponse) Unpack(msg []byte) error {
	if len(msg) < 2 {
		return ErrUnpackedDataTooShortWith(len(msg), 2)
	}
	b1, _, _ := unpackUint8(msg, 0)
	res.SensorType = SensorType(b1)
	b2, _, _ := unpackUint8(msg, 1)
	res.EventReadingType = EventReadingType(b2)
	return nil
}

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

func (res *GetSensorTypeResponse) Format() string {
	return "" +
		fmt.Sprintf("Sensor Type        : %s\n", res.SensorType) +
		fmt.Sprintf("Event/Reading Type : %#02x (%s)\n", uint8(res.EventReadingType), res.EventReadingType.String())
}

func (c *Client) GetSensorType(ctx context.Context, sensorNumber uint8) (response *GetSensorTypeResponse, err error) {
	request := &GetSensorTypeRequest{
		SensorNumber: sensorNumber,
	}
	response = &GetSensorTypeResponse{}
	err = c.Exchange(ctx, request, response)
	return
}