package protocol import ( "encoding/hex" "github.com/gogf/gf/os/glog" ) type Dlt_0x93 struct { //接收表号 DeviceAddress []byte //表号 DeviceID string //当前视在功率 ApparentPower float64 } func (entity *Dlt_0x93) MsgID() MsgID { return ReadAddress } //func (entity *Dlt_0x93) GetDeviceAddress() DeviceAddress { // return entity.DeviceAddress //} func (entity *Dlt_0x93) Encode() ([]byte, error) { writer := NewWriter() // 接收符号 writer.Write([]byte{0x68, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0x68, 0x13, 0x00, 0xDF, 0x16}) return writer.Bytes(), nil } func (entity *Dlt_0x93) Decode(data []byte) (int, error) { entity.DeviceAddress = data[1:7] bytea := data[1:7] for i, j := 0, len(bytea)-1; i < j; i, j = i+1, j-1 { bytea[i], bytea[j] = bytea[j], bytea[i] } entity.DeviceID = hex.EncodeToString(bytea) glog.Debugf("表地址接收成功:表号:%s", entity.DeviceID) return len(data), nil }