From 6d9876e7b9b024879f1463aa7407c6874c5ca06b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 3 Sep 2022 21:13:31 +0200 Subject: [PATCH] UI services: fix broadcast channel reponse handler with one hashId only MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../AutomaticTransactionGenerator.ts | 13 +++++++++++-- src/charging-station/ChargingStation.ts | 5 +++-- .../UIServiceWorkerBroadcastChannel.ts | 10 ++++------ .../ocpp/1.6/OCPP16ResponseService.ts | 2 +- src/charging-station/ui-server/UIHttpServer.ts | 2 +- src/charging-station/ui-server/UIWebSocketServer.ts | 2 +- src/types/AutomaticTransactionGenerator.ts | 2 ++ src/ui/web/src/types/ChargingStationType.ts | 2 ++ 8 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index e8a4b50f..eb7876e2 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -226,7 +226,7 @@ export default class AutomaticTransactionGenerator { } this.connectorsStatus.get(connectorId).lastRunDate = new Date(); } - await this.stopTransaction(connectorId); + // await this.stopTransaction(connectorId); this.connectorsStatus.get(connectorId).stoppedDate = new Date(); logger.info( this.logPrefix(connectorId) + @@ -257,6 +257,10 @@ export default class AutomaticTransactionGenerator { this?.connectorsStatus.get(connectorId)?.rejectedStartTransactionRequests ?? 0; this.connectorsStatus.get(connectorId).stopTransactionRequests = this?.connectorsStatus.get(connectorId)?.stopTransactionRequests ?? 0; + this.connectorsStatus.get(connectorId).acceptedStopTransactionRequests = + this?.connectorsStatus.get(connectorId)?.acceptedStopTransactionRequests ?? 0; + this.connectorsStatus.get(connectorId).rejectedStopTransactionRequests = + this?.connectorsStatus.get(connectorId)?.rejectedStopTransactionRequests ?? 0; this.connectorsStatus.get(connectorId).skippedConsecutiveTransactions = 0; this.connectorsStatus.get(connectorId).skippedTransactions = this?.connectorsStatus.get(connectorId)?.skippedTransactions ?? 0; @@ -346,9 +350,14 @@ export default class AutomaticTransactionGenerator { const measureId = 'StopTransaction with ATG'; const beginId = PerformanceStatistics.beginMeasure(measureId); let stopResponse: StopTransactionResponse; - if (this.chargingStation.getConnectorStatus(connectorId)?.transactionStarted) { + if (this.chargingStation.getConnectorStatus(connectorId)?.transactionStarted === true) { stopResponse = await this.chargingStation.stopTransactionOnConnector(connectorId, reason); this.connectorsStatus.get(connectorId).stopTransactionRequests++; + if (stopResponse.idTagInfo?.status === AuthorizationStatus.ACCEPTED) { + this.connectorsStatus.get(connectorId).acceptedStopTransactionRequests++; + } else { + this.connectorsStatus.get(connectorId).rejectedStopTransactionRequests++; + } } else { const transactionId = this.chargingStation.getConnectorStatus(connectorId).transactionId; logger.warn( diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index c42ff2b9..a4213576 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -233,7 +233,7 @@ export default class ChargingStation { return this.connectors.get(0) ? this.connectors.size - 1 : this.connectors.size; } - public getConnectorStatus(id: number): ConnectorStatus { + public getConnectorStatus(id: number): ConnectorStatus | undefined { return this.connectors.get(id); } @@ -1996,7 +1996,7 @@ export default class ChargingStation { // Stop heartbeat this.stopHeartbeat(); // Stop the ATG if needed - if (this.automaticTransactionGenerator?.configuration?.stopOnConnectionFailure) { + if (this.automaticTransactionGenerator?.configuration?.stopOnConnectionFailure === true) { this.stopAutomaticTransactionGenerator(); } if ( @@ -2030,6 +2030,7 @@ export default class ChargingStation { ); this.wsConnectionRestarted = true; } else if (this.getAutoReconnectMaxRetries() !== -1) { + await this.stopMessageSequence(StopTransactionReason.OTHER); logger.error( `${this.logPrefix()} WebSocket reconnect failure: maximum retries reached (${ this.autoReconnectRetryCount diff --git a/src/charging-station/UIServiceWorkerBroadcastChannel.ts b/src/charging-station/UIServiceWorkerBroadcastChannel.ts index a2b20922..e7615e61 100644 --- a/src/charging-station/UIServiceWorkerBroadcastChannel.ts +++ b/src/charging-station/UIServiceWorkerBroadcastChannel.ts @@ -41,16 +41,14 @@ export default class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChan responses: [responsePayload], }); } else if ( - this.responses.get(uuid)?.responsesReceived + 1 < - this.responses.get(uuid)?.responsesExpected + this.responses.get(uuid)?.responsesReceived <= this.responses.get(uuid)?.responsesExpected ) { this.responses.get(uuid).responsesReceived++; this.responses.get(uuid).responses.push(responsePayload); - } else if ( - this.responses.get(uuid)?.responsesReceived + 1 === - this.responses.get(uuid)?.responsesExpected + } + if ( + this.responses.get(uuid)?.responsesReceived === this.responses.get(uuid)?.responsesExpected ) { - this.responses.get(uuid).responses.push(responsePayload); this.uiService.sendResponse(uuid, this.buildResponsePayload(uuid)); this.responses.delete(uuid); this.uiService.deleteBroadcastChannelRequest(uuid); diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index c9f49178..3129c993 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -581,6 +581,7 @@ export default class OCPP16ResponseService extends OCPPResponseService { if (chargingStation.stationInfo.powerSharedByConnectors) { chargingStation.powerDivider--; } + chargingStation.resetConnectorStatus(transactionConnectorId); logger.info( chargingStation.logPrefix() + ' Transaction ' + @@ -590,7 +591,6 @@ export default class OCPP16ResponseService extends OCPPResponseService { '#' + transactionConnectorId.toString() ); - chargingStation.resetConnectorStatus(transactionConnectorId); } else { logger.warn( chargingStation.logPrefix() + diff --git a/src/charging-station/ui-server/UIHttpServer.ts b/src/charging-station/ui-server/UIHttpServer.ts index 15252937..2747738a 100644 --- a/src/charging-station/ui-server/UIHttpServer.ts +++ b/src/charging-station/ui-server/UIHttpServer.ts @@ -91,7 +91,7 @@ export default class UIHttpServer extends AbstractUIServer { error ); }); - if (!this.uiServices.has(version)) { + if (this.uiServices.has(version) === false) { this.uiServices.set(version, UIServiceFactory.getUIServiceImplementation(version, this)); } if (req.method === 'POST') { diff --git a/src/charging-station/ui-server/UIWebSocketServer.ts b/src/charging-station/ui-server/UIWebSocketServer.ts index c4829dcc..32f52622 100644 --- a/src/charging-station/ui-server/UIWebSocketServer.ts +++ b/src/charging-station/ui-server/UIWebSocketServer.ts @@ -33,7 +33,7 @@ export default class UIWebSocketServer extends AbstractUIServer { ); ws.close(WebSocketCloseEventStatusCode.CLOSE_PROTOCOL_ERROR); } - if (!this.uiServices.has(version)) { + if (this.uiServices.has(version) === false) { this.uiServices.set(version, UIServiceFactory.getUIServiceImplementation(version, this)); } ws.on('message', (rawData) => { diff --git a/src/types/AutomaticTransactionGenerator.ts b/src/types/AutomaticTransactionGenerator.ts index 562996f0..de26ce62 100644 --- a/src/types/AutomaticTransactionGenerator.ts +++ b/src/types/AutomaticTransactionGenerator.ts @@ -23,6 +23,8 @@ export type Status = { acceptedStartTransactionRequests?: number; rejectedStartTransactionRequests?: number; stopTransactionRequests?: number; + acceptedStopTransactionRequests?: number; + rejectedStopTransactionRequests?: number; skippedConsecutiveTransactions?: number; skippedTransactions?: number; }; diff --git a/src/ui/web/src/types/ChargingStationType.ts b/src/ui/web/src/types/ChargingStationType.ts index c8ac081a..dfa02403 100644 --- a/src/ui/web/src/types/ChargingStationType.ts +++ b/src/ui/web/src/types/ChargingStationType.ts @@ -202,6 +202,8 @@ export type Status = { acceptedStartTransactionRequests?: number; rejectedStartTransactionRequests?: number; stopTransactionRequests?: number; + acceptedStopTransactionRequests?: number; + rejectedStopTransactionRequests?: number; skippedConsecutiveTransactions?: number; skippedTransactions?: number; }; -- 2.34.1