Skip to content

Commit

Permalink
adding missed handler on disconnected client
Browse files Browse the repository at this point in the history
  • Loading branch information
dwibudut authored and lorenzodonini committed Oct 20, 2024
1 parent 9f716f9 commit 06565f2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ocpp2.0.1/csms.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,10 @@ func (cs *csms) SetNewChargingStationHandler(handler ChargingStationConnectionHa

func (cs *csms) SetChargingStationDisconnectedHandler(handler ChargingStationConnectionHandler) {
cs.server.SetDisconnectedClientHandler(func(chargingStation ws.Channel) {
for cb, ok := cs.callbackQueue.Dequeue(chargingStation.ID()); ok; cb, ok = cs.callbackQueue.Dequeue(chargingStation.ID()) {
err := ocpp.NewError(ocppj.GenericError, "client disconnected, no response received from client", "")
cb(nil, err)
}
handler(chargingStation)
})
}
Expand Down
20 changes: 18 additions & 2 deletions ocpp2.0.1/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,24 @@ func NewCSMS(endpoint *ocppj.Server, server ws.WsServer) CSMS {
}
server.AddSupportedSubprotocol(types.V201Subprotocol)
if endpoint == nil {
dispatcher := ocppj.NewDefaultServerDispatcher(ocppj.NewFIFOQueueMap(0))
endpoint = ocppj.NewServer(server, dispatcher, nil, authorization.Profile, availability.Profile, data.Profile, diagnostics.Profile, display.Profile, firmware.Profile, iso15118.Profile, localauth.Profile, meter.Profile, provisioning.Profile, remotecontrol.Profile, reservation.Profile, security.Profile, smartcharging.Profile, tariffcost.Profile, transactions.Profile)
endpoint = ocppj.NewServer(server, nil, nil,
authorization.Profile,
availability.Profile,
data.Profile,
diagnostics.Profile,
display.Profile,
firmware.Profile,
iso15118.Profile,
localauth.Profile,
meter.Profile,
provisioning.Profile,
remotecontrol.Profile,
reservation.Profile,
security.Profile,
smartcharging.Profile,
tariffcost.Profile,
transactions.Profile,
)
}
cs := newCSMS(endpoint)
cs.server.SetRequestHandler(func(client ws.Channel, request ocpp.Request, requestId string, action string) {
Expand Down

0 comments on commit 06565f2

Please sign in to comment.