Ocpp: fix connection handling (#15669)
Some checks failed
Release / call-build-workflow (push) Has been cancelled
Release / Publish Docker :release (push) Has been cancelled
Release / Github & APT (push) Has been cancelled
Release / Demo (push) Has been cancelled
Release / Hassio Addon (push) Has been cancelled

This commit is contained in:
andig 2024-08-25 12:59:31 +02:00 • committed by GitHub
parent d03705e1a6
commit b49f783334
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 16 deletions

View file

@ -12,14 +12,17 @@ import (
// Since ocpp-go interfaces at charge point level, we need to manage multiple connector separately
type CP struct {
mu sync.RWMutex
log *util.Logger
mu sync.RWMutex
log *util.Logger
onceConnect sync.Once
onceBoot sync.Once
bootNotificationRequestC chan *core.BootNotificationRequest
id string
connected bool
connectC chan struct{}
bootNotificationRequestC chan *core.BootNotificationRequest
connected bool
connectC chan struct{}
connectors map[int]*Connector
}
@ -29,10 +32,10 @@ func NewChargePoint(log *util.Logger, id string) *CP {
log: log,
id: id,
connectC: make(chan struct{}, 1),
bootNotificationRequestC: make(chan *core.BootNotificationRequest, 1),
connectC: make(chan struct{}),
connectors: make(map[int]*Connector),
bootNotificationRequestC: make(chan *core.BootNotificationRequest, 1),
}
}
@ -97,10 +100,9 @@ func (cp *CP) connect(connect bool) {
cp.connected = connect
if connect {
select {
case cp.connectC <- struct{}{}:
default:
}
cp.onceConnect.Do(func() {
close(cp.connectC)
})
}
}

View file

@ -38,10 +38,9 @@ func (cp *CP) BootNotification(request *core.BootNotificationRequest) (*core.Boo
Status: core.RegistrationStatusAccepted,
}
select {
case cp.bootNotificationRequestC <- request:
default:
}
cp.onceBoot.Do(func() {
cp.bootNotificationRequestC <- request
})
return res, nil
}