X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStation.ts;h=feffa05da837ce929da0dce630a6a9f5601f2c87;hb=c56d42f1989acd8c336fb165d5e295245adb37fa;hp=503231279b9e00f781f418113629122d06bc9fc3;hpb=6ed92bc13120d78f84f2182ddbafd3cbcaa37359;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 50323127..feffa05d 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1,6 +1,7 @@ import { BootNotificationResponse, RegistrationStatus } from '../types/ocpp/Responses'; import ChargingStationConfiguration, { ConfigurationKey } from '../types/ChargingStationConfiguration'; -import ChargingStationTemplate, { CurrentOutType, VoltageOut } from '../types/ChargingStationTemplate'; +import ChargingStationTemplate, { CurrentOutType, PowerUnits, VoltageOut } from '../types/ChargingStationTemplate'; +import { ConnectorPhaseRotation, StandardParametersKey, SupportedFeatureProfiles } from '../types/ocpp/Configuration'; import Connectors, { Connector } from '../types/Connectors'; import { PerformanceObserver, performance } from 'perf_hooks'; import Requests, { AvailabilityType, BootNotificationRequest, IncomingRequest, IncomingRequestCommand } from '../types/ocpp/Requests'; @@ -23,7 +24,6 @@ import OCPPIncomingRequestService from './ocpp/OCPPIncomingRequestService'; import OCPPRequestService from './ocpp/OCPPRequestService'; import { OCPPVersion } from '../types/ocpp/OCPPVersion'; import PerformanceStatistics from '../utils/PerformanceStatistics'; -import { StandardParametersKey } from '../types/ocpp/Configuration'; import { StopTransactionReason } from '../types/ocpp/Transaction'; import Utils from '../utils/Utils'; import { WebSocketCloseEventStatusCode } from '../types/WebSocket'; @@ -161,6 +161,10 @@ export default class ChargingStation { return this.stationInfo.meteringPerTransaction ?? true; } + public getTransactionDataMeterValues(): boolean { + return this.stationInfo.transactionDataMeterValues ?? false; + } + public getEnergyActiveImportRegisterByTransactionId(transactionId: number): number | undefined { if (this.getMeteringPerTransaction()) { for (const connector in this.connectors) { @@ -349,6 +353,7 @@ export default class ChargingStation { delete this.getConnector(connectorId).transactionId; delete this.getConnector(connectorId).idTag; this.getConnector(connectorId).transactionEnergyActiveImportRegisterValue = 0; + delete this.getConnector(connectorId).transactionBeginMeterValue; this.stopMeterValues(connectorId); } @@ -395,13 +400,21 @@ export default class ChargingStation { } catch (error) { FileUtils.handleFileException(this.logPrefix(), 'Template', this.stationTemplateFile, error); } - const stationInfo: ChargingStationInfo = stationTemplateFromFile || {} as ChargingStationInfo; + const stationInfo: ChargingStationInfo = stationTemplateFromFile ?? {} as ChargingStationInfo; if (!Utils.isEmptyArray(stationTemplateFromFile.power)) { stationTemplateFromFile.power = stationTemplateFromFile.power as number[]; - stationInfo.maxPower = stationTemplateFromFile.power[Math.floor(Math.random() * stationTemplateFromFile.power.length)]; + const powerArrayRandomIndex = Math.floor(Math.random() * stationTemplateFromFile.power.length); + stationInfo.maxPower = stationTemplateFromFile.powerUnit === PowerUnits.KILO_WATT + ? stationTemplateFromFile.power[powerArrayRandomIndex] * 1000 + : stationTemplateFromFile.power[powerArrayRandomIndex]; } else { - stationInfo.maxPower = stationTemplateFromFile.power as number; + stationTemplateFromFile.power = stationTemplateFromFile.power as number; + stationInfo.maxPower = stationTemplateFromFile.powerUnit === PowerUnits.KILO_WATT + ? stationTemplateFromFile.power * 1000 + : stationTemplateFromFile.power; } + delete stationInfo.power; + delete stationInfo.powerUnit; stationInfo.chargingStationId = this.getChargingStationId(stationTemplateFromFile); stationInfo.resetTime = stationTemplateFromFile.resetTime ? stationTemplateFromFile.resetTime * 1000 : Constants.CHARGING_STATION_DEFAULT_RESET_TIME; return stationInfo; @@ -494,6 +507,26 @@ export default class ChargingStation { if (!this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData)) { this.addConfigurationKey(StandardParametersKey.MeterValuesSampledData, MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER); } + if (!this.getConfigurationKey(StandardParametersKey.SupportedFeatureProfiles)) { + this.addConfigurationKey(StandardParametersKey.SupportedFeatureProfiles, SupportedFeatureProfiles.Core); + } + if (!this.getConfigurationKey(StandardParametersKey.ConnectorPhaseRotation)) { + const connectorPhaseRotation = []; + for (const connector in this.connectors) { + // AC/DC + if (Utils.convertToInt(connector) === 0 && this.getNumberOfPhases() === 0) { + connectorPhaseRotation.push(`${connector}.${ConnectorPhaseRotation.RST}`); + } else if (Utils.convertToInt(connector) > 0 && this.getNumberOfPhases() === 0) { + connectorPhaseRotation.push(`${connector}.${ConnectorPhaseRotation.NotApplicable}`); + // AC + } else if (Utils.convertToInt(connector) > 0 && this.getNumberOfPhases() === 1) { + connectorPhaseRotation.push(`${connector}.${ConnectorPhaseRotation.NotApplicable}`); + } else if (Utils.convertToInt(connector) > 0 && this.getNumberOfPhases() === 3) { + connectorPhaseRotation.push(`${connector}.${ConnectorPhaseRotation.RST}`); + } + } + this.addConfigurationKey(StandardParametersKey.ConnectorPhaseRotation, connectorPhaseRotation.toString()); + } this.stationInfo.powerDivider = this.getPowerDivider(); if (this.getEnableStatistics()) { this.performanceStatistics = new PerformanceStatistics(this.stationInfo.chargingStationId); @@ -555,7 +588,6 @@ export default class ChargingStation { try { // Parse the message [messageType, messageId, commandName, commandPayload, errorDetails] = JSON.parse(messageEvent.toString()) as IncomingRequest; - // Check the Type of message switch (messageType) { // Incoming Message @@ -877,7 +909,7 @@ export default class ChargingStation { const authorizationFile = this.getAuthorizationFile(); if (authorizationFile) { try { - fs.watch(authorizationFile).on('change', (e) => { + fs.watch(authorizationFile).on('change', () => { try { logger.debug(this.logPrefix() + ' Authorization file ' + authorizationFile + ' have changed, reload'); // Initialize authorizedTags @@ -896,8 +928,8 @@ export default class ChargingStation { private startStationTemplateFileMonitoring(): void { try { - // eslint-disable-next-line @typescript-eslint/no-misused-promises - fs.watch(this.stationTemplateFile).on('change', async (e): Promise => { + // eslint-disable-next-line @typescript-eslint/no-misused-promises + fs.watch(this.stationTemplateFile).on('change', async (): Promise => { try { logger.debug(this.logPrefix() + ' Template file ' + this.stationTemplateFile + ' have changed, reload'); // Initialize