BxCmdSendDynamicArea.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package bx
  2. import (
  3. "bytes"
  4. "encoding/binary"
  5. )
  6. var GROUP byte = 0xa3
  7. var CMD byte = 0x06
  8. type CmdSendDynamicArea struct {
  9. baseBxCmd
  10. processMode byte
  11. r2 byte
  12. delAreaIds []byte
  13. areas []BxArea
  14. }
  15. func NewBxCmdSendDynamicArea(areas []BxArea) CmdSendDynamicArea {
  16. return CmdSendDynamicArea{
  17. baseBxCmd: newBaseCmd(CMD_SEND_DYNAMIC_AREA.group, CMD_SEND_DYNAMIC_AREA.code),
  18. areas: areas,
  19. }
  20. }
  21. func (sd CmdSendDynamicArea) ProcessMode() byte {
  22. return sd.processMode
  23. }
  24. func (sd CmdSendDynamicArea) SetProcessMode(processMode byte) {
  25. sd.processMode = processMode
  26. }
  27. func (sd CmdSendDynamicArea) R2() byte {
  28. return sd.r2
  29. }
  30. func (sd CmdSendDynamicArea) SetR2(r2 byte) {
  31. sd.r2 = r2
  32. }
  33. func (sd CmdSendDynamicArea) DelAreaIds() []byte {
  34. return sd.delAreaIds
  35. }
  36. func (sd CmdSendDynamicArea) SetDelAreaIds(delAreaIds []byte) {
  37. sd.delAreaIds = delAreaIds
  38. }
  39. func (sd CmdSendDynamicArea) Areas() []BxArea {
  40. return sd.areas
  41. }
  42. func (sd CmdSendDynamicArea) SetAreas(areas []BxArea) {
  43. sd.areas = areas
  44. }
  45. func (sd CmdSendDynamicArea) Build() []byte {
  46. w := bytes.NewBuffer(make([]byte, 0, 1024))
  47. binary.Write(w, binary.LittleEndian, sd.Group())
  48. binary.Write(w, binary.LittleEndian, sd.Cmd())
  49. binary.Write(w, binary.LittleEndian, sd.ReqResp())
  50. binary.Write(w, binary.LittleEndian, sd.processMode)
  51. binary.Write(w, binary.LittleEndian, sd.r2)
  52. if sd.delAreaIds == nil {
  53. binary.Write(w, binary.LittleEndian, byte(0x00))
  54. } else {
  55. binary.Write(w, binary.LittleEndian, byte(len(sd.delAreaIds)))
  56. binary.Write(w, binary.LittleEndian, sd.delAreaIds)
  57. }
  58. if sd.areas == nil || len(sd.areas) == 0 {
  59. binary.Write(w, binary.LittleEndian, byte(0x00))
  60. } else {
  61. binary.Write(w, binary.LittleEndian, byte(len(sd.areas)))
  62. for _, v := range sd.areas {
  63. b := v.Build()
  64. binary.Write(w, binary.LittleEndian, int16(len(b)))
  65. binary.Write(w, binary.LittleEndian, b)
  66. }
  67. }
  68. return w.Bytes()
  69. }