Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
premultiply committed Sep 5, 2024
1 parent 506f2fd commit 330c901
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
9 changes: 3 additions & 6 deletions charger/ocpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/smartcharging"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/types"
"github.com/samber/lo"
)

// OCPP charger implementation
Expand Down Expand Up @@ -157,12 +158,8 @@ func NewOCPP(id string, connector int, idtag string,
return nil, fmt.Errorf("invalid connector: %d", connector)
}

if remoteStart && idtag == "" {
idtag = cp.IdTag

if idtag == "" {
idtag = defaultIdTag
}
if remoteStart {
idtag = lo.CoalesceOrEmpty(idtag, cp.IdTag, defaultIdTag)

This comment has been minimized.

Copy link
@andig

andig Sep 5, 2024

Member

Letzter Kommentar: man könnte es else empty setzen. Aber passt.

}

conn, err := ocpp.NewConnector(log, connector, cp, idtag, timeout)
Expand Down
4 changes: 2 additions & 2 deletions charger/ocpp/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ func (conn *Connector) TriggerMessageRequest(feature remotetrigger.MessageTrigge
})
}

func (conn *Connector) remoteStartTransactionRequest(idtag string) {
func (conn *Connector) remoteStartTransactionRequest() {
rc := make(chan error, 1)
err := Instance().RemoteStartTransaction(conn.cp.ID(), func(resp *core.RemoteStartTransactionConfirmation, err error) {
if err == nil && resp != nil && resp.Status != types.RemoteStartStopStatusAccepted {
err = errors.New(string(resp.Status))
}

rc <- err
}, idtag, func(request *core.RemoteStartTransactionRequest) {
}, conn.remoteIdTag, func(request *core.RemoteStartTransactionRequest) {
connector := conn.id
request.ConnectorId = &connector
})
Expand Down
2 changes: 1 addition & 1 deletion charger/ocpp/connector_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (conn *Connector) StatusNotification(request *core.StatusNotificationReques

if conn.isWaitingForAuth() {
if conn.remoteIdTag != "" {
defer conn.remoteStartTransactionRequest(conn.remoteIdTag)
defer conn.remoteStartTransactionRequest()

This comment has been minimized.

Copy link
@andig

andig Sep 5, 2024

Member

Hast Du mal probiert, ob es das defer hier wirklich braucht? Eigentlich sollte das auch ohne gehen da der CP den Status ja schon hat.

This comment has been minimized.

Copy link
@premultiply

premultiply Sep 5, 2024

Author Member

Ja, habe ich.
Ohne defer wird die Bestätigung der StatusNotification durch das CS so lange blockiert bis der CP die RemoteStartTransaction seinerseits bestätigt hat während er noch immer auf die Bestätigung der zuvor geschickten StatusNotification wartet. Deadlock-Risiko.

This comment has been minimized.

Copy link
@andig

andig Sep 5, 2024

Member

Bäh, ok. Das ist doof.

} else {
conn.log.DEBUG.Printf("waiting for local authentication")
}
Expand Down

0 comments on commit 330c901

Please sign in to comment.