From: Jérôme Benoit Date: Sat, 28 Nov 2020 21:33:46 +0000 (+0100) Subject: Add connector Id 0 handling by default X-Git-Tag: v1.0.1-0~171 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=593cf3f9c5d1b68ec8b5a034343a7cd6f0be7f38;p=e-mobility-charging-stations-simulator.git Add connector Id 0 handling by default Needed for charging profiles support. Signed-off-by: Jérôme Benoit --- diff --git a/src/assets/station-templates/abb.station-template.json b/src/assets/station-templates/abb.station-template.json index 4eee07fb..510045e7 100644 --- a/src/assets/station-templates/abb.station-template.json +++ b/src/assets/station-templates/abb.station-template.json @@ -9,7 +9,7 @@ "powerUnit": "W", "powerOutType": "DC", "numberOfConnectors": 2, - "useConnectorId0": false, + "useConnectorId0": true, "randomConnectors": false, "resetTime": 30, "enableStatistics": false, diff --git a/src/assets/station-templates/evlink.station-template.json b/src/assets/station-templates/evlink.station-template.json index 46b1532b..4ced1375 100644 --- a/src/assets/station-templates/evlink.station-template.json +++ b/src/assets/station-templates/evlink.station-template.json @@ -51,6 +51,7 @@ "stopOnConnectionFailure": false }, "Connectors": { + "0": {}, "1": { "MeterValues": [ { diff --git a/src/assets/station-templates/keba.station-template.json b/src/assets/station-templates/keba.station-template.json index 02db4f46..4c8ef7eb 100644 --- a/src/assets/station-templates/keba.station-template.json +++ b/src/assets/station-templates/keba.station-template.json @@ -48,6 +48,7 @@ "stopOnConnectionFailure": false }, "Connectors": { + "0": {}, "1": { "MeterValues": [ { diff --git a/src/assets/station-templates/schneider-imredd.station-template.json b/src/assets/station-templates/schneider-imredd.station-template.json index d314c5ae..0e333065 100644 --- a/src/assets/station-templates/schneider-imredd.station-template.json +++ b/src/assets/station-templates/schneider-imredd.station-template.json @@ -50,6 +50,7 @@ "stopOnConnectionFailure": false }, "Connectors": { + "0": {}, "1": { "MeterValues": [ { diff --git a/src/assets/station-templates/schneider.station-template.json b/src/assets/station-templates/schneider.station-template.json index bdd48c7a..26f36319 100644 --- a/src/assets/station-templates/schneider.station-template.json +++ b/src/assets/station-templates/schneider.station-template.json @@ -55,6 +55,7 @@ "stopOnConnectionFailure": false }, "Connectors": { + "0": {}, "1": { "MeterValues": [ { diff --git a/src/assets/station-templates/siemens.station-template.json b/src/assets/station-templates/siemens.station-template.json index 9c4d5cff..0c6cdc34 100644 --- a/src/assets/station-templates/siemens.station-template.json +++ b/src/assets/station-templates/siemens.station-template.json @@ -49,6 +49,7 @@ "stopOnConnectionFailure": false }, "Connectors": { + "0": {}, "1": { "bootStatus": "Unavailable", "MeterValues": [ diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 667c154b..1301bc7a 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -118,7 +118,10 @@ export default class ChargingStation { } const templateMaxConnectors = this._getTemplateMaxNumberOfConnectors(); if (templateMaxConnectors <= 0) { - logger.warn(`${this._logPrefix()} Charging station template ${this._stationTemplateFile} with no connector configurations`); + 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) { @@ -132,7 +135,7 @@ export default class ChargingStation { // Add connector Id 0 let lastConnector = '0'; for (lastConnector in this._stationInfo.Connectors) { - if (Utils.convertToInt(lastConnector) === 0 && this._stationInfo.useConnectorId0 && this._stationInfo.Connectors[lastConnector]) { + if (Utils.convertToInt(lastConnector) === 0 && this._getUseConnectorId0() && this._stationInfo.Connectors[lastConnector]) { this._connectors[lastConnector] = Utils.cloneObject(this._stationInfo.Connectors[lastConnector]) as Connector; } } @@ -148,7 +151,7 @@ export default class ChargingStation { delete this._stationInfo.Connectors; // Initialize transaction attributes on connectors for (const connector in this._connectors) { - if (!this.getConnector(Utils.convertToInt(connector)).transactionStarted) { + if (Utils.convertToInt(connector) > 0 && !this.getConnector(Utils.convertToInt(connector)).transactionStarted) { this._initTransactionOnConnector(Utils.convertToInt(connector)); } } @@ -189,6 +192,10 @@ export default class ChargingStation { return this._stationInfo.authorizationFile && this._stationInfo.authorizationFile; } + _getUseConnectorId0(): boolean { + return !Utils.isUndefined(this._stationInfo.useConnectorId0) ? this._stationInfo.useConnectorId0 : true; + } + _loadAndGetAuthorizedTags(): string[] { let authorizedTags: string[] = []; const authorizationFile = this._getAuthorizationFile(); @@ -233,7 +240,7 @@ export default class ChargingStation { _getNumberOfRunningTransactions(): number { let trxCount = 0; for (const connector in this._connectors) { - if (this.getConnector(Utils.convertToInt(connector)).transactionStarted) { + if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector)).transactionStarted) { trxCount++; } } @@ -313,7 +320,7 @@ export default class ChargingStation { _getTransactionIdTag(transactionId: number): string { for (const connector in this._connectors) { - if (this.getConnector(Utils.convertToInt(connector)).transactionId === transactionId) { + if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector)).transactionId === transactionId) { return this.getConnector(Utils.convertToInt(connector)).idTag; } } @@ -321,7 +328,7 @@ export default class ChargingStation { _getTransactionMeterStop(transactionId: number): number { for (const connector in this._connectors) { - if (this.getConnector(Utils.convertToInt(connector)).transactionId === transactionId) { + if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector)).transactionId === transactionId) { return this.getConnector(Utils.convertToInt(connector)).lastEnergyActiveImportRegisterValue; } } @@ -367,7 +374,9 @@ export default class ChargingStation { this._startHeartbeat(); // Initialize connectors status for (const connector in this._connectors) { - if (!this._hasStopped && !this.getConnector(Utils.convertToInt(connector)).status && this.getConnector(Utils.convertToInt(connector)).bootStatus) { + if (Utils.convertToInt(connector) === 0) { + continue; + } else if (!this._hasStopped && !this.getConnector(Utils.convertToInt(connector)).status && this.getConnector(Utils.convertToInt(connector)).bootStatus) { // Send status in template at startup await this.sendStatusNotification(Utils.convertToInt(connector), this.getConnector(Utils.convertToInt(connector)).bootStatus); } else if (this._hasStopped && this.getConnector(Utils.convertToInt(connector)).bootStatus) { @@ -407,7 +416,7 @@ export default class ChargingStation { await this._automaticTransactionGeneration.stop(reason); } else { for (const connector in this._connectors) { - if (this.getConnector(Utils.convertToInt(connector)).transactionStarted) { + if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector)).transactionStarted) { await this.sendStopTransaction(this.getConnector(Utils.convertToInt(connector)).transactionId, reason); } } @@ -561,9 +570,10 @@ export default class ChargingStation { async stop(reason: StopTransactionReason = StopTransactionReason.NONE): Promise { // Stop message sequence await this._stopMessageSequence(reason); - // eslint-disable-next-line guard-for-in for (const connector in this._connectors) { - await this.sendStatusNotification(Utils.convertToInt(connector), ChargePointStatus.UNAVAILABLE); + if (Utils.convertToInt(connector) > 0) { + await this.sendStatusNotification(Utils.convertToInt(connector), ChargePointStatus.UNAVAILABLE); + } } if (this._wsConnection?.readyState === WebSocket.OPEN) { this._wsConnection.close(); @@ -822,11 +832,10 @@ export default class ChargingStation { ...!Utils.isUndefined(meterValuesTemplate[index].value) ? { value: meterValuesTemplate[index].value } : { value: voltageMeasurandValue.toString() }, }); for (let phase = 1; self._getNumberOfPhases() === 3 && phase <= self._getNumberOfPhases(); phase++) { - const voltageValue = Utils.convertToFloat(meterValue.sampledValue[meterValue.sampledValue.length - 1].value); let phaseValue: string; - if (voltageValue >= 0 && voltageValue <= 250) { + if (self._getVoltageOut() >= 0 && self._getVoltageOut() <= 250) { phaseValue = `L${phase}-N`; - } else if (voltageValue > 250) { + } else if (self._getVoltageOut() > 250) { phaseValue = `L${phase}-L${(phase + 1) % self._getNumberOfPhases() !== 0 ? (phase + 1) % self._getNumberOfPhases() : self._getNumberOfPhases()}`; } meterValue.sampledValue.push({ @@ -1146,7 +1155,7 @@ export default class ChargingStation { let transactionConnectorId: number; for (const connector in this._connectors) { - if (Utils.convertToInt(connector) === connectorId) { + if (Utils.convertToInt(connector) > 0 && Utils.convertToInt(connector) === connectorId) { transactionConnectorId = Utils.convertToInt(connector); break; } @@ -1178,7 +1187,7 @@ export default class ChargingStation { handleResponseStopTransaction(payload: StopTransactionResponse, requestPayload: StopTransactionRequest): void { let transactionConnectorId: number; for (const connector in this._connectors) { - if (this.getConnector(Utils.convertToInt(connector)).transactionId === Utils.convertToInt(requestPayload.transactionId)) { + if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector)).transactionId === Utils.convertToInt(requestPayload.transactionId)) { transactionConnectorId = Utils.convertToInt(connector); break; } @@ -1411,7 +1420,7 @@ export default class ChargingStation { async handleRequestRemoteStopTransaction(commandPayload: RemoteStopTransactionRequest): Promise { const transactionId = Utils.convertToInt(commandPayload.transactionId); for (const connector in this._connectors) { - if (this.getConnector(Utils.convertToInt(connector)).transactionId === transactionId) { + if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector)).transactionId === transactionId) { await this.sendStopTransaction(transactionId); return Constants.OCPP_RESPONSE_ACCEPTED; }