package protocol import ( "encoding/hex" "fmt" "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(ctx *PacketContext) ([]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(ctx *PacketContext, data []byte) (result string, err error) { entity.DeviceAddress = data[1:7] ctx.SetReceiveAddress(data[1:7]) glog.Debugf("11111111----------DeviceAddress:%2X", ctx.GetReceiveAddress()) 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) ctx.SetId(entity.DeviceID) glog.Debugf("2222222----------DeviceAddress:%2X", ctx.GetReceiveAddress()) glog.Debugf("表地址接收成功:表号:%s", entity.DeviceID) result = fmt.Sprintf("%s:%s", "表号", entity.DeviceID) glog.Debugf("DeviceAddress:%2X,Id:%s,", ctx.GetReceiveAddress(), ctx.GetId()) return result, nil }