From: Jérôme Benoit Date: Fri, 28 Apr 2023 17:35:20 +0000 (+0200) Subject: feat: support evses in more code path X-Git-Tag: v1.2.12~48 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=4334db724447c1a0f989cd467dc44e136a7478eb;p=e-mobility-charging-stations-simulator.git feat: support evses in more code path Reference: https://github.com/SAP/e-mobility-charging-stations-simulator/issues/349 Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index fb79ae25..d928a623 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -132,17 +132,37 @@ export class AutomaticTransactionGenerator extends AsyncResource { this.connectorsStatus.clear(); this.initializeConnectorsStatus(); } - for (const connectorId of this.chargingStation.connectors.keys()) { - if (connectorId > 0) { - this.startConnector(connectorId); + if (this.chargingStation.hasEvses) { + for (const [evseId, evseStatus] of this.chargingStation.evses) { + if (evseId > 0) { + for (const connectorId of evseStatus.connectors.keys()) { + this.startConnector(connectorId); + } + } + } + } else { + for (const connectorId of this.chargingStation.connectors.keys()) { + if (connectorId > 0) { + this.startConnector(connectorId); + } } } } private stopConnectors(): void { - for (const connectorId of this.chargingStation.connectors.keys()) { - if (connectorId > 0) { - this.stopConnector(connectorId); + if (this.chargingStation.hasEvses) { + for (const [evseId, evseStatus] of this.chargingStation.evses) { + if (evseId > 0) { + for (const connectorId of evseStatus.connectors.keys()) { + this.stopConnector(connectorId); + } + } + } + } else { + for (const connectorId of this.chargingStation.connectors.keys()) { + if (connectorId > 0) { + this.stopConnector(connectorId); + } } } } @@ -295,22 +315,45 @@ export class AutomaticTransactionGenerator extends AsyncResource { } private initializeConnectorsStatus(): void { - for (const connectorId of this.chargingStation.connectors.keys()) { - if (connectorId > 0) { - this.connectorsStatus.set(connectorId, { - start: false, - authorizeRequests: 0, - acceptedAuthorizeRequests: 0, - rejectedAuthorizeRequests: 0, - startTransactionRequests: 0, - acceptedStartTransactionRequests: 0, - rejectedStartTransactionRequests: 0, - stopTransactionRequests: 0, - acceptedStopTransactionRequests: 0, - rejectedStopTransactionRequests: 0, - skippedConsecutiveTransactions: 0, - skippedTransactions: 0, - }); + if (this.chargingStation.hasEvses) { + for (const [evseId, evseStatus] of this.chargingStation.evses) { + if (evseId > 0) { + for (const connectorId of evseStatus.connectors.keys()) { + this.connectorsStatus.set(connectorId, { + start: false, + authorizeRequests: 0, + acceptedAuthorizeRequests: 0, + rejectedAuthorizeRequests: 0, + startTransactionRequests: 0, + acceptedStartTransactionRequests: 0, + rejectedStartTransactionRequests: 0, + stopTransactionRequests: 0, + acceptedStopTransactionRequests: 0, + rejectedStopTransactionRequests: 0, + skippedConsecutiveTransactions: 0, + skippedTransactions: 0, + }); + } + } + } + } else { + for (const connectorId of this.chargingStation.connectors.keys()) { + if (connectorId > 0) { + this.connectorsStatus.set(connectorId, { + start: false, + authorizeRequests: 0, + acceptedAuthorizeRequests: 0, + rejectedAuthorizeRequests: 0, + startTransactionRequests: 0, + acceptedStartTransactionRequests: 0, + rejectedStartTransactionRequests: 0, + stopTransactionRequests: 0, + acceptedStopTransactionRequests: 0, + rejectedStopTransactionRequests: 0, + skippedConsecutiveTransactions: 0, + skippedTransactions: 0, + }); + } } } } diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index b28c520b..9cd20129 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -267,10 +267,9 @@ export class ChargingStation { if (this.hasEvses) { let numberOfConnectors = 0; for (const [evseId, evseStatus] of this.evses) { - if (evseId === 0) { - continue; + if (evseId > 0) { + numberOfConnectors += evseStatus.connectors.size; } - numberOfConnectors += evseStatus.connectors.size; } return numberOfConnectors; } @@ -1994,30 +1993,32 @@ export class ChargingStation { // Initialize connectors status if (this.hasEvses) { for (const [evseId, evseStatus] of this.evses) { - if (evseId === 0) { - continue; + if (evseId > 0) { + for (const [connectorId, connectorStatus] of evseStatus.connectors) { + const connectorBootStatus = ChargingStationUtils.getBootConnectorStatus( + this, + connectorId, + connectorStatus + ); + await OCPPServiceUtils.sendAndSetConnectorStatus( + this, + connectorId, + connectorBootStatus + ); + } } - for (const [connectorId, connectorStatus] of evseStatus.connectors) { + } + } else { + for (const connectorId of this.connectors.keys()) { + if (connectorId > 0) { const connectorBootStatus = ChargingStationUtils.getBootConnectorStatus( this, connectorId, - connectorStatus + this.getConnectorStatus(connectorId) ); await OCPPServiceUtils.sendAndSetConnectorStatus(this, connectorId, connectorBootStatus); } } - } else { - for (const connectorId of this.connectors.keys()) { - if (connectorId === 0) { - continue; - } - const connectorBootStatus = ChargingStationUtils.getBootConnectorStatus( - this, - connectorId, - this.getConnectorStatus(connectorId) - ); - await OCPPServiceUtils.sendAndSetConnectorStatus(this, connectorId, connectorBootStatus); - } } if (this.stationInfo?.firmwareStatus === FirmwareStatus.Installing) { await this.ocppRequestService.requestHandler< diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 3cb96e19..f715adc3 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -21,6 +21,7 @@ import { type ChangeConfigurationResponse, type ClearChargingProfileRequest, type ClearChargingProfileResponse, + type ConnectorStatus, ErrorType, type GenericResponse, GenericStatus, @@ -655,12 +656,13 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { ); return OCPP16Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN; } - const connectorStatus = chargingStation.getConnectorStatus(commandPayload.connectorId); if ( !Utils.isNullOrUndefined(commandPayload.connectorId) && - Utils.isNotEmptyArray(connectorStatus?.chargingProfiles) + Utils.isNotEmptyArray( + chargingStation.getConnectorStatus(commandPayload.connectorId)?.chargingProfiles + ) ) { - connectorStatus.chargingProfiles = []; + chargingStation.getConnectorStatus(commandPayload.connectorId).chargingProfiles = []; logger.debug( `${chargingStation.logPrefix()} Charging profile(s) cleared on connector id ${ commandPayload.connectorId @@ -670,13 +672,10 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { } if (Utils.isNullOrUndefined(commandPayload.connectorId)) { let clearedCP = false; - for (const connectorId of chargingStation.connectors.keys()) { - if ( - Utils.isNotEmptyArray(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles) - ) { - chargingStation - .getConnectorStatus(connectorId) - ?.chargingProfiles?.forEach((chargingProfile: OCPP16ChargingProfile, index: number) => { + const clearChargingProfiles = (connectorStatus: ConnectorStatus) => { + if (Utils.isNotEmptyArray(connectorStatus?.chargingProfiles)) { + connectorStatus?.chargingProfiles?.forEach( + (chargingProfile: OCPP16ChargingProfile, index: number) => { let clearCurrentCP = false; if (chargingProfile.chargingProfileId === commandPayload.id) { clearCurrentCP = true; @@ -707,7 +706,19 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { ); clearedCP = true; } - }); + } + ); + } + }; + if (chargingStation.hasEvses) { + for (const evseStatus of chargingStation.evses.values()) { + for (const connectorStatus of evseStatus.connectors.values()) { + clearChargingProfiles(connectorStatus); + } + } + } else { + for (const connectorId of chargingStation.connectors.keys()) { + clearChargingProfiles(chargingStation.getConnectorStatus(connectorId)); } } if (clearedCP) {