register.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package protocol
  2. // 消息ID枚举
  3. type MsgID uint32
  4. //type DeviceAddress []byte
  5. const (
  6. ReadAddress MsgID = 0x93
  7. // 注册心跳
  8. Msgdlt_0x0040 MsgID = 0x0040
  9. //上传正向有功总电能
  10. Msgdlt_0x33333433 MsgID = 0x33333433
  11. //上传反向有功总电能
  12. Msgdlt_0x33333533 MsgID = 0x33333533
  13. //上传A电压
  14. Msgdlt_0x33343435 MsgID = 0x33343435
  15. //上传A电流
  16. Msgdlt_0x33343535 MsgID = 0x33343535
  17. //上传B电压
  18. Msgdlt_0x33353435 MsgID = 0x33353435
  19. //上传B电流
  20. Msgdlt_0x33353535 MsgID = 0x33353535
  21. //上传C电压
  22. Msgdlt_0x33363435 MsgID = 0x33363435
  23. //上传C电流
  24. Msgdlt_0x33363535 MsgID = 0x33363535
  25. //当前总有功功率
  26. Msgdlt_0x33333635 MsgID = 0x33333635
  27. //当前总无功功率
  28. Msgdlt_0x33333735 MsgID = 0x33333735
  29. //总功率因数
  30. Msgdlt_0x33333935 MsgID = 0x33333935
  31. //当前视在功率
  32. Msgdlt_0x33333835 MsgID = 0x33333835
  33. // 电压数据块
  34. Msgdlt_0x33323435 MsgID = 0x33323435
  35. // 电流数据块
  36. Msgdlt_0x33323535 MsgID = 0x33323535
  37. )
  38. // 消息实体映射
  39. var entityMapper = map[uint32]func() Entity{
  40. uint32(Msgdlt_0x0040): func() Entity {
  41. return new(Dlt_0x0040)
  42. },
  43. uint32(Msgdlt_0x33333433): func() Entity {
  44. return new(Dlt_0x33333433)
  45. },
  46. uint32(Msgdlt_0x33333533): func() Entity {
  47. return new(Dlt_0x33333533)
  48. },
  49. uint32(Msgdlt_0x33343435): func() Entity {
  50. return new(Dlt_0x33343435)
  51. },
  52. uint32(Msgdlt_0x33343535): func() Entity {
  53. return new(Dlt_0x33343535)
  54. },
  55. uint32(Msgdlt_0x33353435): func() Entity {
  56. return new(Dlt_0x33353435)
  57. },
  58. uint32(Msgdlt_0x33353535): func() Entity {
  59. return new(Dlt_0x33353535)
  60. },
  61. uint32(Msgdlt_0x33363435): func() Entity {
  62. return new(Dlt_0x33363435)
  63. },
  64. uint32(Msgdlt_0x33363535): func() Entity {
  65. return new(Dlt_0x33363535)
  66. },
  67. uint32(Msgdlt_0x33333635): func() Entity {
  68. return new(Dlt_0x33333635)
  69. },
  70. uint32(Msgdlt_0x33333735): func() Entity {
  71. return new(Dlt_0x33333735)
  72. },
  73. uint32(Msgdlt_0x33333935): func() Entity {
  74. return new(Dlt_0x33333935)
  75. },
  76. uint32(Msgdlt_0x33333835): func() Entity {
  77. return new(Dlt_0x33333835)
  78. },
  79. uint32(ReadAddress): func() Entity {
  80. return new(Dlt_0x93)
  81. },
  82. uint32(Msgdlt_0x33323435): func() Entity {
  83. return new(Dlt_0x33323435)
  84. },
  85. uint32(Msgdlt_0x33323535): func() Entity {
  86. return new(Dlt_0x33323535)
  87. },
  88. }
  89. // Register 类型注册
  90. func Register(typ uint32, creator func() Entity) {
  91. entityMapper[typ] = creator
  92. }