package protocol

type PacketContext struct {
	ReceiveAddress []byte
	Id             string
	ReportPower    bool
	VICount        int
	ReportVI       bool
	IsReg          bool
	VIData         VIData
}

// SetReceiveAddress 设置接收表地址
func (a *PacketContext) SetReceiveAddress(address []byte) {
	a.ReceiveAddress = address
}

// GetReceiveAddress 获取接收表地址
func (a *PacketContext) GetReceiveAddress() []byte {
	if a.ReceiveAddress != nil {
		return a.ReceiveAddress
	}
	return nil
}

// SetId 设置表号
func (a *PacketContext) SetId(id string) {
	a.Id = id
}

// GetId 获取表号
func (a *PacketContext) GetId() string {
	return a.Id
}

// SetReportPower 是否上报
func (a *PacketContext) SetReportPower(report bool) {
	a.ReportPower = report
}

// GetReportPower 获取是否上报
func (a *PacketContext) GetReportPower() bool {
	return a.ReportPower
}

// SetReportPower 设置电压电流收集数量
func (a *PacketContext) SetViCount() {
	c := a.VICount
	if c < 4 {
		a.VICount += 1
		return
	}
	if c == 4 {
		a.VICount = 0
		a.SetReportVI(true)
	}
}

// GetViCount 获取电压电流收集数量
func (a *PacketContext) GetViCount() int {
	return a.VICount
}

// SetReportPower 是否上报电流电压数据
func (a *PacketContext) SetReportVI(report bool) {
	a.ReportVI = report
}

// GetReportPower 获取是否上报电流电压数据
func (a *PacketContext) GetReportVI() bool {
	return a.ReportVI
}

// SetIsReg 设置是否注册
func (a *PacketContext) SetIsReg(isReg bool) {
	a.IsReg = isReg
}

// GetIsReg 获取是否注册
func (a *PacketContext) GetIsReg() bool {
	return a.IsReg
}

// SetAV
func (a *PacketContext) SetAV(value float64) {
	a.VIData.AV = value
}

// SetAI
func (a *PacketContext) SetAI(value float64) {
	a.VIData.AI = value
}

// SetBV
func (a *PacketContext) SetBV(value float64) {
	a.VIData.BV = value
}

// SetBI
func (a *PacketContext) SetBI(value float64) {
	a.VIData.BI = value
}

// SetCV
func (a *PacketContext) SetCV(value float64) {
	a.VIData.CV = value
}

// SetIsReg
func (a *PacketContext) SetCI(value float64) {
	a.VIData.CI = value
}

// GetVIData
func (a *PacketContext) GetVIData() VIData {
	return a.VIData
}
