forked from bougou/go-ipmi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_master_write_read.go
60 lines (49 loc) · 1.51 KB
/
cmd_master_write_read.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
package ipmi
// 22.11 Master Write-Read Command
type MasterWriteReadRequest struct {
ChannelNumber uint8
BusID uint8
BusTypeIsPrivate bool
SlaveAddress uint8
ReadCount uint8
Data []byte // Data to write. This command should support at least 35 bytes of write data
}
type MasterWriteReadResponse struct {
// Bytes read from specified slave address. This field will be absent if the read count is 0. The controller terminates the I2C transaction with a STOP condition after reading the requested number of bytes.
Data []byte
}
func (req *MasterWriteReadRequest) Command() Command {
return CommandMasterWriteRead
}
func (req *MasterWriteReadRequest) Pack() []byte {
out := make([]byte, 3+len(req.Data))
var b uint8 = req.ChannelNumber << 4
b |= (req.BusID << 1) & 0x0e
if req.BusTypeIsPrivate {
b = setBit0(b)
}
packUint8(b, out, 0)
packUint8(req.SlaveAddress, out, 1)
packUint8(req.ReadCount, out, 2)
packBytes(req.Data, out, 3)
return out
}
func (res *MasterWriteReadResponse) Unpack(msg []byte) error {
return nil
}
func (*MasterWriteReadResponse) CompletionCodes() map[uint8]string {
return map[uint8]string{
0x81: "Lost Arbitration",
0x82: "Bus Error",
0x83: "NAK on Write",
0x84: "Truncated Read",
}
}
func (res *MasterWriteReadResponse) Format() string {
return ""
}
func (c *Client) MasterWriteRead(request *MasterWriteReadRequest) (*MasterWriteReadResponse, error) {
response := &MasterWriteReadResponse{}
err := c.Exchange(request, response)
return response, err
}