Skip to content

Commit

Permalink
Bender: detect RFID availability (#4418)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Sep 13, 2022
1 parent 6bbfeff commit fd0c4ab
Show file tree
Hide file tree
Showing 2 changed files with 350 additions and 24 deletions.
28 changes: 21 additions & 7 deletions charger/bender.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func NewBenderCCFromConfig(other map[string]interface{}) (api.Charger, error) {
return NewBenderCC(cc.URI, cc.ID)
}

//go:generate go run ../cmd/tools/decorate.go -f decorateBenderCC -b *BenderCC -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterCurrent,Currents,func() (float64, float64, float64, error)" -t "api.ChargeRater,ChargedEnergy,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)"
//go:generate go run ../cmd/tools/decorate.go -f decorateBenderCC -b *BenderCC -r api.Charger -t "api.Meter,CurrentPower,func() (float64, error)" -t "api.MeterCurrent,Currents,func() (float64, float64, float64, error)" -t "api.ChargeRater,ChargedEnergy,func() (float64, error)" -t "api.MeterEnergy,TotalEnergy,func() (float64, error)" -t "api.Identifier,Identify,func() (string, error)"

// NewBenderCC creates BenderCC charger
func NewBenderCC(uri string, id uint8) (api.Charger, error) {
Expand All @@ -108,17 +108,33 @@ func NewBenderCC(uri string, id uint8) (api.Charger, error) {
wb.legacy = true
}

var (
currentPower func() (float64, error)
currents func() (float64, float64, float64, error)
chargedEnergy func() (float64, error)
totalEnergy func() (float64, error)
identify func() (string, error)
)

// check presence of metering
reg := uint16(bendRegActivePower)
if wb.legacy {
reg = bendRegPhaseEnergy
}

if b, err := wb.conn.ReadHoldingRegisters(reg, 2); err == nil && binary.BigEndian.Uint32(b) != math.MaxUint32 {
return decorateBenderCC(wb, wb.currentPower, wb.currents, wb.chargedEnergy, wb.totalEnergy), nil
currentPower = wb.currentPower
currents = wb.currents
chargedEnergy = wb.chargedEnergy
totalEnergy = wb.totalEnergy
}

// check rfid
if _, err := wb.identify(); err == nil {
identify = wb.identify
}

return wb, err
return decorateBenderCC(wb, currentPower, currents, chargedEnergy, totalEnergy, identify), nil
}

// Status implements the api.Charger interface
Expand Down Expand Up @@ -277,10 +293,8 @@ func (wb *BenderCC) currents() (float64, float64, float64, error) {
return curr[0], curr[1], curr[2], nil
}

var _ api.Identifier = (*BenderCC)(nil)

// Identify implements the api.Identifier interface
func (wb *BenderCC) Identify() (string, error) {
// identify implements the api.Identifier interface
func (wb *BenderCC) identify() (string, error) {
if !wb.legacy {
var id []byte

Expand Down
Loading

0 comments on commit fd0c4ab

Please sign in to comment.