+
+ this._requests = {};
+ this._messageQueue = [];
+
+ this._authorizedTags = this._loadAndGetAuthorizedTags();
+ }
+
+ _getStationName(stationTemplate) {
+ return stationTemplate.fixedName ? stationTemplate.baseName : stationTemplate.baseName + '-' + ('000000000' + this._index).substr(('000000000' + this._index).length - 4);
+ }
+
+ _buildStationInfo() {
+ let stationTemplateFromFile;
+ try {
+ // Load template file
+ const fileDescriptor = fs.openSync(this._stationTemplateFile, 'r');
+ stationTemplateFromFile = JSON.parse(fs.readFileSync(fileDescriptor, 'utf8'));
+ fs.closeSync(fileDescriptor);
+ } catch (error) {
+ logger.error(this._basicFormatLog() + ' Template file loading error: ' + error);
+ }
+ const stationTemplate = stationTemplateFromFile || {};
+ if (!Utils.isEmptyArray(stationTemplateFromFile.power)) {
+ stationTemplate.maxPower = stationTemplateFromFile.power[Math.floor(Math.random() * stationTemplateFromFile.power.length)];
+ } else {
+ stationTemplate.maxPower = stationTemplateFromFile.power;
+ }
+ stationTemplate.name = this._getStationName(stationTemplateFromFile);
+ stationTemplate.resetTime = stationTemplateFromFile.resetTime ? stationTemplateFromFile.resetTime * 1000 : Constants.CHARGING_STATION_DEFAULT_RESET_TIME;
+ return stationTemplate;
+ }
+
+ _initialize() {
+ this._stationInfo = this._buildStationInfo();
+ this._bootNotificationMessage = {
+ chargePointModel: this._stationInfo.chargePointModel,
+ chargePointVendor: this._stationInfo.chargePointVendor,
+ chargePointSerialNumber: this._stationInfo.chargePointSerialNumberPrefix ? this._stationInfo.chargePointSerialNumberPrefix : '',
+ firmwareVersion: this._stationInfo.firmwareVersion ? this._stationInfo.firmwareVersion : '',
+ };
+ this._configuration = this._getConfiguration();
+ this._supervisionUrl = this._getSupervisionURL();
+ this._wsConnectionUrl = this._supervisionUrl + '/' + this._stationInfo.name;
+ // Build connectors if needed
+ const maxConnectors = this._getMaxConnectors();
+ const connectorsConfig = Utils.cloneJSonDocument(this._stationInfo.Connectors);
+ const connectorsConfigLength = Utils.convertToBoolean(this._stationInfo.useConnectorId0) && Object.keys(connectorsConfig).includes('0') ? Object.keys(connectorsConfig).length : Object.keys(connectorsConfig).length - 1;
+ if (!this._connectors || (this._connectors && Object.keys(this._connectors).length !== connectorsConfigLength)) {
+ this._connectors = {};
+ // Determine number of customized connectors
+ let lastConnector;
+ for (lastConnector in connectorsConfig) {
+ // Add connector 0, OCPP specification violation that for example KEBA have
+ if (Utils.convertToInt(lastConnector) === 0 && Utils.convertToBoolean(this._stationInfo.useConnectorId0) &&
+ connectorsConfig[lastConnector]) {
+ this._connectors[lastConnector] = connectorsConfig[lastConnector];
+ }
+ }
+ this._addConfigurationKey('NumberOfConnectors', maxConnectors, true);
+ // Generate all connectors
+ for (let index = 1; index <= maxConnectors; index++) {
+ const randConnectorID = Utils.convertToBoolean(this._stationInfo.randomConnectors) ? Utils.getRandomInt(lastConnector, 1) : index;
+ this._connectors[index] = connectorsConfig[randConnectorID];
+ }
+ }
+ // Initialize transaction attributes on connectors
+ for (const connector in this._connectors) {
+ if (!this._connectors[connector].transactionStarted) {
+ this._initTransactionOnConnector(connector);
+ }
+ }