Ocpp: gracefully handle longer meter interval (#19325)
This commit is contained in:
parent
75e0a7dc42
commit
9f1e54d9e9
3 changed files with 8 additions and 5 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue