From 06565f2d96424c1c39e1fab90bdb20e9d0a785d9 Mon Sep 17 00:00:00 2001 From: dwibudut Date: Thu, 17 Oct 2024 21:03:30 +0700 Subject: [PATCH] adding missed handler on disconnected client --- ocpp2.0.1/csms.go | 4 ++++ ocpp2.0.1/v2.go | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ocpp2.0.1/csms.go b/ocpp2.0.1/csms.go index 0a54442b..6d7b1684 100644 --- a/ocpp2.0.1/csms.go +++ b/ocpp2.0.1/csms.go @@ -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) }) } diff --git a/ocpp2.0.1/v2.go b/ocpp2.0.1/v2.go index 3f9cb495..338c7eb6 100644 --- a/ocpp2.0.1/v2.go +++ b/ocpp2.0.1/v2.go @@ -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) {