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
|
package ipmi
import (
"context"
"fmt"
"strings"
)
type CommandRawRequest struct {
NetFn NetFn
Cmd uint8
Data []byte
Name string
}
type CommandRawResponse struct {
Response []byte
}
func (req *CommandRawRequest) Command() Command {
return Command{ID: req.Cmd, NetFn: req.NetFn, Name: req.Name}
}
func (req *CommandRawRequest) Pack() []byte {
out := make([]byte, len(req.Data))
packBytes(req.Data, out, 0)
return out
}
func (res *CommandRawResponse) Unpack(msg []byte) error {
res.Response = msg
return nil
}
func (res *CommandRawResponse) CompletionCodes() map[uint8]string {
return map[uint8]string{}
}
func (res *CommandRawResponse) Format() string {
// convert the byte array to a slice of hex strings
hexStrings := make([]string, len(res.Response))
for i, b := range res.Response {
hexStrings[i] = fmt.Sprintf("0x%02X", b)
}
// join the hex strings with commas
hexString := strings.Join(hexStrings, ", ")
return fmt.Sprintf("raw.Response = %s", hexString)
}
func (c *Client) RawCommand(ctx context.Context, netFn NetFn, cmd uint8, data []byte, name string) (response *CommandRawResponse, err error) {
request := &CommandRawRequest{
NetFn: netFn,
Cmd: cmd,
Data: data,
Name: name,
}
response = &CommandRawResponse{}
err = c.Exchange(ctx, request, response)
return
}
|