- this.stationInfo = this.buildStationInfo();
- this.bootNotificationRequest = {
- chargePointModel: this.stationInfo.chargePointModel,
- chargePointVendor: this.stationInfo.chargePointVendor,
- ...!Utils.isUndefined(this.stationInfo.chargeBoxSerialNumberPrefix) && { chargeBoxSerialNumber: this.stationInfo.chargeBoxSerialNumberPrefix },
- ...!Utils.isUndefined(this.stationInfo.firmwareVersion) && { firmwareVersion: this.stationInfo.firmwareVersion },
- };
- this.configuration = this.getTemplateChargingStationConfiguration();
- this.supervisionUrl = this.getSupervisionURL();
- this.wsConnectionUrl = this.supervisionUrl + '/' + this.stationInfo.chargingStationId;
- // Build connectors if needed
- const maxConnectors = this.getMaxNumberOfConnectors();
- if (maxConnectors <= 0) {
- logger.warn(`${this.logPrefix()} Charging station template ${this.stationTemplateFile} with ${maxConnectors} connectors`);
- }
- const templateMaxConnectors = this.getTemplateMaxNumberOfConnectors();
- if (templateMaxConnectors <= 0) {
- logger.warn(`${this.logPrefix()} Charging station template ${this.stationTemplateFile} with no connector configuration`);
- }
- if (!this.stationInfo.Connectors[0]) {
- logger.warn(`${this.logPrefix()} Charging station template ${this.stationTemplateFile} with no connector Id 0 configuration`);
- }
- // Sanity check
- if (maxConnectors > (this.stationInfo.Connectors[0] ? templateMaxConnectors - 1 : templateMaxConnectors) && !this.stationInfo.randomConnectors) {
- logger.warn(`${this.logPrefix()} Number of connectors exceeds the number of connector configurations in template ${this.stationTemplateFile}, forcing random connector configurations affectation`);
- this.stationInfo.randomConnectors = true;
- }
- const connectorsConfigHash = crypto.createHash('sha256').update(JSON.stringify(this.stationInfo.Connectors) + maxConnectors.toString()).digest('hex');
- // FIXME: Handle shrinking the number of connectors
- if (!this.connectors || (this.connectors && this.connectorsConfigurationHash !== connectorsConfigHash)) {
- this.connectorsConfigurationHash = connectorsConfigHash;
- // Add connector Id 0
- let lastConnector = '0';
- for (lastConnector in this.stationInfo.Connectors) {
- if (Utils.convertToInt(lastConnector) === 0 && this.getUseConnectorId0() && this.stationInfo.Connectors[lastConnector]) {
- this.connectors[lastConnector] = Utils.cloneObject<Connector>(this.stationInfo.Connectors[lastConnector]);
- this.connectors[lastConnector].availability = AvailabilityType.OPERATIVE;
- if (Utils.isUndefined(this.connectors[lastConnector]?.chargingProfiles)) {
- this.connectors[lastConnector].chargingProfiles = [];
- }
+ this.configurationFile = path.join(
+ path.dirname(this.templateFile.replace('station-templates', 'configurations')),
+ `${ChargingStationUtils.getHashId(this.index, this.getTemplateFromFile())}.json`
+ );
+ this.stationInfo = this.getStationInfo();
+ if (
+ this.stationInfo.firmwareStatus === FirmwareStatus.Installing &&
+ Utils.isNotEmptyString(this.stationInfo.firmwareVersion) &&
+ Utils.isNotEmptyString(this.stationInfo.firmwareVersionPattern)
+ ) {
+ const patternGroup: number | undefined =
+ this.stationInfo.firmwareUpgrade?.versionUpgrade?.patternGroup ??
+ this.stationInfo.firmwareVersion?.split('.').length;
+ const match = this.stationInfo?.firmwareVersion
+ ?.match(new RegExp(this.stationInfo.firmwareVersionPattern))
+ ?.slice(1, patternGroup + 1);
+ const patchLevelIndex = match.length - 1;
+ match[patchLevelIndex] = (
+ Utils.convertToInt(match[patchLevelIndex]) +
+ this.stationInfo.firmwareUpgrade?.versionUpgrade?.step
+ ).toString();
+ this.stationInfo.firmwareVersion = match?.join('.');
+ }
+ this.saveStationInfo();
+ // Avoid duplication of connectors related information in RAM
+ delete this.stationInfo?.Connectors;
+ this.configuredSupervisionUrl = this.getConfiguredSupervisionUrl();
+ if (this.getEnableStatistics() === true) {
+ this.performanceStatistics = PerformanceStatistics.getInstance(
+ this.stationInfo.hashId,
+ this.stationInfo.chargingStationId,
+ this.configuredSupervisionUrl
+ );
+ }
+ this.bootNotificationRequest = ChargingStationUtils.createBootNotificationRequest(
+ this.stationInfo
+ );
+ this.powerDivider = this.getPowerDivider();
+ // OCPP configuration
+ this.ocppConfiguration = this.getOcppConfiguration();
+ this.initializeOcppConfiguration();
+ this.initializeOcppServices();
+ if (this.stationInfo?.autoRegister === true) {
+ this.bootNotificationResponse = {
+ currentTime: new Date(),
+ interval: this.getHeartbeatInterval() / 1000,
+ status: RegistrationStatusEnumType.ACCEPTED,
+ };
+ }
+ }
+
+ private initializeOcppServices(): void {
+ const ocppVersion = this.stationInfo.ocppVersion ?? OCPPVersion.VERSION_16;
+ switch (ocppVersion) {
+ case OCPPVersion.VERSION_16:
+ this.ocppIncomingRequestService =
+ OCPP16IncomingRequestService.getInstance<OCPP16IncomingRequestService>();
+ this.ocppRequestService = OCPP16RequestService.getInstance<OCPP16RequestService>(
+ OCPP16ResponseService.getInstance<OCPP16ResponseService>()
+ );
+ break;
+ case OCPPVersion.VERSION_20:
+ case OCPPVersion.VERSION_201:
+ this.ocppIncomingRequestService =
+ OCPP20IncomingRequestService.getInstance<OCPP20IncomingRequestService>();
+ this.ocppRequestService = OCPP20RequestService.getInstance<OCPP20RequestService>(
+ OCPP20ResponseService.getInstance<OCPP20ResponseService>()
+ );
+ break;
+ default:
+ this.handleUnsupportedVersion(ocppVersion);
+ break;
+ }
+ }
+
+ private initializeOcppConfiguration(): void {
+ if (
+ !ChargingStationConfigurationUtils.getConfigurationKey(
+ this,
+ StandardParametersKey.HeartbeatInterval
+ )
+ ) {
+ ChargingStationConfigurationUtils.addConfigurationKey(
+ this,
+ StandardParametersKey.HeartbeatInterval,
+ '0'
+ );
+ }
+ if (
+ !ChargingStationConfigurationUtils.getConfigurationKey(
+ this,
+ StandardParametersKey.HeartBeatInterval
+ )
+ ) {
+ ChargingStationConfigurationUtils.addConfigurationKey(
+ this,
+ StandardParametersKey.HeartBeatInterval,
+ '0',
+ { visible: false }
+ );
+ }
+ if (
+ this.getSupervisionUrlOcppConfiguration() &&
+ Utils.isNotEmptyString(this.getSupervisionUrlOcppKey()) &&
+ !ChargingStationConfigurationUtils.getConfigurationKey(this, this.getSupervisionUrlOcppKey())
+ ) {
+ ChargingStationConfigurationUtils.addConfigurationKey(
+ this,
+ this.getSupervisionUrlOcppKey(),
+ this.configuredSupervisionUrl.href,
+ { reboot: true }
+ );
+ } else if (
+ !this.getSupervisionUrlOcppConfiguration() &&
+ Utils.isNotEmptyString(this.getSupervisionUrlOcppKey()) &&
+ ChargingStationConfigurationUtils.getConfigurationKey(this, this.getSupervisionUrlOcppKey())
+ ) {
+ ChargingStationConfigurationUtils.deleteConfigurationKey(
+ this,
+ this.getSupervisionUrlOcppKey(),
+ { save: false }
+ );
+ }
+ if (
+ Utils.isNotEmptyString(this.stationInfo?.amperageLimitationOcppKey) &&
+ !ChargingStationConfigurationUtils.getConfigurationKey(
+ this,
+ this.stationInfo.amperageLimitationOcppKey
+ )
+ ) {
+ ChargingStationConfigurationUtils.addConfigurationKey(
+ this,
+ this.stationInfo.amperageLimitationOcppKey,
+ (
+ this.stationInfo.maximumAmperage *
+ ChargingStationUtils.getAmperageLimitationUnitDivider(this.stationInfo)
+ ).toString()
+ );
+ }
+ if (
+ !ChargingStationConfigurationUtils.getConfigurationKey(
+ this,
+ StandardParametersKey.SupportedFeatureProfiles
+ )
+ ) {
+ ChargingStationConfigurationUtils.addConfigurationKey(
+ this,
+ StandardParametersKey.SupportedFeatureProfiles,
+ `${SupportedFeatureProfiles.Core},${SupportedFeatureProfiles.FirmwareManagement},${SupportedFeatureProfiles.LocalAuthListManagement},${SupportedFeatureProfiles.SmartCharging},${SupportedFeatureProfiles.RemoteTrigger}`
+ );
+ }
+ ChargingStationConfigurationUtils.addConfigurationKey(
+ this,
+ StandardParametersKey.NumberOfConnectors,
+ this.getNumberOfConnectors().toString(),
+ { readonly: true },
+ { overwrite: true }
+ );
+ if (
+ !ChargingStationConfigurationUtils.getConfigurationKey(
+ this,
+ StandardParametersKey.MeterValuesSampledData
+ )
+ ) {
+ ChargingStationConfigurationUtils.addConfigurationKey(
+ this,
+ StandardParametersKey.MeterValuesSampledData,
+ MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER
+ );
+ }
+ if (
+ !ChargingStationConfigurationUtils.getConfigurationKey(
+ this,
+ StandardParametersKey.ConnectorPhaseRotation
+ )
+ ) {
+ const connectorPhaseRotation = [];
+ for (const connectorId of this.connectors.keys()) {
+ // AC/DC
+ if (connectorId === 0 && this.getNumberOfPhases() === 0) {
+ connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.RST}`);
+ } else if (connectorId > 0 && this.getNumberOfPhases() === 0) {
+ connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`);
+ // AC
+ } else if (connectorId > 0 && this.getNumberOfPhases() === 1) {
+ connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`);
+ } else if (connectorId > 0 && this.getNumberOfPhases() === 3) {
+ connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.RST}`);