Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't handle incoming requests if ocpp16 client stopped #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion ocpp1.6/charge_point.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ocpp16

import (
"fmt"
"sync"

"github.com/lorenzodonini/ocpp-go/internal/callbackqueue"
"github.com/lorenzodonini/ocpp-go/ocpp"
Expand All @@ -28,6 +29,7 @@ type chargePoint struct {
callbacks callbackqueue.CallbackQueue
stopC chan struct{}
errC chan error // external error channel
incomingWaitGroup sync.WaitGroup
}

func (cp *chargePoint) error(err error) {
Expand Down Expand Up @@ -328,8 +330,9 @@ func (cp *chargePoint) Start(centralSystemUrl string) error {
}

func (cp *chargePoint) Stop() {
cp.client.Stop()
close(cp.stopC)
cp.incomingWaitGroup.Wait()
cp.client.Stop()

if cp.errC != nil {
close(cp.errC)
Expand All @@ -354,6 +357,13 @@ func (cp *chargePoint) notSupportedError(requestId string, action string) {
}

func (cp *chargePoint) handleIncomingRequest(request ocpp.Request, requestId string, action string) {
cp.incomingWaitGroup.Add(1)
defer cp.incomingWaitGroup.Done()
select {
case <-cp.stopC:
return
default:
}
profile, found := cp.client.GetProfileForFeature(action)
// Check whether action is supported and a handler for it exists
if !found {
Expand Down