Ocpp: refactor watchdog
This commit is contained in:
parent
6cca320b9d
commit
e79505e602
2 changed files with 10 additions and 12 deletions
|
|
@ -217,7 +217,7 @@ func NewOCPP(id string, connector int, idtag string, meterValues string, meterIn
|
|||
c.log.DEBUG.Println("enabling meter watchdog")
|
||||
}
|
||||
|
||||
cp.WatchDog(meterInterval)
|
||||
go cp.WatchDog(meterInterval)
|
||||
}
|
||||
|
||||
// TODO deprecate
|
||||
|
|
|
|||
|
|
@ -113,20 +113,18 @@ func (cp *CP) Initialized(timeout time.Duration) bool {
|
|||
}
|
||||
}
|
||||
|
||||
// WatchDog triggers meter values messages if older than timeout.
|
||||
// Must be wrapped in a goroutine.
|
||||
func (cp *CP) WatchDog(timeout time.Duration) {
|
||||
cp.timeout = timeout
|
||||
for ; true; <-time.NewTicker(timeout).C {
|
||||
cp.mu.Lock()
|
||||
update := cp.txnId != 0 && time.Since(cp.meterUpdated) > timeout
|
||||
cp.mu.Unlock()
|
||||
|
||||
go func() {
|
||||
for ; true; <-time.NewTicker(timeout).C {
|
||||
cp.mu.Lock()
|
||||
update := cp.txnId != 0 && time.Since(cp.meterUpdated) > timeout
|
||||
cp.mu.Unlock()
|
||||
|
||||
if update {
|
||||
Instance().TriggerMessageRequest(cp.ID(), core.MeterValuesFeatureName)
|
||||
}
|
||||
if update {
|
||||
Instance().TriggerMessageRequest(cp.ID(), core.MeterValuesFeatureName)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
// TransactionID returns the current transaction id
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue