- private handleUnsupportedVersion(version: OCPPVersion) {
- const errMsg = `${this.logPrefix()} Unsupported protocol version '${version}' configured in template file ${
- this.templateFile
- }`;
- logger.error(errMsg);
- throw new Error(errMsg);
- }
-
- private createBootNotificationRequest(stationInfo: ChargingStationInfo): BootNotificationRequest {
- return {
- chargePointModel: stationInfo.chargePointModel,
- chargePointVendor: stationInfo.chargePointVendor,
- ...(!Utils.isUndefined(stationInfo.chargeBoxSerialNumber) && {
- chargeBoxSerialNumber: stationInfo.chargeBoxSerialNumber,
- }),
- ...(!Utils.isUndefined(stationInfo.chargePointSerialNumber) && {
- chargePointSerialNumber: stationInfo.chargePointSerialNumber,
- }),
- ...(!Utils.isUndefined(stationInfo.firmwareVersion) && {
- firmwareVersion: stationInfo.firmwareVersion,
- }),
- ...(!Utils.isUndefined(stationInfo.iccid) && { iccid: stationInfo.iccid }),
- ...(!Utils.isUndefined(stationInfo.imsi) && { imsi: stationInfo.imsi }),
- ...(!Utils.isUndefined(stationInfo.meterSerialNumber) && {
- meterSerialNumber: stationInfo.meterSerialNumber,
- }),
- ...(!Utils.isUndefined(stationInfo.meterType) && {
- meterType: stationInfo.meterType,
- }),
- };
- }
-
- private getHashId(stationInfo: ChargingStationInfo): string {
- const hashBootNotificationRequest = {
- chargePointModel: stationInfo.chargePointModel,
- chargePointVendor: stationInfo.chargePointVendor,
- ...(!Utils.isUndefined(stationInfo.chargeBoxSerialNumberPrefix) && {
- chargeBoxSerialNumber: stationInfo.chargeBoxSerialNumberPrefix,
- }),
- ...(!Utils.isUndefined(stationInfo.chargePointSerialNumberPrefix) && {
- chargePointSerialNumber: stationInfo.chargePointSerialNumberPrefix,
- }),
- ...(!Utils.isUndefined(stationInfo.firmwareVersion) && {
- firmwareVersion: stationInfo.firmwareVersion,
- }),
- ...(!Utils.isUndefined(stationInfo.iccid) && { iccid: stationInfo.iccid }),
- ...(!Utils.isUndefined(stationInfo.imsi) && { imsi: stationInfo.imsi }),
- ...(!Utils.isUndefined(stationInfo.meterSerialNumberPrefix) && {
- meterSerialNumber: stationInfo.meterSerialNumberPrefix,
- }),
- ...(!Utils.isUndefined(stationInfo.meterType) && {
- meterType: stationInfo.meterType,
- }),
- };
- return crypto
- .createHash(Constants.DEFAULT_HASH_ALGORITHM)
- .update(JSON.stringify(hashBootNotificationRequest) + stationInfo.chargingStationId)
- .digest('hex');
- }
-
- private initialize(): void {
- this.stationInfo = this.getStationInfo();
- logger.info(`${this.logPrefix()} Charging station hashId '${this.hashId}'`);
- this.bootNotificationRequest = this.createBootNotificationRequest(this.stationInfo);
- this.ocppConfiguration = this.getOcppConfiguration();
- this.stationInfo?.Configuration && delete this.stationInfo.Configuration;
- this.wsConfiguredConnectionUrl = new URL(
- this.getConfiguredSupervisionUrl().href + '/' + this.stationInfo.chargingStationId
- );
- // Build connectors if needed
- const maxConnectors = this.getMaxNumberOfConnectors();
- if (maxConnectors <= 0) {
- logger.warn(
- `${this.logPrefix()} Charging station template ${
- this.templateFile
- } with ${maxConnectors} connectors`
- );
- }
- const templateMaxConnectors = this.getTemplateMaxNumberOfConnectors();
- if (templateMaxConnectors === 0) {
- logger.warn(
- `${this.logPrefix()} Charging station template ${
- this.templateFile
- } with empty connectors configuration`
- );
- } else if (templateMaxConnectors < 0) {
- logger.error(
- `${this.logPrefix()} Charging station template ${
- this.templateFile
- } with no connectors configuration defined`
- );
- }
- if (!this.stationInfo?.Connectors[0]) {
- logger.warn(
- `${this.logPrefix()} Charging station template ${
- this.templateFile
- } 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.templateFile
- }, forcing random connector configurations affectation`
- );
- this.stationInfo.randomConnectors = true;
- }
- const connectorsConfigHash = crypto
- .createHash(Constants.DEFAULT_HASH_ALGORITHM)
- .update(JSON.stringify(this.stationInfo?.Connectors) + maxConnectors.toString())
- .digest('hex');
- const connectorsConfigChanged =
- this.connectors?.size !== 0 && this.connectorsConfigurationHash !== connectorsConfigHash;
- if (this.connectors?.size === 0 || connectorsConfigChanged) {
- connectorsConfigChanged && this.connectors.clear();
- this.connectorsConfigurationHash = connectorsConfigHash;
- // Add connector Id 0
- let lastConnector = '0';
- for (lastConnector in this.stationInfo?.Connectors) {
- const lastConnectorId = Utils.convertToInt(lastConnector);
- if (
- lastConnectorId === 0 &&
- this.getUseConnectorId0() &&
- this.stationInfo?.Connectors[lastConnector]
- ) {
- this.connectors.set(
- lastConnectorId,
- Utils.cloneObject<ConnectorStatus>(this.stationInfo?.Connectors[lastConnector])
- );
- this.getConnectorStatus(lastConnectorId).availability = AvailabilityType.OPERATIVE;
- if (Utils.isUndefined(this.getConnectorStatus(lastConnectorId)?.chargingProfiles)) {
- this.getConnectorStatus(lastConnectorId).chargingProfiles = [];
- }
- }
- }
- // Generate all connectors
- if (
- (this.stationInfo?.Connectors[0] ? templateMaxConnectors - 1 : templateMaxConnectors) > 0
- ) {
- for (let index = 1; index <= maxConnectors; index++) {
- const randConnectorId = this.stationInfo.randomConnectors
- ? Utils.getRandomInteger(Utils.convertToInt(lastConnector), 1)
- : index;
- this.connectors.set(
- index,
- Utils.cloneObject<ConnectorStatus>(this.stationInfo?.Connectors[randConnectorId])
- );
- this.getConnectorStatus(index).availability = AvailabilityType.OPERATIVE;
- if (Utils.isUndefined(this.getConnectorStatus(index)?.chargingProfiles)) {
- this.getConnectorStatus(index).chargingProfiles = [];
- }
- }
- }
- }
- this.stationInfo.maximumAmperage = this.getMaximumAmperage();
- this.stationInfo = this.createStationInfoHash(this.stationInfo);