async stop(reason = '') {
logger.info(this._logPrefix() + ' ATG OVER => STOPPING ALL TRANSACTIONS');
for (const connector in this._chargingStation._connectors) {
- if (this._chargingStation._connectors[connector].transactionStarted) {
- logger.info(this._logPrefix(connector) + ' ATG OVER. Stop transaction ' + this._chargingStation._connectors[connector].transactionId);
- await this._chargingStation.sendStopTransaction(this._chargingStation._connectors[connector].transactionId, reason);
+ if (this._chargingStation._getConnector(connector).transactionStarted) {
+ logger.info(this._logPrefix(connector) + ' ATG OVER. Stop transaction ' + this._chargingStation._getConnector(connector).transactionId);
+ await this._chargingStation.sendStopTransaction(this._chargingStation._getConnector(connector).transactionId, reason);
}
}
this._timeToStop = true;
// Wait until end of transaction
const wait = Utils.getRandomInt(this._chargingStation._stationInfo.AutomaticTransactionGenerator.maxDuration,
this._chargingStation._stationInfo.AutomaticTransactionGenerator.minDuration) * 1000;
- logger.info(this._logPrefix(connectorId) + ' transaction ' + this._chargingStation._connectors[connectorId].transactionId + ' will stop in ' + Utils.secondstoHHMMSS(wait / 1000));
+ logger.info(this._logPrefix(connectorId) + ' transaction ' + this._chargingStation._getConnector(connectorId).transactionId + ' will stop in ' + Utils.secondstoHHMMSS(wait / 1000));
await Utils.sleep(wait);
// Stop transaction
- if (this._chargingStation._connectors[connectorId].transactionStarted) {
- logger.info(this._logPrefix(connectorId) + ' stop transaction ' + this._chargingStation._connectors[connectorId].transactionId);
+ if (this._chargingStation._getConnector(connectorId).transactionStarted) {
+ logger.info(this._logPrefix(connectorId) + ' stop transaction ' + this._chargingStation._getConnector(connectorId).transactionId);
const stopTransaction = performance.timerify(this.stopTransaction);
this._performanceObserver.observe({entryTypes: ['function']});
await stopTransaction(connectorId, this);
// eslint-disable-next-line class-methods-use-this
async stopTransaction(connectorId, self) {
- await self._chargingStation.sendStopTransaction(self._chargingStation._connectors[connectorId].transactionId);
+ await self._chargingStation.sendStopTransaction(self._chargingStation._getConnector(connectorId).transactionId);
}
}
stationTemplateFromFile = JSON.parse(fs.readFileSync(fileDescriptor, 'utf8'));
fs.closeSync(fileDescriptor);
} catch (error) {
- logger.error(this._logPrefix() + ' Template file loading error: ' + error);
+ logger.error('Template file ' + this._stationTemplateFile + ' loading error: ' + error);
+ throw error;
}
const stationTemplate = stationTemplateFromFile || {};
if (!Utils.isEmptyArray(stationTemplateFromFile.power)) {
delete this._stationInfo.Connectors;
// Initialize transaction attributes on connectors
for (const connector in this._connectors) {
- if (!this._connectors[connector].transactionStarted) {
+ if (!this._getConnector(connector).transactionStarted) {
this._initTransactionOnConnector(connector);
}
}
authorizedTags = JSON.parse(fs.readFileSync(fileDescriptor, 'utf8'));
fs.closeSync(fileDescriptor);
} catch (error) {
- logger.error(this._logPrefix() + ' Authorization file loading error: ' + error);
+ logger.error(this._logPrefix() + ' Authorization file ' + authorizationFile + ' loading error: ' + error);
+ throw error;
}
} else {
logger.info(this._logPrefix() + ' No authorization file given in template file ' + this._stationTemplateFile);
this._startHeartbeat(this);
// Initialize connectors status
for (const connector in this._connectors) {
- if (!this._connectors[connector].transactionStarted) {
- if (this._connectors[connector].bootStatus) {
- this.sendStatusNotificationWithTimeout(connector, this._connectors[connector].bootStatus);
+ if (!this._getConnector(connector).transactionStarted) {
+ if (this._getConnector(connector).bootStatus) {
+ this.sendStatusNotificationWithTimeout(connector, this._getConnector(connector).bootStatus);
} else {
this.sendStatusNotificationWithTimeout(connector, 'Available');
}
}
async _startMeterValues(connectorId, interval) {
- if (!this._connectors[connectorId].transactionStarted) {
+ if (!this._getConnector(connectorId).transactionStarted) {
logger.error(`${this._logPrefix()} Trying to start MeterValues on connector Id ${connectorId} with no transaction started`);
return;
- } else if (this._connectors[connectorId].transactionStarted && !this._connectors[connectorId].transactionId) {
+ } else if (this._getConnector(connectorId).transactionStarted && !this._getConnector(connectorId).transactionId) {
logger.error(`${this._logPrefix()} Trying to start MeterValues on connector Id ${connectorId} with no transaction id`);
return;
}
if (interval > 0) {
- this._connectors[connectorId].transactionSetInterval = setInterval(async () => {
+ this._getConnector(connectorId).transactionSetInterval = setInterval(async () => {
const sendMeterValues = performance.timerify(this.sendMeterValues);
this._performanceObserver.observe({
entryTypes: ['function'],
await this._automaticTransactionGeneration.stop(reason);
} else {
for (const connector in this._connectors) {
- if (this._connectors[connector].transactionStarted) {
- await this.sendStopTransaction(this._connectors[connector].transactionId, reason);
+ if (this._getConnector(connector).transactionStarted) {
+ await this.sendStopTransaction(this._getConnector(connector).transactionId, reason);
}
}
}
sampledValueLcl.sampledValue = [meterValuesClone];
}
for (let index = 0; index < sampledValueLcl.sampledValue.length; index++) {
- const connector = self._connectors[connectorId];
+ const connector = self._getConnector(connectorId);
// SoC measurand
if (sampledValueLcl.sampledValue[index].measurand && sampledValueLcl.sampledValue[index].measurand === 'SoC' && self._getConfigurationKey('MeterValuesSampledData').value.includes('SoC')) {
sampledValueLcl.sampledValue[index].value = !Utils.isUndefined(sampledValueLcl.sampledValue[index].value) ?
const payload = {
connectorId,
- transactionId: self._connectors[connectorId].transactionId,
+ transactionId: self._getConnector(connectorId).transactionId,
meterValue: [sampledValueLcl],
};
await self.sendMessage(Utils.generateUUID(), payload, Constants.OCPP_JSON_CALL_MESSAGE, 'MeterValues');
}
_initTransactionOnConnector(connectorId) {
- this._connectors[connectorId].transactionStarted = false;
- this._connectors[connectorId].transactionId = null;
- this._connectors[connectorId].idTag = null;
- this._connectors[connectorId].lastEnergyActiveImportRegisterValue = -1;
+ this._getConnector(connectorId).transactionStarted = false;
+ this._getConnector(connectorId).transactionId = null;
+ this._getConnector(connectorId).idTag = null;
+ this._getConnector(connectorId).lastEnergyActiveImportRegisterValue = -1;
}
_resetTransactionOnConnector(connectorId) {
this._initTransactionOnConnector(connectorId);
- if (this._connectors[connectorId].transactionSetInterval) {
- clearInterval(this._connectors[connectorId].transactionSetInterval);
+ if (this._getConnector(connectorId).transactionSetInterval) {
+ clearInterval(this._getConnector(connectorId).transactionSetInterval);
}
}
handleResponseStartTransaction(payload, requestPayload) {
- if (this._connectors[requestPayload.connectorId].transactionStarted) {
- logger.debug(this._logPrefix() + ' Try to start a transaction on an already used connector ' + requestPayload.connectorId + ': %s', this._connectors[requestPayload.connectorId]);
+ if (this._getConnector(requestPayload.connectorId).transactionStarted) {
+ logger.debug(this._logPrefix() + ' Try to start a transaction on an already used connector ' + requestPayload.connectorId + ': %s', this._getConnector(requestPayload.connectorId));
return;
}
return;
}
if (payload.idTagInfo && payload.idTagInfo.status === 'Accepted') {
- this._connectors[transactionConnectorId].transactionStarted = true;
- this._connectors[transactionConnectorId].transactionId = payload.transactionId;
- this._connectors[transactionConnectorId].idTag = requestPayload.idTag;
- this._connectors[transactionConnectorId].lastEnergyActiveImportRegisterValue = 0;
+ this._getConnector(requestPayload.connectorId).transactionStarted = true;
+ this._getConnector(requestPayload.connectorId).transactionId = payload.transactionId;
+ this._getConnector(requestPayload.connectorId).idTag = requestPayload.idTag;
+ this._getConnector(requestPayload.connectorId).lastEnergyActiveImportRegisterValue = 0;
this.sendStatusNotification(requestPayload.connectorId, 'Charging');
logger.info(this._logPrefix() + ' Transaction ' + payload.transactionId + ' STARTED on ' + this._stationInfo.name + '#' + requestPayload.connectorId + ' for idTag ' + requestPayload.idTag);
if (this._stationInfo.powerSharedByConnectors) {
handleResponseStopTransaction(payload, requestPayload) {
let transactionConnectorId;
for (const connector in this._connectors) {
- if (this._connectors[connector].transactionId === requestPayload.transactionId) {
+ if (this._getConnector(connector).transactionId === requestPayload.transactionId) {
transactionConnectorId = connector;
break;
}
async handleRemoteStopTransaction(commandPayload) {
for (const connector in this._connectors) {
- if (this._connectors[connector].transactionId === commandPayload.transactionId) {
+ if (this._getConnector(connector).transactionId === commandPayload.transactionId) {
this.sendStopTransaction(commandPayload.transactionId);
return Constants.OCPP_RESPONSE_ACCEPTED;
}