dlt645_test.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package protocol
  2. import (
  3. "encoding/hex"
  4. "testing"
  5. "github.com/yuguorong/go/log"
  6. )
  7. //fefefefe68040042050821681104333333332516
  8. //fefefefe68040042050821681104333333332516
  9. func TestPacket(t *testing.T) {
  10. dlt645 := LoadProtocol("DLT645-2007")
  11. //FEFEFEFE68AAAAAAAAAAAA681300DF16
  12. readcmd := dlt645.PackageCmd("ReadAddress")
  13. log.Infof("%X\n", readcmd)
  14. //fefefefe68010018251120681104333333332016
  15. cmd := dlt645.PackageCmd("TotalActivePower", "201125180001")
  16. log.Infof("cmd %X", cmd)
  17. if cmd == nil {
  18. t.Error("failed in PackageCmd")
  19. }
  20. srecv := hex.EncodeToString(cmd.([]byte))
  21. t.Logf("param: [%s]\n", srecv)
  22. }
  23. //020068361211
  24. func TestParse(t *testing.T) {
  25. dlt645 := LoadProtocol("DLT645-2007")
  26. v := dlt645.PackageCmd("TotalActivePower", "111236680002")
  27. log.Infof("%X\n", v)
  28. cap := []byte{104, 2, 0, 104, 54, 18, 17, 104, 145, 8, 51, 51, 51, 51, 51, 51, 51, 51, 196, 22}
  29. //104, 17, 18, 54, 104, 0, 2, 104, 147, 6, 53, 51, 155, 105, 69, 68, 33, 22}
  30. //t1 := []byte{0xfe, 0xfe, 0xfe, 0xfe, 0x68, 0x04, 0x00, 0x42, 0x05, 0x08, 0x21, 0x68, 0x11, 0x04, 0x33, 0x33, 0x33, 0x33, 0x25, 0x16}
  31. addr_ack := []byte{0x68, 0x08, 0x00, 0x01, 0x04, 0x06, 0x01, 0x68, 0x93, 0x06, 0x3B, 0x33, 0x34, 0x37, 0x39, 0x34, 0xC3, 0x16}
  32. //tcmd := []byte{0xfe, 0xfe, 0xfe, 0xfe, 0x68, 0x06, 0x00, 0x42, 0x05, 0x08, 0x21, 0x68, 0x11, 0x04, 0x33, 0x33, 0x33, 0x33, 0x27, 0x16}
  33. tack := []byte{0xfe, 0xfe, 0xfe, 0xfe, 0x68, 0x06, 0x00, 0x42, 0x05, 0x08, 0x21, 0x68, 0x91, 0x08, 0x33, 0x33, 0x33, 0x33, 0x47, 0xc5, 0x33, 0x33, 0x1d, 0x16}
  34. //tdec := []byte{0xfe, 0xfe, 0xfe, 0xfe, 0x68, 0x04, 0x00, 0x42, 0x05, 0x08, 0x21, 0x68, 0x91, 0x08, 0x33, 0x33, 0x33, 0x33, 0xb4, 0xbc, 0x34, 0x33, 0x80, 0x16}
  35. devname := ""
  36. v1 := dlt645.ParsePacket(cap, &devname)
  37. t.Log(v1)
  38. vret := dlt645.ParsePacket(tack, &devname)
  39. if vret == nil {
  40. t.Error("Error in parse packet")
  41. }
  42. mret := dlt645.ParsePacket(addr_ack, &devname)
  43. t.Log(mret, ",", devname)
  44. t.Logf("Get param: [%#v]\n", vret)
  45. }
  46. //map[CH2O-Rtd:0.008 CN:2011 CO2-Rtd:405.0 DataTime:20211006030527 HUMI-Rtd:43.5 MN:8888888826462285 PM25-Rtd:2.0 TEMP-Rtd:22.0 VOC-Rtd:0.052
  47. func TestHj212(t *testing.T) {
  48. parten := "##0159ST=22;CN=2011;PW=123456;MN=8888888826462285;CP=&&DataTime=20211006030527;TEMP-Rtd=22.0;HUMI-Rtd=43.5;PM25-Rtd=2.0;CO2-Rtd=405.0;CH2O-Rtd=0.008;VOC-Rtd=0.052;&&8ef7"
  49. ip := LoadProtocol("HJ212")
  50. ip.Init("HJ212")
  51. mret := ip.ParsePacket([]byte(parten))
  52. log.Info(mret)
  53. }