X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStation.ts;h=bbe294b62ca07c7ed53292871829bd5dd9ee244d;hb=cf058664a0053a43b9ac08815b6e430179ff5ddf;hp=c42ff2b9625b126cdfccf0ce9f5df145315d644d;hpb=5e3cb7281de2b6fa8b61a453f964c2f213fefa80;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index c42ff2b9..bbe294b6 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); } @@ -498,7 +498,7 @@ export default class ChargingStation { this.initialize(); // Restart the ATG this.stopAutomaticTransactionGenerator(); - if (this.getAutomaticTransactionGeneratorConfigurationFromTemplate()?.enable) { + if (this.getAutomaticTransactionGeneratorConfigurationFromTemplate()?.enable === true) { this.startAutomaticTransactionGenerator(); } if (this.getEnableStatistics()) { @@ -519,7 +519,8 @@ export default class ChargingStation { parentPort.postMessage(MessageChannelUtils.buildStartedMessage(this)); } - public async stop(): Promise { + public async stop(reason?: StopTransactionReason): Promise { + await this.stopMessageSequence(reason); for (const connectorId of this.connectors.keys()) { if (connectorId > 0) { await this.ocppRequestService.requestHandler< @@ -545,8 +546,8 @@ export default class ChargingStation { parentPort.postMessage(MessageChannelUtils.buildStoppedMessage(this)); } - public async reset(): Promise { - await this.stop(); + public async reset(reason?: StopTransactionReason): Promise { + await this.stop(reason); await Utils.sleep(this.stationInfo.resetTime); this.initialize(); this.start(); @@ -558,57 +559,6 @@ export default class ChargingStation { } } - public getChargingProfilePowerLimit(connectorId: number): number | undefined { - let limit: number, matchingChargingProfile: ChargingProfile; - let chargingProfiles: ChargingProfile[] = []; - // Get charging profiles for connector and sort by stack level - chargingProfiles = this.getConnectorStatus(connectorId).chargingProfiles.sort( - (a, b) => b.stackLevel - a.stackLevel - ); - // Get profiles on connector 0 - if (this.getConnectorStatus(0).chargingProfiles) { - chargingProfiles.push( - ...this.getConnectorStatus(0).chargingProfiles.sort((a, b) => b.stackLevel - a.stackLevel) - ); - } - if (!Utils.isEmptyArray(chargingProfiles)) { - const result = ChargingStationUtils.getLimitFromChargingProfiles( - chargingProfiles, - this.logPrefix() - ); - if (!Utils.isNullOrUndefined(result)) { - limit = result.limit; - matchingChargingProfile = result.matchingChargingProfile; - switch (this.getCurrentOutType()) { - case CurrentType.AC: - limit = - matchingChargingProfile.chargingSchedule.chargingRateUnit === - ChargingRateUnitType.WATT - ? limit - : ACElectricUtils.powerTotal(this.getNumberOfPhases(), this.getVoltageOut(), limit); - break; - case CurrentType.DC: - limit = - matchingChargingProfile.chargingSchedule.chargingRateUnit === - ChargingRateUnitType.WATT - ? limit - : DCElectricUtils.power(this.getVoltageOut(), limit); - } - const connectorMaximumPower = this.getMaximumPower() / this.powerDivider; - if (limit > connectorMaximumPower) { - logger.error( - `${this.logPrefix()} Charging profile id ${ - matchingChargingProfile.chargingProfileId - } limit is greater than connector id ${connectorId} maximum, dump charging profiles' stack: %j`, - this.getConnectorStatus(connectorId).chargingProfiles - ); - limit = connectorMaximumPower; - } - } - } - return limit; - } - public setChargingProfile(connectorId: number, cp: ChargingProfile): void { if (Utils.isNullOrUndefined(this.getConnectorStatus(connectorId).chargingProfiles)) { logger.error( @@ -652,6 +602,7 @@ export default class ChargingStation { this.getConnectorStatus(connectorId).transactionEnergyActiveImportRegisterValue = 0; delete this.getConnectorStatus(connectorId).transactionBeginMeterValue; this.stopMeterValues(connectorId); + parentPort.postMessage(MessageChannelUtils.buildUpdatedMessage(this)); } public hasFeatureProfile(featureProfile: SupportedFeatureProfiles) { @@ -767,24 +718,6 @@ export default class ChargingStation { } } - public getNumberOfRunningTransactions(): number { - let trxCount = 0; - for (const connectorId of this.connectors.keys()) { - if (connectorId > 0 && this.getConnectorStatus(connectorId)?.transactionStarted === true) { - trxCount++; - } - } - return trxCount; - } - - public async stopRunningTransactions(reason = StopTransactionReason.NONE): Promise { - for (const connectorId of this.connectors.keys()) { - if (connectorId > 0 && this.getConnectorStatus(connectorId)?.transactionStarted === true) { - await this.stopTransactionOnConnector(connectorId, reason); - } - } - } - public async stopTransactionOnConnector( connectorId: number, reason = StopTransactionReason.NONE @@ -817,7 +750,6 @@ export default class ChargingStation { { transactionId, meterStop: this.getEnergyActiveImportRegisterByTransactionId(transactionId, true), - idTag: this.getTransactionIdTag(transactionId), reason, } ); @@ -1467,7 +1399,6 @@ export default class ChargingStation { )}' and reason '${reason}'` ); this.autoReconnectRetryCount = 0; - await this.stopMessageSequence(StopTransactionReason.OTHER); break; // Abnormal close default: @@ -1662,6 +1593,24 @@ export default class ChargingStation { : true; } + private getNumberOfRunningTransactions(): number { + let trxCount = 0; + for (const connectorId of this.connectors.keys()) { + if (connectorId > 0 && this.getConnectorStatus(connectorId)?.transactionStarted === true) { + trxCount++; + } + } + return trxCount; + } + + private async stopRunningTransactions(reason = StopTransactionReason.NONE): Promise { + for (const connectorId of this.connectors.keys()) { + if (connectorId > 0 && this.getConnectorStatus(connectorId)?.transactionStarted === true) { + await this.stopTransactionOnConnector(connectorId, reason); + } + } + } + // 0 for disabling private getConnectionTimeout(): number | undefined { if ( @@ -1747,6 +1696,57 @@ export default class ChargingStation { } } + private getChargingProfilePowerLimit(connectorId: number): number | undefined { + let limit: number, matchingChargingProfile: ChargingProfile; + let chargingProfiles: ChargingProfile[] = []; + // Get charging profiles for connector and sort by stack level + chargingProfiles = this.getConnectorStatus(connectorId).chargingProfiles.sort( + (a, b) => b.stackLevel - a.stackLevel + ); + // Get profiles on connector 0 + if (this.getConnectorStatus(0).chargingProfiles) { + chargingProfiles.push( + ...this.getConnectorStatus(0).chargingProfiles.sort((a, b) => b.stackLevel - a.stackLevel) + ); + } + if (!Utils.isEmptyArray(chargingProfiles)) { + const result = ChargingStationUtils.getLimitFromChargingProfiles( + chargingProfiles, + this.logPrefix() + ); + if (!Utils.isNullOrUndefined(result)) { + limit = result.limit; + matchingChargingProfile = result.matchingChargingProfile; + switch (this.getCurrentOutType()) { + case CurrentType.AC: + limit = + matchingChargingProfile.chargingSchedule.chargingRateUnit === + ChargingRateUnitType.WATT + ? limit + : ACElectricUtils.powerTotal(this.getNumberOfPhases(), this.getVoltageOut(), limit); + break; + case CurrentType.DC: + limit = + matchingChargingProfile.chargingSchedule.chargingRateUnit === + ChargingRateUnitType.WATT + ? limit + : DCElectricUtils.power(this.getVoltageOut(), limit); + } + const connectorMaximumPower = this.getMaximumPower() / this.powerDivider; + if (limit > connectorMaximumPower) { + logger.error( + `${this.logPrefix()} Charging profile id ${ + matchingChargingProfile.chargingProfileId + } limit is greater than connector id ${connectorId} maximum, dump charging profiles' stack: %j`, + this.getConnectorStatus(connectorId).chargingProfiles + ); + limit = connectorMaximumPower; + } + } + } + return limit; + } + private async startMessageSequence(): Promise { if (this.stationInfo?.autoRegister) { await this.ocppRequestService.requestHandler< @@ -1833,7 +1833,7 @@ export default class ChargingStation { } } // Start the ATG - if (this.getAutomaticTransactionGeneratorConfigurationFromTemplate()?.enable) { + if (this.getAutomaticTransactionGeneratorConfigurationFromTemplate()?.enable === true) { this.startAutomaticTransactionGenerator(); } } @@ -1846,12 +1846,10 @@ export default class ChargingStation { // Stop heartbeat this.stopHeartbeat(); // Stop ongoing transactions - if (this.getNumberOfRunningTransactions() > 0) { - if (this.automaticTransactionGenerator?.started) { - this.stopAutomaticTransactionGenerator(); - } else { - await this.stopRunningTransactions(reason); - } + if (this.automaticTransactionGenerator?.started === true) { + this.stopAutomaticTransactionGenerator(); + } else { + await this.stopRunningTransactions(reason); } } @@ -1996,7 +1994,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 (