import { BootNotificationResponse, RegistrationStatus } from '../types/ocpp/Responses';
import ChargingStationConfiguration, { ConfigurationKey } from '../types/ChargingStationConfiguration';
-import ChargingStationTemplate, { CurrentOutType, VoltageOut } from '../types/ChargingStationTemplate';
+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';
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';
}
}
- public getTransactionMeterStop(transactionId: number): number | undefined {
+ public getOutOfOrderEndMeterValues(): boolean {
+ return this.stationInfo.outOfOrderEndMeterValues ?? false;
+ }
+
+ public getBeginEndMeterValues(): boolean {
+ return this.stationInfo.beginEndMeterValues ?? false;
+ }
+
+ public getMeteringPerTransaction(): boolean {
+ 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) {
+ if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector)).transactionId === transactionId) {
+ return this.getConnector(Utils.convertToInt(connector)).transactionEnergyActiveImportRegisterValue;
+ }
+ }
+ }
for (const connector in this.connectors) {
if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector)).transactionId === transactionId) {
- return this.getConnector(Utils.convertToInt(connector)).lastEnergyActiveImportRegisterValue;
+ return this.getConnector(Utils.convertToInt(connector)).energyActiveImportRegisterValue;
}
}
}
+ public getEnergyActiveImportRegisterByConnectorId(connectorId: number): number | undefined {
+ if (this.getMeteringPerTransaction()) {
+ return this.getConnector(connectorId).transactionEnergyActiveImportRegisterValue;
+ }
+ return this.getConnector(connectorId).energyActiveImportRegisterValue;
+ }
+
public getAuthorizeRemoteTxRequests(): boolean {
const authorizeRemoteTxRequests = this.getConfigurationKey(StandardParametersKey.AuthorizeRemoteTxRequests);
return authorizeRemoteTxRequests ? Utils.convertToBoolean(authorizeRemoteTxRequests.value) : false;
this.startWebSocketPing();
}
+ public getAutomaticTransactionGeneratorRequireAuthorize(): boolean {
+ return this.stationInfo.AutomaticTransactionGenerator.requireAuthorize ?? true;
+ }
+
public startHeartbeat(): void {
if (this.getHeartbeatInterval() && this.getHeartbeatInterval() > 0 && !this.heartbeatSetInterval) {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
}
public resetTransactionOnConnector(connectorId: number): void {
- this.initTransactionOnConnector(connectorId);
+ this.getConnector(connectorId).transactionStarted = false;
+ delete this.getConnector(connectorId).transactionId;
+ delete this.getConnector(connectorId).idTag;
+ this.getConnector(connectorId).transactionEnergyActiveImportRegisterValue = 0;
+ delete this.getConnector(connectorId).transactionBeginMeterValue;
this.stopMeterValues(connectorId);
}
} catch (error) {
FileUtils.handleFileException(this.logPrefix(), 'Template', this.stationTemplateFile, error);
}
- const stationInfo: ChargingStationInfo = stationTemplateFromFile || {} as ChargingStationInfo;
+ const stationInfo: ChargingStationInfo = stationTemplateFromFile ?? {} as ChargingStationInfo;
if (!Utils.isEmptyArray(stationTemplateFromFile.power)) {
stationTemplateFromFile.power = stationTemplateFromFile.power as number[];
- stationInfo.maxPower = stationTemplateFromFile.power[Math.floor(Math.random() * stationTemplateFromFile.power.length)];
+ const powerArrayRandomIndex = Math.floor(Math.random() * stationTemplateFromFile.power.length);
+ stationInfo.maxPower = stationTemplateFromFile.powerUnit === PowerUnits.KILO_WATT
+ ? stationTemplateFromFile.power[powerArrayRandomIndex] * 1000
+ : stationTemplateFromFile.power[powerArrayRandomIndex];
} else {
- stationInfo.maxPower = stationTemplateFromFile.power as number;
+ stationTemplateFromFile.power = stationTemplateFromFile.power as number;
+ stationInfo.maxPower = stationTemplateFromFile.powerUnit === PowerUnits.KILO_WATT
+ ? 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;
// Initialize transaction attributes on connectors
for (const connector in this.connectors) {
if (Utils.convertToInt(connector) > 0 && !this.getConnector(Utils.convertToInt(connector)).transactionStarted) {
- this.initTransactionOnConnector(Utils.convertToInt(connector));
+ this.initTransactionAttributesOnConnector(Utils.convertToInt(connector));
}
}
switch (this.getOCPPVersion()) {
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);
try {
// Parse the message
[messageType, messageId, commandName, commandPayload, errorDetails] = JSON.parse(messageEvent.toString()) as IncomingRequest;
-
// Check the Type of message
switch (messageType) {
// Incoming Message
private async onError(errorEvent: any): Promise<void> {
logger.error(this.logPrefix() + ' Socket error: %j', errorEvent);
- // pragma switch (errorEvent.code) {
+ // switch (errorEvent.code) {
// case 'ECONNREFUSED':
// await this._reconnect(errorEvent);
// break;
for (const connector in this.connectors) {
if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector)).transactionStarted) {
const transactionId = this.getConnector(Utils.convertToInt(connector)).transactionId;
- await this.ocppRequestService.sendStopTransaction(transactionId, this.getTransactionMeterStop(transactionId), this.getTransactionIdTag(transactionId), reason);
+ await this.ocppRequestService.sendStopTransaction(transactionId, this.getEnergyActiveImportRegisterByTransactionId(transactionId),
+ this.getTransactionIdTag(transactionId), reason);
}
}
}
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
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
}
}
- private initTransactionOnConnector(connectorId: number): void {
+ private initTransactionAttributesOnConnector(connectorId: number): void {
this.getConnector(connectorId).transactionStarted = false;
- delete this.getConnector(connectorId).transactionId;
- delete this.getConnector(connectorId).idTag;
- this.getConnector(connectorId).lastEnergyActiveImportRegisterValue = -1;
+ this.getConnector(connectorId).energyActiveImportRegisterValue = 0;
+ this.getConnector(connectorId).transactionEnergyActiveImportRegisterValue = 0;
}
}