Ocpp: gracefully handle longer meter interval (#19325)

This commit is contained in:
andig 2025-03-02 11:26:25 +01:00 • committed by GitHub
parent 75e0a7dc42
commit 9f1e54d9e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 5 deletions

View file

@ -181,7 +181,7 @@ func NewOCPP(ctx context.Context,
idTag = lo.CoalesceOrEmpty(idTag, cp.IdTag, defaultIdTag)
}
conn, err := ocpp.NewConnector(log, connector, cp, idTag)
conn, err := ocpp.NewConnector(log, connector, cp, idTag, meterInterval)
if err != nil {
return nil, err
}

View file

@ -32,9 +32,11 @@ type Connector struct {
idTag string
remoteIdTag string
meterInterval time.Duration
}
func NewConnector(log *util.Logger, id int, cp *CP, idTag string) (*Connector, error) {
func NewConnector(log *util.Logger, id int, cp *CP, idTag string, meterInterval time.Duration) (*Connector, error) {
conn := &Connector{
log: log,
cp: cp,
@ -43,7 +45,8 @@ func NewConnector(log *util.Logger, id int, cp *CP, idTag string) (*Connector, e
statusC: make(chan struct{}, 1),
measurements: make(map[types.Measurand]types.SampledValue),
remoteIdTag: idTag,
remoteIdTag: idTag,
meterInterval: meterInterval,
}
if err := cp.registerConnector(id, conn); err != nil {
@ -191,7 +194,7 @@ func (conn *Connector) isWaitingForAuth() bool {
// isMeterTimeout checks if meter values are outdated.
// Must only be called while holding lock.
func (conn *Connector) isMeterTimeout() bool {
return conn.clock.Since(conn.meterUpdated) > Timeout
return conn.clock.Since(conn.meterUpdated) > max(conn.meterInterval+10*time.Second, Timeout)
}
var _ api.CurrentGetter = (*Connector)(nil)

View file

@ -26,7 +26,7 @@ func (suite *connTestSuite) SetupTest() {
// setup instance
Instance()
suite.cp = NewChargePoint(util.NewLogger("foo"), "abc")
suite.conn, _ = NewConnector(util.NewLogger("foo"), 1, suite.cp, "")
suite.conn, _ = NewConnector(util.NewLogger("foo"), 1, suite.cp, "", Timeout)
suite.clock = clock.NewMock()
suite.conn.clock = suite.clock