Skip to content

Commit

Permalink
Ocpp: fix connection handling (#15669)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig authored Aug 25, 2024
1 parent d03705e commit b49f783
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
26 changes: 14 additions & 12 deletions charger/ocpp/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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),
}
}

Expand Down Expand Up @@ -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)
})
}
}

Expand Down
7 changes: 3 additions & 4 deletions charger/ocpp/cp_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit b49f783

Please sign in to comment.