BxCmdTurnOnOff.go 803 B

12345678910111213141516171819202122232425262728293031323334
  1. package bx
  2. import (
  3. "bytes"
  4. "encoding/binary"
  5. )
  6. type BxCmdTurnOnOff struct {
  7. baseBxCmd
  8. on bool
  9. }
  10. // NewBxCmdTurnOnOff ture=on false=off
  11. func NewBxCmdTurnOnOff(on bool) BxCmdTurnOnOff {
  12. return BxCmdTurnOnOff{
  13. baseBxCmd: newBaseCmd(CMD_TURN_ON_OFF.group, CMD_TURN_ON_OFF.code),
  14. on: on,
  15. }
  16. }
  17. func (cmd BxCmdTurnOnOff) Build() []byte {
  18. w := bytes.NewBuffer(make([]byte, 0, 8))
  19. binary.Write(w, binary.LittleEndian, cmd.Group())
  20. binary.Write(w, binary.LittleEndian, cmd.Cmd())
  21. binary.Write(w, binary.LittleEndian, cmd.ReqResp())
  22. //r0 r1
  23. binary.Write(w, binary.LittleEndian, byte(0x00))
  24. binary.Write(w, binary.LittleEndian, byte(0x00))
  25. if cmd.on {
  26. binary.Write(w, binary.LittleEndian, byte(0x01))
  27. } else {
  28. binary.Write(w, binary.LittleEndian, byte(0x02))
  29. }
  30. return w.Bytes()
  31. }