dlt645_0x93.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package protocol
  2. import (
  3. "encoding/hex"
  4. "fmt"
  5. "github.com/gogf/gf/os/glog"
  6. )
  7. type Dlt_0x93 struct {
  8. //接收表号
  9. DeviceAddress []byte
  10. //表号
  11. DeviceID string
  12. //当前视在功率
  13. ApparentPower float64
  14. }
  15. func (entity *Dlt_0x93) MsgID() MsgID {
  16. return ReadAddress
  17. }
  18. //func (entity *Dlt_0x93) GetDeviceAddress() DeviceAddress {
  19. // return entity.DeviceAddress
  20. //}
  21. func (entity *Dlt_0x93) Encode(ctx *PacketContext) ([]byte, error) {
  22. writer := NewWriter()
  23. // 接收符号
  24. writer.Write([]byte{0x68, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0x68, 0x13, 0x00, 0xDF, 0x16})
  25. return writer.Bytes(), nil
  26. }
  27. func (entity *Dlt_0x93) Decode(ctx *PacketContext, data []byte) (result string, err error) {
  28. entity.DeviceAddress = data[1:7]
  29. ctx.SetReceiveAddress(data[1:7])
  30. glog.Debugf("11111111----------DeviceAddress:%2X", ctx.GetReceiveAddress())
  31. bytea := data[1:7]
  32. for i, j := 0, len(bytea)-1; i < j; i, j = i+1, j-1 {
  33. bytea[i], bytea[j] = bytea[j], bytea[i]
  34. }
  35. entity.DeviceID = hex.EncodeToString(bytea)
  36. ctx.SetId(entity.DeviceID)
  37. glog.Debugf("2222222----------DeviceAddress:%2X", ctx.GetReceiveAddress())
  38. glog.Debugf("表地址接收成功:表号:%s", entity.DeviceID)
  39. result = fmt.Sprintf("%s:%s", "表号", entity.DeviceID)
  40. glog.Debugf("DeviceAddress:%2X,Id:%s,", ctx.GetReceiveAddress(), ctx.GetId())
  41. return result, nil
  42. }