-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathcmd_get_sol_config_params.go
171 lines (141 loc) · 4.7 KB
/
cmd_get_sol_config_params.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package ipmi
import (
"context"
"fmt"
)
// 26.3 Get SOL Configuration Parameters Command
type GetSOLConfigParamRequest struct {
GetParamRevisionOnly bool
ChannelNumber uint8
ParamSelector SOLConfigParamSelector
SetSelector uint8
BlockSelector uint8
}
type GetSOLConfigParamResponse struct {
ParamRevision uint8
ParamData []byte
}
func (req *GetSOLConfigParamRequest) Command() Command {
return CommandGetSOLConfigParam
}
func (req *GetSOLConfigParamRequest) Pack() []byte {
out := make([]byte, 4)
b := req.ChannelNumber
if req.GetParamRevisionOnly {
b = setBit7(b)
}
packUint8(b, out, 0)
packUint8(uint8(req.ParamSelector), out, 1)
packUint8(req.SetSelector, out, 2)
packUint8(req.BlockSelector, out, 3)
return out
}
func (res *GetSOLConfigParamResponse) CompletionCodes() map[uint8]string {
return map[uint8]string{}
}
func (res *GetSOLConfigParamResponse) Unpack(msg []byte) error {
if len(msg) < 1 {
return ErrUnpackedDataTooShortWith(len(msg), 1)
}
res.ParamRevision = msg[0]
if len(msg) > 1 {
res.ParamData, _, _ = unpackBytes(msg, 1, len(msg)-1)
}
return nil
}
func (res *GetSOLConfigParamResponse) Format() string {
return ""
}
func (c *Client) GetSOLConfigParam(ctx context.Context, channelNumber uint8, paramSelector SOLConfigParamSelector, setSelector, blockSelector uint8) (response *GetSOLConfigParamResponse, err error) {
request := &GetSOLConfigParamRequest{
ChannelNumber: channelNumber,
ParamSelector: paramSelector,
SetSelector: 0x00,
BlockSelector: 0x00,
}
response = &GetSOLConfigParamResponse{}
err = c.Exchange(ctx, request, response)
return
}
func (c *Client) GetSOLConfigParamFor(ctx context.Context, channelNumber uint8, param SOLConfigParameter) error {
if isNilSOLConfigParameter(param) {
return nil
}
paramSelector, setSelector, blockSelector := param.SOLConfigParameter()
res, err := c.GetSOLConfigParam(ctx, channelNumber, paramSelector, setSelector, blockSelector)
if err != nil {
return fmt.Errorf("GetSOLConfigParam for param (%s[%2d]) failed, err: %w", paramSelector.String(), paramSelector, err)
}
if err := param.Unpack(res.ParamData); err != nil {
return fmt.Errorf("unpack param (%s[%2d]) failed, err: %w", paramSelector.String(), paramSelector, err)
}
return nil
}
func (c *Client) GetSOLConfigParams(ctx context.Context, channelNumber uint8) (*SOLConfigParams, error) {
solConfigParams := &SOLConfigParams{
SetInProgress: &SOLConfigParam_SetInProgress{},
SOLEnable: &SOLConfigParam_SOLEnable{},
SOLAuthentication: &SOLConfigParam_SOLAuthentication{},
Character: &SOLConfigParam_Character{},
SOLRetry: &SOLConfigParam_SOLRetry{},
NonVolatileBitRate: &SOLConfigParam_NonVolatileBitRate{},
VolatileBitRate: &SOLConfigParam_VolatileBitRate{},
PayloadChannel: &SOLConfigParam_PayloadChannel{},
PayloadPort: &SOLConfigParam_PayloadPort{},
}
if err := c.GetSOLConfigParamsFor(ctx, channelNumber, solConfigParams); err != nil {
return nil, fmt.Errorf("GetSOLConfigParamFor failed, err: %w", err)
}
return solConfigParams, nil
}
func (c *Client) GetSOLConfigParamsFor(ctx context.Context, channelNumber uint8, solConfigParams *SOLConfigParams) error {
if solConfigParams == nil {
return nil
}
if solConfigParams.SetInProgress != nil {
if err := c.GetSOLConfigParamFor(ctx, channelNumber, solConfigParams.SetInProgress); err != nil {
return err
}
}
if solConfigParams.SOLEnable != nil {
if err := c.GetSOLConfigParamFor(ctx, channelNumber, solConfigParams.SOLEnable); err != nil {
return err
}
}
if solConfigParams.SOLAuthentication != nil {
if err := c.GetSOLConfigParamFor(ctx, channelNumber, solConfigParams.SOLAuthentication); err != nil {
return err
}
}
if solConfigParams.Character != nil {
if err := c.GetSOLConfigParamFor(ctx, channelNumber, solConfigParams.Character); err != nil {
return err
}
}
if solConfigParams.SOLRetry != nil {
if err := c.GetSOLConfigParamFor(ctx, channelNumber, solConfigParams.SOLRetry); err != nil {
return err
}
}
if solConfigParams.NonVolatileBitRate != nil {
if err := c.GetSOLConfigParamFor(ctx, channelNumber, solConfigParams.NonVolatileBitRate); err != nil {
return err
}
}
if solConfigParams.VolatileBitRate != nil {
if err := c.GetSOLConfigParamFor(ctx, channelNumber, solConfigParams.VolatileBitRate); err != nil {
return err
}
}
if solConfigParams.PayloadChannel != nil {
if err := c.GetSOLConfigParamFor(ctx, channelNumber, solConfigParams.PayloadChannel); err != nil {
return err
}
}
if solConfigParams.PayloadPort != nil {
if err := c.GetSOLConfigParamFor(ctx, channelNumber, solConfigParams.PayloadPort); err != nil {
return err
}
}
return nil
}