dlt645_test.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. cmd := dlt645.PackageCmd("00000000", "210805420004")
  12. if cmd == nil {
  13. t.Error("failed in PackageCmd")
  14. }
  15. srecv := hex.EncodeToString(cmd.([]byte))
  16. t.Logf("param: [%s]\n", srecv)
  17. }
  18. func TestParse(t *testing.T) {
  19. dlt645 := LoadProtocol("DLT645-2007")
  20. //t1 := []byte{0xfe, 0xfe, 0xfe, 0xfe, 0x68, 0x04, 0x00, 0x42, 0x05, 0x08, 0x21, 0x68, 0x11, 0x04, 0x33, 0x33, 0x33, 0x33, 0x25, 0x16}
  21. tcmd := []byte{0xfe, 0xfe, 0xfe, 0xfe, 0x68, 0x06, 0x00, 0x42, 0x05, 0x08, 0x21, 0x68, 0x11, 0x04, 0x33, 0x33, 0x33, 0x33, 0x27, 0x16}
  22. 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}
  23. //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}
  24. vret := dlt645.ParsePacket(tack, tcmd)
  25. if vret == nil {
  26. t.Error("Error in parse packet")
  27. }
  28. t.Logf("Get param: [%#v]\n", vret)
  29. }
  30. //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
  31. func TestHj212(t *testing.T) {
  32. 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"
  33. ip := LoadProtocol("HJ212")
  34. ip.Init("HJ212")
  35. mret := ip.ParsePacket([]byte(parten))
  36. log.Info(mret)
  37. }