dlt645_test.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. //020068361211
  19. func TestParse(t *testing.T) {
  20. dlt645 := LoadProtocol("DLT645-2007")
  21. cap := []byte{104, 2, 0, 104, 54, 18, 17, 104, 145, 8, 51, 51, 51, 51, 51, 51, 51, 51, 196, 22}
  22. //104, 17, 18, 54, 104, 0, 2, 104, 147, 6, 53, 51, 155, 105, 69, 68, 33, 22}
  23. //t1 := []byte{0xfe, 0xfe, 0xfe, 0xfe, 0x68, 0x04, 0x00, 0x42, 0x05, 0x08, 0x21, 0x68, 0x11, 0x04, 0x33, 0x33, 0x33, 0x33, 0x25, 0x16}
  24. addr_ack := []byte{0x68, 0x08, 0x00, 0x01, 0x04, 0x06, 0x01, 0x68, 0x93, 0x06, 0x3B, 0x33, 0x34, 0x37, 0x39, 0x34, 0xC3, 0x16}
  25. //tcmd := []byte{0xfe, 0xfe, 0xfe, 0xfe, 0x68, 0x06, 0x00, 0x42, 0x05, 0x08, 0x21, 0x68, 0x11, 0x04, 0x33, 0x33, 0x33, 0x33, 0x27, 0x16}
  26. 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}
  27. //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}
  28. devname := ""
  29. v1 := dlt645.ParsePacket(cap, &devname)
  30. t.Log(v1)
  31. vret := dlt645.ParsePacket(tack, &devname)
  32. if vret == nil {
  33. t.Error("Error in parse packet")
  34. }
  35. mret := dlt645.ParsePacket(addr_ack, &devname)
  36. t.Log(mret, ",", devname)
  37. t.Logf("Get param: [%#v]\n", vret)
  38. }
  39. //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
  40. func TestHj212(t *testing.T) {
  41. 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"
  42. ip := LoadProtocol("HJ212")
  43. ip.Init("HJ212")
  44. mret := ip.ParsePacket([]byte(parten))
  45. log.Info(mret)
  46. }