UI services: fix broadcast channel reponse handler with one hashId only
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 3 Sep 2022 19:13:31 +0000 (21:13 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 3 Sep 2022 19:13:31 +0000 (21:13 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/AutomaticTransactionGenerator.ts
src/charging-station/ChargingStation.ts
src/charging-station/UIServiceWorkerBroadcastChannel.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
src/charging-station/ui-server/UIHttpServer.ts
src/charging-station/ui-server/UIWebSocketServer.ts
src/types/AutomaticTransactionGenerator.ts
src/ui/web/src/types/ChargingStationType.ts

index e8a4b50f1a1b19a9c72c44d0d0f7117beec6a9e7..eb7876e2b34d16a8efa91bccc72be25dfade3fef 100644 (file)
@@ -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(
index c42ff2b9625b126cdfccf0ce9f5df145315d644d..a42135766f3b8b4f66d5c375cb6d773659784b37 100644 (file)
@@ -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
index a2b209220ae084ba84e1fa7accda1e782443929b..e7615e611e30f3b7f895bb06caf14dff79fe0645 100644 (file)
@@ -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);
index c9f491780eda37975e055194705e3b768aff42d7..3129c993ecb7abdadfbcad09a88a9b4cacd9b376 100644 (file)
@@ -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() +
index 152529373d375f033985f571989ed8e31cc63dba..2747738a65d1aadff3b59d654d51570bb0b8a1c1 100644 (file)
@@ -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') {
index c4829dcc29d9362d024fde7644c2df8355405218..32f5262207873aaa62b71682ab92ac46d6fb316a 100644 (file)
@@ -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) => {
index 562996f096014a0c970f02bc6688e3a8ff7435be..de26ce62bdc2d4770641715a951051f0fbc9209e 100644 (file)
@@ -23,6 +23,8 @@ export type Status = {
   acceptedStartTransactionRequests?: number;
   rejectedStartTransactionRequests?: number;
   stopTransactionRequests?: number;
+  acceptedStopTransactionRequests?: number;
+  rejectedStopTransactionRequests?: number;
   skippedConsecutiveTransactions?: number;
   skippedTransactions?: number;
 };
index c8ac081af4aaed988e77870c85227d575045de6b..dfa02403a72d365038eac1f9b5fd88a28e863d70 100644 (file)
@@ -202,6 +202,8 @@ export type Status = {
   acceptedStartTransactionRequests?: number;
   rejectedStartTransactionRequests?: number;
   stopTransactionRequests?: number;
+  acceptedStopTransactionRequests?: number;
+  rejectedStopTransactionRequests?: number;
   skippedConsecutiveTransactions?: number;
   skippedTransactions?: number;
 };