12345678910111213141516171819202122232425262728293031323334 |
- package bx
- import (
- "bytes"
- "encoding/binary"
- )
- type BxCmdTurnOnOff struct {
- baseBxCmd
- on bool
- }
- // NewBxCmdTurnOnOff ture=on false=off
- func NewBxCmdTurnOnOff(on bool) BxCmdTurnOnOff {
- return BxCmdTurnOnOff{
- baseBxCmd: newBaseCmd(CMD_TURN_ON_OFF.group, CMD_TURN_ON_OFF.code),
- on: on,
- }
- }
- func (cmd BxCmdTurnOnOff) Build() []byte {
- w := bytes.NewBuffer(make([]byte, 0, 8))
- binary.Write(w, binary.LittleEndian, cmd.Group())
- binary.Write(w, binary.LittleEndian, cmd.Cmd())
- binary.Write(w, binary.LittleEndian, cmd.ReqResp())
- //r0 r1
- binary.Write(w, binary.LittleEndian, byte(0x00))
- binary.Write(w, binary.LittleEndian, byte(0x00))
- if cmd.on {
- binary.Write(w, binary.LittleEndian, byte(0x01))
- } else {
- binary.Write(w, binary.LittleEndian, byte(0x02))
- }
- return w.Bytes()
- }
|