Release 1.0.17
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStation.ts
index 6dce9a374d008e6562fb8aabe9d580c3ea160e26..feffa05da837ce929da0dce630a6a9f5601f2c87 100644 (file)
@@ -1,6 +1,7 @@
 import { BootNotificationResponse, RegistrationStatus } from '../types/ocpp/Responses';
 import ChargingStationConfiguration, { ConfigurationKey } from '../types/ChargingStationConfiguration';
 import ChargingStationTemplate, { CurrentOutType, PowerUnits, VoltageOut } from '../types/ChargingStationTemplate';
+import { ConnectorPhaseRotation, StandardParametersKey, SupportedFeatureProfiles } from '../types/ocpp/Configuration';
 import Connectors, { Connector } from '../types/Connectors';
 import { PerformanceObserver, performance } from 'perf_hooks';
 import Requests, { AvailabilityType, BootNotificationRequest, IncomingRequest, IncomingRequestCommand } from '../types/ocpp/Requests';
@@ -23,7 +24,6 @@ import OCPPIncomingRequestService from './ocpp/OCPPIncomingRequestService';
 import OCPPRequestService from './ocpp/OCPPRequestService';
 import { OCPPVersion } from '../types/ocpp/OCPPVersion';
 import PerformanceStatistics from '../utils/PerformanceStatistics';
-import { StandardParametersKey } from '../types/ocpp/Configuration';
 import { StopTransactionReason } from '../types/ocpp/Transaction';
 import Utils from '../utils/Utils';
 import { WebSocketCloseEventStatusCode } from '../types/WebSocket';
@@ -161,6 +161,10 @@ export default class ChargingStation {
     return this.stationInfo.meteringPerTransaction ?? true;
   }
 
+  public getTransactionDataMeterValues(): boolean {
+    return this.stationInfo.transactionDataMeterValues ?? false;
+  }
+
   public getEnergyActiveImportRegisterByTransactionId(transactionId: number): number | undefined {
     if (this.getMeteringPerTransaction()) {
       for (const connector in this.connectors) {
@@ -349,6 +353,7 @@ export default class ChargingStation {
     delete this.getConnector(connectorId).transactionId;
     delete this.getConnector(connectorId).idTag;
     this.getConnector(connectorId).transactionEnergyActiveImportRegisterValue = 0;
+    delete this.getConnector(connectorId).transactionBeginMeterValue;
     this.stopMeterValues(connectorId);
   }
 
@@ -405,9 +410,11 @@ export default class ChargingStation {
     } else {
       stationTemplateFromFile.power = stationTemplateFromFile.power as number;
       stationInfo.maxPower = stationTemplateFromFile.powerUnit === PowerUnits.KILO_WATT
-        ? (stationTemplateFromFile.power) * 1000
+        ? stationTemplateFromFile.power * 1000
         : stationTemplateFromFile.power;
     }
+    delete stationInfo.power;
+    delete stationInfo.powerUnit;
     stationInfo.chargingStationId = this.getChargingStationId(stationTemplateFromFile);
     stationInfo.resetTime = stationTemplateFromFile.resetTime ? stationTemplateFromFile.resetTime * 1000 : Constants.CHARGING_STATION_DEFAULT_RESET_TIME;
     return stationInfo;
@@ -500,6 +507,26 @@ export default class ChargingStation {
     if (!this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData)) {
       this.addConfigurationKey(StandardParametersKey.MeterValuesSampledData, MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER);
     }
+    if (!this.getConfigurationKey(StandardParametersKey.SupportedFeatureProfiles)) {
+      this.addConfigurationKey(StandardParametersKey.SupportedFeatureProfiles, SupportedFeatureProfiles.Core);
+    }
+    if (!this.getConfigurationKey(StandardParametersKey.ConnectorPhaseRotation)) {
+      const connectorPhaseRotation = [];
+      for (const connector in this.connectors) {
+        // AC/DC
+        if (Utils.convertToInt(connector) === 0 && this.getNumberOfPhases() === 0) {
+          connectorPhaseRotation.push(`${connector}.${ConnectorPhaseRotation.RST}`);
+        } else if (Utils.convertToInt(connector) > 0 && this.getNumberOfPhases() === 0) {
+          connectorPhaseRotation.push(`${connector}.${ConnectorPhaseRotation.NotApplicable}`);
+        // AC
+        } else if (Utils.convertToInt(connector) > 0 && this.getNumberOfPhases() === 1) {
+          connectorPhaseRotation.push(`${connector}.${ConnectorPhaseRotation.NotApplicable}`);
+        } else if (Utils.convertToInt(connector) > 0 && this.getNumberOfPhases() === 3) {
+          connectorPhaseRotation.push(`${connector}.${ConnectorPhaseRotation.RST}`);
+        }
+      }
+      this.addConfigurationKey(StandardParametersKey.ConnectorPhaseRotation, connectorPhaseRotation.toString());
+    }
     this.stationInfo.powerDivider = this.getPowerDivider();
     if (this.getEnableStatistics()) {
       this.performanceStatistics = new PerformanceStatistics(this.stationInfo.chargingStationId);
@@ -882,7 +909,7 @@ export default class ChargingStation {
     const authorizationFile = this.getAuthorizationFile();
     if (authorizationFile) {
       try {
-        fs.watch(authorizationFile).on('change', (e) => {
+        fs.watch(authorizationFile).on('change', () => {
           try {
             logger.debug(this.logPrefix() + ' Authorization file ' + authorizationFile + ' have changed, reload');
             // Initialize authorizedTags
@@ -901,8 +928,8 @@ export default class ChargingStation {
 
   private startStationTemplateFileMonitoring(): void {
     try {
-    // eslint-disable-next-line @typescript-eslint/no-misused-promises
-      fs.watch(this.stationTemplateFile).on('change', async (e): Promise<void> => {
+      // eslint-disable-next-line @typescript-eslint/no-misused-promises
+      fs.watch(this.stationTemplateFile).on('change', async (): Promise<void> => {
         try {
           logger.debug(this.logPrefix() + ' Template file ' + this.stationTemplateFile + ' have changed, reload');
           // Initialize