Ocpp: wait for meter values (#15226)

This commit is contained in:
andig 2024-08-04 13:53:51 +02:00 • committed by GitHub
parent 260ebd215a
commit a926456315
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 1 deletions

View file

@ -171,7 +171,7 @@ func NewOCPP(id string, connector int, idtag string,
conn.TriggerMessageRequest(core.BootNotificationFeatureName)
select {
case <-time.After(timeout):
c.log.DEBUG.Printf("BootNotification timeout")
c.log.WARN.Printf("boot notification timeout")
case res := <-cp.BootNotificationRequest():
c.bootNotification = res
}
@ -285,6 +285,13 @@ func NewOCPP(id string, connector int, idtag string,
if c.hasMeasurement(types.MeasurandPowerActiveImport) || c.hasMeasurement(types.MeasurandEnergyActiveImportRegister) {
conn.TriggerMessageRequest(core.MeterValuesFeatureName)
// wait for meter values
select {
case <-time.After(timeout):
c.log.WARN.Println("meter value timeout")
case <-c.conn.MeterSampled():
}
if meterInterval > 0 && meterInterval != meterSampleInterval {
if err := c.configure(ocpp.KeyMeterValueSampleInterval, strconv.Itoa(int(meterInterval.Seconds()))); err != nil {
return nil, err

View file

@ -24,6 +24,7 @@ type Connector struct {
status *core.StatusNotificationRequest
statusC chan struct{}
meterC chan map[types.Measurand]types.SampledValue
meterUpdated time.Time
measurements map[types.Measurand]types.SampledValue
@ -42,6 +43,7 @@ func NewConnector(log *util.Logger, id int, cp *CP, timeout time.Duration) (*Con
clock: clock.New(),
statusC: make(chan struct{}),
measurements: make(map[types.Measurand]types.SampledValue),
meterC: make(chan map[types.Measurand]types.SampledValue),
timeout: timeout,
}
@ -54,6 +56,10 @@ func (conn *Connector) TestClock(clock clock.Clock) {
conn.clock = clock
}
func (conn *Connector) MeterSampled() <-chan map[types.Measurand]types.SampledValue {
return conn.meterC
}
func (conn *Connector) ChargePoint() *CP {
return conn.cp
}

View file

@ -71,6 +71,11 @@ func (conn *Connector) MeterValues(request *core.MeterValuesRequest) (*core.Mete
}
}
select {
case conn.meterC <- conn.measurements:
default:
}
return new(core.MeterValuesConfirmation), nil
}