- public static getDefaultVoltageOut(
- currentType: CurrentType,
- templateFile: string,
- logPrefix: string
- ): Voltage {
- const errMsg = `${logPrefix} 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(errMsg);
- throw new Error(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 = `${chargingStation.logPrefix()} Missing MeterValues for default measurand '${measurand}' in template on connectorId ${connectorId}`;
- logger.error(errorMsg);
- throw new Error(errorMsg);
- }
- logger.debug(
- `${chargingStation.logPrefix()} No MeterValues for measurand '${measurand}' ${onPhaseStr}in template on connectorId ${connectorId}`
- );
- }
-
- public static getAuthorizedTags(
- stationInfo: ChargingStationInfo,
- templateFile: string,
- logPrefix: string
- ): string[] {
- let authorizedTags: string[] = [];
- const authorizationFile = ChargingStationUtils.getAuthorizationFile(stationInfo);
- if (authorizationFile) {
- try {
- // Load authorization file
- authorizedTags = JSON.parse(fs.readFileSync(authorizationFile, 'utf8')) as string[];
- } catch (error) {
- FileUtils.handleFileException(
- logPrefix,
- FileType.Authorization,
- authorizationFile,
- error as NodeJS.ErrnoException
- );
- }
- } else {
- logger.info(logPrefix + ' No authorization file given in template file ' + templateFile);
- }
- return authorizedTags;
- }
-
- public static getAuthorizationFile(stationInfo: ChargingStationInfo): string | undefined {
- return (
- stationInfo.authorizationFile &&
- path.join(
- path.resolve(__dirname, '../'),
- 'assets',
- path.basename(stationInfo.authorizationFile)
- )
- );
- }
-
- public static isChargingStationConfigurationCacheable(
- chargingStationConfiguration: ChargingStationConfiguration
- ): boolean {
- return (
- !Utils.isNullOrUndefined(chargingStationConfiguration?.configurationKey) &&
- !Utils.isNullOrUndefined(chargingStationConfiguration?.stationInfo) &&
- !Utils.isNullOrUndefined(chargingStationConfiguration?.configurationHash) &&
- !Utils.isEmptyArray(chargingStationConfiguration?.configurationKey) &&
- !Utils.isEmptyObject(chargingStationConfiguration?.stationInfo) &&
- !Utils.isEmptyString(chargingStationConfiguration?.configurationHash)
- );
- }
-