- public static getDefaultVoltageOut(
- currentType: CurrentType,
- templateFile: string,
- logPrefix: string
- ): Voltage {
- const errMsg = `Unknown ${currentType} currentOutType in template file ${templateFile}, cannot define default voltage out`;
- let defaultVoltageOut: number;
- switch (currentType) {
- case CurrentType.AC:
- defaultVoltageOut = Voltage.VOLTAGE_230;
- break;
- case CurrentType.DC:
- defaultVoltageOut = Voltage.VOLTAGE_400;
- break;
- default:
- logger.error(`${logPrefix} ${errMsg}`);
- throw new BaseError(errMsg);
- }
- return defaultVoltageOut;
- }
-
- public static getSampledValueTemplate(
- chargingStation: ChargingStation,
- connectorId: number,
- measurand: MeterValueMeasurand = MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER,
- phase?: MeterValuePhase
- ): SampledValueTemplate | undefined {
- const onPhaseStr = phase ? `on phase ${phase} ` : '';
- if (!Constants.SUPPORTED_MEASURANDS.includes(measurand)) {
- logger.warn(
- `${chargingStation.logPrefix()} Trying to get unsupported MeterValues measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId}`
- );
- return;
- }
- if (
- measurand !== MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER &&
- !ChargingStationConfigurationUtils.getConfigurationKey(
- chargingStation,
- StandardParametersKey.MeterValuesSampledData
- )?.value.includes(measurand)
- ) {
- logger.debug(
- `${chargingStation.logPrefix()} Trying to get MeterValues measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId} not found in '${
- StandardParametersKey.MeterValuesSampledData
- }' OCPP parameter`
- );
- return;
- }
- const sampledValueTemplates: SampledValueTemplate[] =
- chargingStation.getConnectorStatus(connectorId).MeterValues;
- for (
- let index = 0;
- !Utils.isEmptyArray(sampledValueTemplates) && index < sampledValueTemplates.length;
- index++
- ) {
- if (
- !Constants.SUPPORTED_MEASURANDS.includes(
- sampledValueTemplates[index]?.measurand ??
- MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
- )
- ) {
- logger.warn(
- `${chargingStation.logPrefix()} Unsupported MeterValues measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId}`
- );
- } else if (
- phase &&
- sampledValueTemplates[index]?.phase === phase &&
- sampledValueTemplates[index]?.measurand === measurand &&
- ChargingStationConfigurationUtils.getConfigurationKey(
- chargingStation,
- StandardParametersKey.MeterValuesSampledData
- )?.value.includes(measurand)
- ) {
- return sampledValueTemplates[index];
- } else if (
- !phase &&
- !sampledValueTemplates[index].phase &&
- sampledValueTemplates[index]?.measurand === measurand &&
- ChargingStationConfigurationUtils.getConfigurationKey(
- chargingStation,
- StandardParametersKey.MeterValuesSampledData
- )?.value.includes(measurand)
- ) {
- return sampledValueTemplates[index];
- } else if (
- measurand === MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER &&
- (!sampledValueTemplates[index].measurand ||
- sampledValueTemplates[index].measurand === measurand)
- ) {
- return sampledValueTemplates[index];
- }
- }
- if (measurand === MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER) {
- const errorMsg = `Missing MeterValues for default measurand '${measurand}' in template on connectorId ${connectorId}`;
- logger.error(`${chargingStation.logPrefix()} ${errorMsg}`);
- throw new BaseError(errorMsg);
- }
- logger.debug(
- `${chargingStation.logPrefix()} No MeterValues for measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId}`
- );
- }
-
- public static getAuthorizationFile(stationInfo: ChargingStationInfo): string | undefined {
- return (
- stationInfo.authorizationFile &&
- path.join(
- path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'),
- 'assets',
- path.basename(stationInfo.authorizationFile)
- )
- );
- }
-
- public static isRequestCommandSupported(
- command: RequestCommand,
- chargingStation: ChargingStation
- ): boolean {
- const isRequestCommand = Object.values(RequestCommand).includes(command);
- if (isRequestCommand && !chargingStation.stationInfo?.commandsSupport?.outgoingCommands) {
- return true;
- } else if (isRequestCommand && chargingStation.stationInfo?.commandsSupport?.outgoingCommands) {
- return chargingStation.stationInfo?.commandsSupport?.outgoingCommands[command] ?? false;
- }
- logger.error(`${chargingStation.logPrefix()} Unknown outgoing OCPP command '${command}'`);
- return false;
- }
-
- public static isIncomingRequestCommandSupported(
- command: IncomingRequestCommand,
- chargingStation: ChargingStation
- ): boolean {
- const isIncomingRequestCommand = Object.values(IncomingRequestCommand).includes(command);
- if (
- isIncomingRequestCommand &&
- !chargingStation.stationInfo?.commandsSupport?.incomingCommands
- ) {
- return true;
- } else if (
- isIncomingRequestCommand &&
- chargingStation.stationInfo?.commandsSupport?.incomingCommands
- ) {
- return chargingStation.stationInfo?.commandsSupport?.incomingCommands[command] ?? false;
- }
- logger.error(`${chargingStation.logPrefix()} Unknown incoming OCPP command '${command}'`);
- return false;
- }
-