From: Jérôme Benoit Date: Sun, 27 Jun 2021 13:16:36 +0000 (+0200) Subject: Consistent naming for CS template enums X-Git-Tag: v1.0.25~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=4c2b490420d856ee0602b3806d6508b67643613b;p=e-mobility-charging-stations-simulator.git Consistent naming for CS template enums Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 4c3179f4..30b21bdc 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1,6 +1,6 @@ import { BootNotificationResponse, RegistrationStatus } from '../types/ocpp/Responses'; import ChargingStationConfiguration, { ConfigurationKey } from '../types/ChargingStationConfiguration'; -import ChargingStationTemplate, { CurrentOutType, PowerUnits, VoltageOut } from '../types/ChargingStationTemplate'; +import ChargingStationTemplate, { CurrentType, PowerUnits, Voltage } from '../types/ChargingStationTemplate'; import { ConnectorPhaseRotation, StandardParametersKey, SupportedFeatureProfiles } from '../types/ocpp/Configuration'; import Connectors, { Connector, SampledValueTemplate } from '../types/Connectors'; import { MeterValueMeasurand, MeterValuePhase } from '../types/ocpp/MeterValues'; @@ -93,9 +93,9 @@ export default class ChargingStation { public getNumberOfPhases(): number | undefined { switch (this.getCurrentOutType()) { - case CurrentOutType.AC: + case CurrentType.AC: return !Utils.isUndefined(this.stationInfo.numberOfPhases) ? this.stationInfo.numberOfPhases : 3; - case CurrentOutType.DC: + case CurrentType.DC: return 0; } } @@ -120,19 +120,19 @@ export default class ChargingStation { return this.connectors[id]; } - public getCurrentOutType(): CurrentOutType | undefined { - return this.stationInfo.currentOutType ?? CurrentOutType.AC; + public getCurrentOutType(): CurrentType | undefined { + return this.stationInfo.currentOutType ?? CurrentType.AC; } public getVoltageOut(): number | undefined { const errMsg = `${this.logPrefix()} Unknown ${this.getCurrentOutType()} currentOutType in template file ${this.stationTemplateFile}, cannot define default voltage out`; let defaultVoltageOut: number; switch (this.getCurrentOutType()) { - case CurrentOutType.AC: - defaultVoltageOut = VoltageOut.VOLTAGE_230; + case CurrentType.AC: + defaultVoltageOut = Voltage.VOLTAGE_230; break; - case CurrentOutType.DC: - defaultVoltageOut = VoltageOut.VOLTAGE_400; + case CurrentType.DC: + defaultVoltageOut = Voltage.VOLTAGE_400; break; default: logger.error(errMsg); diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index eb502d6e..74bc1fbf 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -1,6 +1,6 @@ import { ACElectricUtils, DCElectricUtils } from '../../../utils/ElectricUtils'; import { AuthorizeRequest, OCPP16AuthorizeResponse, OCPP16StartTransactionResponse, OCPP16StopTransactionReason, OCPP16StopTransactionResponse, StartTransactionRequest, StopTransactionRequest } from '../../../types/ocpp/1.6/Transaction'; -import { CurrentOutType, VoltageOut } from '../../../types/ChargingStationTemplate'; +import { CurrentType, Voltage } from '../../../types/ChargingStationTemplate'; import { HeartbeatRequest, OCPP16BootNotificationRequest, OCPP16IncomingRequestCommand, OCPP16RequestCommand, StatusNotificationRequest } from '../../../types/ocpp/1.6/Requests'; import { MeterValueUnit, MeterValuesRequest, OCPP16MeterValue, OCPP16MeterValueMeasurand, OCPP16MeterValuePhase } from '../../../types/ocpp/1.6/MeterValues'; @@ -158,11 +158,11 @@ export default class OCPP16RequestService extends OCPPRequestService { const voltagePhaseLineToLineSampledValueTemplate = self.chargingStation.getSampledValueTemplate(connectorId, OCPP16MeterValueMeasurand.VOLTAGE, phaseLineToLineValue as OCPP16MeterValuePhase); let voltagePhaseLineToLineMeasurandValue: number; if (voltagePhaseLineToLineSampledValueTemplate) { - const voltagePhaseLineToLineSampledValueTemplateValue = voltagePhaseLineToLineSampledValueTemplate.value ? parseInt(voltagePhaseLineToLineSampledValueTemplate.value) : VoltageOut.VOLTAGE_400; + const voltagePhaseLineToLineSampledValueTemplateValue = voltagePhaseLineToLineSampledValueTemplate.value ? parseInt(voltagePhaseLineToLineSampledValueTemplate.value) : Voltage.VOLTAGE_400; const fluctuationPhaseLineToLinePercent = voltagePhaseLineToLineSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT; voltagePhaseLineToLineMeasurandValue = Utils.getRandomFloatFluctuatedRounded(voltagePhaseLineToLineSampledValueTemplateValue, fluctuationPhaseLineToLinePercent); } - const defaultVoltagePhaseLineToLineMeasurandValue = Utils.getRandomFloatFluctuatedRounded(VoltageOut.VOLTAGE_400, fluctuationPercent); + const defaultVoltagePhaseLineToLineMeasurandValue = Utils.getRandomFloatFluctuatedRounded(Voltage.VOLTAGE_400, fluctuationPercent); meterValue.sampledValue.push(OCPP16ServiceUtils.buildSampledValue(voltagePhaseLineToLineSampledValueTemplate ?? voltageSampledValueTemplate, voltagePhaseLineToLineMeasurandValue ?? defaultVoltagePhaseLineToLineMeasurandValue, null, phaseLineToLineValue as OCPP16MeterValuePhase)); } @@ -186,7 +186,7 @@ export default class OCPP16RequestService extends OCPPRequestService { const maxPower = Math.round(self.chargingStation.stationInfo.maxPower / self.chargingStation.stationInfo.powerDivider); const maxPowerPerPhase = Math.round((self.chargingStation.stationInfo.maxPower / self.chargingStation.stationInfo.powerDivider) / self.chargingStation.getNumberOfPhases()); switch (self.chargingStation.getCurrentOutType()) { - case CurrentOutType.AC: + case CurrentType.AC: if (self.chargingStation.getNumberOfPhases() === 3) { const defaultFluctuatedPowerPerPhase = powerSampledValueTemplate.value && Utils.getRandomFloatFluctuatedRounded(parseInt(powerSampledValueTemplate.value) / self.chargingStation.getNumberOfPhases(), powerSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT); @@ -208,7 +208,7 @@ export default class OCPP16RequestService extends OCPPRequestService { } powerMeasurandValues.allPhases = Utils.roundTo(powerMeasurandValues.L1 + powerMeasurandValues.L2 + powerMeasurandValues.L3, 2); break; - case CurrentOutType.DC: + case CurrentType.DC: powerMeasurandValues.allPhases = powerSampledValueTemplate.value ? Utils.getRandomFloatFluctuatedRounded(parseInt(powerSampledValueTemplate.value), powerSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT) : Utils.getRandomFloatRounded(maxPower / unitDivider); @@ -250,7 +250,7 @@ export default class OCPP16RequestService extends OCPPRequestService { const currentMeasurandValues: MeasurandValues = {} as MeasurandValues; let maxAmperage: number; switch (self.chargingStation.getCurrentOutType()) { - case CurrentOutType.AC: + case CurrentType.AC: maxAmperage = ACElectricUtils.amperagePerPhaseFromPower(self.chargingStation.getNumberOfPhases(), self.chargingStation.stationInfo.maxPower / self.chargingStation.stationInfo.powerDivider, self.chargingStation.getVoltageOut()); if (self.chargingStation.getNumberOfPhases() === 3) { const defaultFluctuatedAmperagePerPhase = currentSampledValueTemplate.value @@ -273,7 +273,7 @@ export default class OCPP16RequestService extends OCPPRequestService { } currentMeasurandValues.allPhases = Utils.roundTo((currentMeasurandValues.L1 + currentMeasurandValues.L2 + currentMeasurandValues.L3) / self.chargingStation.getNumberOfPhases(), 2); break; - case CurrentOutType.DC: + case CurrentType.DC: maxAmperage = DCElectricUtils.amperage(self.chargingStation.stationInfo.maxPower / self.chargingStation.stationInfo.powerDivider, self.chargingStation.getVoltageOut()); currentMeasurandValues.allPhases = currentSampledValueTemplate.value ? Utils.getRandomFloatFluctuatedRounded(parseInt(currentSampledValueTemplate.value), currentSampledValueTemplate.fluctuationPercent ?? Constants.DEFAULT_FLUCTUATION_PERCENT) diff --git a/src/types/ChargingStationTemplate.ts b/src/types/ChargingStationTemplate.ts index 5fff748b..fd1d988f 100644 --- a/src/types/ChargingStationTemplate.ts +++ b/src/types/ChargingStationTemplate.ts @@ -3,7 +3,7 @@ import Connectors from './Connectors'; import { OCPPProtocol } from './ocpp/OCPPProtocol'; import { OCPPVersion } from './ocpp/OCPPVersion'; -export enum CurrentOutType { +export enum CurrentType { AC = 'AC', DC = 'DC', } @@ -13,7 +13,7 @@ export enum PowerUnits { KILO_WATT = 'kW', } -export enum VoltageOut { +export enum Voltage { VOLTAGE_110 = 110, VOLTAGE_230 = 230, VOLTAGE_400 = 400, @@ -47,8 +47,8 @@ export default interface ChargingStationTemplate { power: number | number[]; powerSharedByConnectors?: boolean; powerUnit: PowerUnits; - currentOutType?: CurrentOutType; - voltageOut?: number; + currentOutType?: CurrentType; + voltageOut?: Voltage; numberOfPhases?: number; numberOfConnectors?: number | number[]; useConnectorId0?: boolean;