123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package protocol
- import (
- "encoding/hex"
- "testing"
- "github.com/yuguorong/go/log"
- )
- //fefefefe68040042050821681104333333332516
- //fefefefe68040042050821681104333333332516
- func TestPacket(t *testing.T) {
- dlt645 := LoadProtocol("DLT645-2007")
- //FEFEFEFE68AAAAAAAAAAAA681300DF16
- readcmd := dlt645.PackageCmd("ReadAddress")
- log.Infof("%X\n", readcmd)
- //fefefefe68010018251120681104333333332016
- cmd := dlt645.PackageCmd("TotalActivePower", "201125180001")
- log.Infof("cmd %X", cmd)
- if cmd == nil {
- t.Error("failed in PackageCmd")
- }
- srecv := hex.EncodeToString(cmd.([]byte))
- t.Logf("param: [%s]\n", srecv)
- }
- //020068361211
- func TestParse(t *testing.T) {
- dlt645 := LoadProtocol("DLT645-2007")
- v := dlt645.PackageCmd("TotalActivePower", "111236680002")
- log.Infof("%X\n", v)
- cap := []byte{104, 2, 0, 104, 54, 18, 17, 104, 145, 8, 51, 51, 51, 51, 51, 51, 51, 51, 196, 22}
- //104, 17, 18, 54, 104, 0, 2, 104, 147, 6, 53, 51, 155, 105, 69, 68, 33, 22}
- //t1 := []byte{0xfe, 0xfe, 0xfe, 0xfe, 0x68, 0x04, 0x00, 0x42, 0x05, 0x08, 0x21, 0x68, 0x11, 0x04, 0x33, 0x33, 0x33, 0x33, 0x25, 0x16}
- addr_ack := []byte{0x68, 0x08, 0x00, 0x01, 0x04, 0x06, 0x01, 0x68, 0x93, 0x06, 0x3B, 0x33, 0x34, 0x37, 0x39, 0x34, 0xC3, 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}
- devname := ""
- v1 := dlt645.ParsePacket(cap, &devname)
- t.Log(v1)
- vret := dlt645.ParsePacket(tack, &devname)
- if vret == nil {
- t.Error("Error in parse packet")
- }
- mret := dlt645.ParsePacket(addr_ack, &devname)
- t.Log(mret, ",", devname)
- 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)
- }
|