BxCmdTimingSwitch.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package bx
  2. import (
  3. "bytes"
  4. "encoding/binary"
  5. )
  6. //定时开关机
  7. type CmdTimingSwitch struct {
  8. baseBxCmd
  9. onOffSet [][2]uint64
  10. }
  11. func NewCmdTimingSwitch(onOffSet [][2]uint64) CmdTimingSwitch {
  12. return CmdTimingSwitch{
  13. baseBxCmd: newBaseCmd(CMD_TIMING_SWITCH.group, CMD_TIMING_SWITCH.code),
  14. onOffSet: onOffSet,
  15. }
  16. }
  17. func (cmd CmdTimingSwitch) Build() []byte {
  18. w := bytes.NewBuffer(make([]byte, 0, 1024))
  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 len(cmd.onOffSet) == 0 || len(cmd.onOffSet) > 256 {
  26. return nil
  27. }
  28. binary.Write(w, binary.LittleEndian, byte(len(cmd.onOffSet)))
  29. for i, v := range cmd.onOffSet {
  30. if i > 2 {
  31. break
  32. }
  33. binary.Write(w, binary.BigEndian, Uint2BCD(uint64(v[0]), true)) //开机
  34. binary.Write(w, binary.BigEndian, Uint2BCD(uint64(v[1]), true)) //关机
  35. }
  36. return w.Bytes()
  37. }