package protocol import ( "encoding/hex" "testing" "github.com/yuguorong/go/log" ) //fefefefe68040042050821681104333333332516 //fefefefe68040042050821681104333333332516 func TestPacket(t *testing.T) { dlt645 := LoadProtocol("DLT645-2007") cmd := dlt645.PackageCmd("00000000", "210805420004") if cmd == nil { t.Error("failed in PackageCmd") } srecv := hex.EncodeToString(cmd.([]byte)) t.Logf("param: [%s]\n", srecv) } func TestParse(t *testing.T) { dlt645 := LoadProtocol("DLT645-2007") //t1 := []byte{0xfe, 0xfe, 0xfe, 0xfe, 0x68, 0x04, 0x00, 0x42, 0x05, 0x08, 0x21, 0x68, 0x11, 0x04, 0x33, 0x33, 0x33, 0x33, 0x25, 0x16} tcmd := []byte{0xfe, 0xfe, 0xfe, 0xfe, 0x68, 0x06, 0x00, 0x42, 0x05, 0x08, 0x21, 0x68, 0x11, 0x04, 0x33, 0x33, 0x33, 0x33, 0x27, 0x16} 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} //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} vret := dlt645.ParsePacket(tack, tcmd) if vret == nil { t.Error("Error in parse packet") } t.Logf("Get param: [%#v]\n", vret) } //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 func TestHj212(t *testing.T) { 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" ip := LoadProtocol("HJ212") ip.Init("HJ212") mret := ip.ParsePacket([]byte(parten)) log.Info(mret) }