1 // Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
3 import crypto from
'node:crypto';
4 import fs from
'node:fs';
5 import path from
'node:path';
6 import { URL
} from
'node:url';
7 import { parentPort
} from
'node:worker_threads';
9 import merge from
'just-merge';
10 import WebSocket
, { type RawData
} from
'ws';
13 AutomaticTransactionGenerator
,
14 ChargingStationConfigurationUtils
,
16 ChargingStationWorkerBroadcastChannel
,
22 // OCPP16IncomingRequestService,
24 // OCPP16ResponseService,
26 OCPP20IncomingRequestService
,
28 // OCPP20ResponseService,
29 type OCPPIncomingRequestService
,
30 type OCPPRequestService
,
33 import { OCPP16IncomingRequestService
} from
'./ocpp/1.6/OCPP16IncomingRequestService';
34 import { OCPP16ResponseService
} from
'./ocpp/1.6/OCPP16ResponseService';
35 import { OCPP20ResponseService
} from
'./ocpp/2.0/OCPP20ResponseService';
36 import { OCPPServiceUtils
} from
'./ocpp/OCPPServiceUtils';
37 import { BaseError
, OCPPError
} from
'../exception';
38 import { PerformanceStatistics
} from
'../performance';
40 type AutomaticTransactionGeneratorConfiguration
,
42 type BootNotificationRequest
,
43 type BootNotificationResponse
,
45 type ChargingStationConfiguration
,
46 type ChargingStationInfo
,
47 type ChargingStationOcppConfiguration
,
48 type ChargingStationTemplate
,
49 ConnectorPhaseRotation
,
59 type FirmwareStatusNotificationRequest
,
60 type FirmwareStatusNotificationResponse
,
62 type HeartbeatRequest
,
63 type HeartbeatResponse
,
65 type IncomingRequestCommand
,
70 type MeterValuesRequest
,
71 type MeterValuesResponse
,
75 RegistrationStatusEnumType
,
78 StandardParametersKey
,
79 type StatusNotificationRequest
,
80 type StatusNotificationResponse
,
81 StopTransactionReason
,
82 type StopTransactionRequest
,
83 type StopTransactionResponse
,
84 SupervisionUrlDistribution
,
85 SupportedFeatureProfiles
,
88 WebSocketCloseEventStatusCode
,
101 export class ChargingStation
{
102 public readonly index
: number;
103 public readonly templateFile
: string;
104 public stationInfo
!: ChargingStationInfo
;
105 public started
: boolean;
106 public starting
: boolean;
107 public idTagsCache
: IdTagsCache
;
108 public automaticTransactionGenerator
!: AutomaticTransactionGenerator
| undefined;
109 public ocppConfiguration
!: ChargingStationOcppConfiguration
| undefined;
110 public wsConnection
!: WebSocket
| null;
111 public readonly connectors
: Map
<number, ConnectorStatus
>;
112 public readonly evses
: Map
<number, EvseStatus
>;
113 public readonly requests
: Map
<string, CachedRequest
>;
114 public performanceStatistics
!: PerformanceStatistics
| undefined;
115 public heartbeatSetInterval
!: NodeJS
.Timeout
;
116 public ocppRequestService
!: OCPPRequestService
;
117 public bootNotificationRequest
!: BootNotificationRequest
;
118 public bootNotificationResponse
!: BootNotificationResponse
| undefined;
119 public powerDivider
!: number;
120 private stopping
: boolean;
121 private configurationFile
!: string;
122 private configurationFileHash
!: string;
123 private connectorsConfigurationHash
!: string;
124 private evsesConfigurationHash
!: string;
125 private ocppIncomingRequestService
!: OCPPIncomingRequestService
;
126 private readonly messageBuffer
: Set
<string>;
127 private configuredSupervisionUrl
!: URL
;
128 private wsConnectionRestarted
: boolean;
129 private autoReconnectRetryCount
: number;
130 private templateFileWatcher
!: fs
.FSWatcher
| undefined;
131 private readonly sharedLRUCache
: SharedLRUCache
;
132 private webSocketPingSetInterval
!: NodeJS
.Timeout
;
133 private readonly chargingStationWorkerBroadcastChannel
: ChargingStationWorkerBroadcastChannel
;
135 constructor(index
: number, templateFile
: string) {
136 this.started
= false;
137 this.starting
= false;
138 this.stopping
= false;
139 this.wsConnectionRestarted
= false;
140 this.autoReconnectRetryCount
= 0;
142 this.templateFile
= templateFile
;
143 this.connectors
= new Map
<number, ConnectorStatus
>();
144 this.evses
= new Map
<number, EvseStatus
>();
145 this.requests
= new Map
<string, CachedRequest
>();
146 this.messageBuffer
= new Set
<string>();
147 this.sharedLRUCache
= SharedLRUCache
.getInstance();
148 this.idTagsCache
= IdTagsCache
.getInstance();
149 this.chargingStationWorkerBroadcastChannel
= new ChargingStationWorkerBroadcastChannel(this);
154 private get
wsConnectionUrl(): URL
{
157 this.getSupervisionUrlOcppConfiguration() &&
158 Utils.isNotEmptyString(this.getSupervisionUrlOcppKey())
159 ? ChargingStationConfigurationUtils.getConfigurationKey(
161 this.getSupervisionUrlOcppKey()
163 : this.configuredSupervisionUrl.href
164 }/${this.stationInfo.chargingStationId}`
168 public logPrefix
= (): string => {
169 return Utils
.logPrefix(
171 (Utils.isNotEmptyString(this?.stationInfo?.chargingStationId)
172 ? this?.stationInfo?.chargingStationId
173 : ChargingStationUtils.getChargingStationId(this.index, this.getTemplateFromFile())) ??
174 'Error at building log prefix'
179 public hasIdTags(): boolean {
180 const idTagsFile
= ChargingStationUtils
.getIdTagsFile(this.stationInfo
);
181 return Utils
.isNotEmptyArray(this.idTagsCache
.getIdTags(idTagsFile
));
184 public getEnableStatistics(): boolean {
185 return this.stationInfo
.enableStatistics
?? false;
188 public getMustAuthorizeAtRemoteStart(): boolean {
189 return this.stationInfo
.mustAuthorizeAtRemoteStart
?? true;
192 public getPayloadSchemaValidation(): boolean {
193 return this.stationInfo
.payloadSchemaValidation
?? true;
196 public getNumberOfPhases(stationInfo
?: ChargingStationInfo
): number | undefined {
197 const localStationInfo
: ChargingStationInfo
= stationInfo
?? this.stationInfo
;
198 switch (this.getCurrentOutType(stationInfo
)) {
200 return !Utils
.isUndefined(localStationInfo
.numberOfPhases
)
201 ? localStationInfo
.numberOfPhases
208 public isWebSocketConnectionOpened(): boolean {
209 return this?.wsConnection
?.readyState
=== WebSocket
.OPEN
;
212 public getRegistrationStatus(): RegistrationStatusEnumType
| undefined {
213 return this?.bootNotificationResponse
?.status;
216 public isInUnknownState(): boolean {
217 return Utils
.isNullOrUndefined(this?.bootNotificationResponse
?.status);
220 public isInPendingState(): boolean {
221 return this?.bootNotificationResponse
?.status === RegistrationStatusEnumType
.PENDING
;
224 public isInAcceptedState(): boolean {
225 return this?.bootNotificationResponse
?.status === RegistrationStatusEnumType
.ACCEPTED
;
228 public isInRejectedState(): boolean {
229 return this?.bootNotificationResponse
?.status === RegistrationStatusEnumType
.REJECTED
;
232 public isRegistered(): boolean {
234 this.isInUnknownState() === false &&
235 (this.isInAcceptedState() === true || this.isInPendingState() === true)
239 public isChargingStationAvailable(): boolean {
240 return this.getConnectorStatus(0)?.availability
=== AvailabilityType
.Operative
;
243 public isConnectorAvailable(id
: number): boolean {
244 return id
> 0 && this.getConnectorStatus(id
)?.availability
=== AvailabilityType
.Operative
;
247 public getNumberOfConnectors(): number {
248 return this.connectors
.get(0) ? this.connectors
.size
- 1 : this.connectors
.size
;
251 public getConnectorStatus(id
: number): ConnectorStatus
| undefined {
252 return this.connectors
.get(id
);
255 public getCurrentOutType(stationInfo
?: ChargingStationInfo
): CurrentType
{
256 return (stationInfo
?? this.stationInfo
)?.currentOutType
?? CurrentType
.AC
;
259 public getOcppStrictCompliance(): boolean {
260 return this.stationInfo
?.ocppStrictCompliance
?? false;
263 public getVoltageOut(stationInfo
?: ChargingStationInfo
): number | undefined {
264 const defaultVoltageOut
= ChargingStationUtils
.getDefaultVoltageOut(
265 this.getCurrentOutType(stationInfo
),
269 const localStationInfo
: ChargingStationInfo
= stationInfo
?? this.stationInfo
;
270 return !Utils
.isUndefined(localStationInfo
.voltageOut
)
271 ? localStationInfo
.voltageOut
275 public getMaximumPower(stationInfo
?: ChargingStationInfo
): number {
276 const localStationInfo
= stationInfo
?? this.stationInfo
;
277 return (localStationInfo
['maxPower'] as number) ?? localStationInfo
.maximumPower
;
280 public getConnectorMaximumAvailablePower(connectorId
: number): number {
281 let connectorAmperageLimitationPowerLimit
: number;
283 !Utils
.isNullOrUndefined(this.getAmperageLimitation()) &&
284 this.getAmperageLimitation() < this.stationInfo
?.maximumAmperage
286 connectorAmperageLimitationPowerLimit
=
287 (this.getCurrentOutType() === CurrentType
.AC
288 ? ACElectricUtils
.powerTotal(
289 this.getNumberOfPhases(),
290 this.getVoltageOut(),
291 this.getAmperageLimitation() * this.getNumberOfConnectors()
293 : DCElectricUtils
.power(this.getVoltageOut(), this.getAmperageLimitation())) /
296 const connectorMaximumPower
= this.getMaximumPower() / this.powerDivider
;
297 const connectorChargingProfilesPowerLimit
=
298 ChargingStationUtils
.getChargingStationConnectorChargingProfilesPowerLimit(this, connectorId
);
300 isNaN(connectorMaximumPower
) ? Infinity : connectorMaximumPower
,
301 isNaN(connectorAmperageLimitationPowerLimit
)
303 : connectorAmperageLimitationPowerLimit
,
304 isNaN(connectorChargingProfilesPowerLimit
) ? Infinity : connectorChargingProfilesPowerLimit
308 public getTransactionIdTag(transactionId
: number): string | undefined {
309 for (const connectorId
of this.connectors
.keys()) {
312 this.getConnectorStatus(connectorId
)?.transactionId
=== transactionId
314 return this.getConnectorStatus(connectorId
)?.transactionIdTag
;
319 public getOutOfOrderEndMeterValues(): boolean {
320 return this.stationInfo
?.outOfOrderEndMeterValues
?? false;
323 public getBeginEndMeterValues(): boolean {
324 return this.stationInfo
?.beginEndMeterValues
?? false;
327 public getMeteringPerTransaction(): boolean {
328 return this.stationInfo
?.meteringPerTransaction
?? true;
331 public getTransactionDataMeterValues(): boolean {
332 return this.stationInfo
?.transactionDataMeterValues
?? false;
335 public getMainVoltageMeterValues(): boolean {
336 return this.stationInfo
?.mainVoltageMeterValues
?? true;
339 public getPhaseLineToLineVoltageMeterValues(): boolean {
340 return this.stationInfo
?.phaseLineToLineVoltageMeterValues
?? false;
343 public getCustomValueLimitationMeterValues(): boolean {
344 return this.stationInfo
?.customValueLimitationMeterValues
?? true;
347 public getConnectorIdByTransactionId(transactionId
: number): number | undefined {
348 for (const connectorId
of this.connectors
.keys()) {
351 this.getConnectorStatus(connectorId
)?.transactionId
=== transactionId
358 public getEnergyActiveImportRegisterByTransactionId(
359 transactionId
: number,
362 return this.getEnergyActiveImportRegister(
363 this.getConnectorStatus(this.getConnectorIdByTransactionId(transactionId
)),
368 public getEnergyActiveImportRegisterByConnectorId(connectorId
: number, rounded
= false): number {
369 return this.getEnergyActiveImportRegister(this.getConnectorStatus(connectorId
), rounded
);
372 public getAuthorizeRemoteTxRequests(): boolean {
373 const authorizeRemoteTxRequests
= ChargingStationConfigurationUtils
.getConfigurationKey(
375 StandardParametersKey
.AuthorizeRemoteTxRequests
377 return authorizeRemoteTxRequests
378 ? Utils
.convertToBoolean(authorizeRemoteTxRequests
.value
)
382 public getLocalAuthListEnabled(): boolean {
383 const localAuthListEnabled
= ChargingStationConfigurationUtils
.getConfigurationKey(
385 StandardParametersKey
.LocalAuthListEnabled
387 return localAuthListEnabled
? Utils
.convertToBoolean(localAuthListEnabled
.value
) : false;
390 public getHeartbeatInterval(): number {
391 const HeartbeatInterval
= ChargingStationConfigurationUtils
.getConfigurationKey(
393 StandardParametersKey
.HeartbeatInterval
395 if (HeartbeatInterval
) {
396 return Utils
.convertToInt(HeartbeatInterval
.value
) * 1000;
398 const HeartBeatInterval
= ChargingStationConfigurationUtils
.getConfigurationKey(
400 StandardParametersKey
.HeartBeatInterval
402 if (HeartBeatInterval
) {
403 return Utils
.convertToInt(HeartBeatInterval
.value
) * 1000;
405 this.stationInfo
?.autoRegister
=== false &&
407 `${this.logPrefix()} Heartbeat interval configuration key not set, using default value: ${
408 Constants.DEFAULT_HEARTBEAT_INTERVAL
411 return Constants
.DEFAULT_HEARTBEAT_INTERVAL
;
414 public setSupervisionUrl(url
: string): void {
416 this.getSupervisionUrlOcppConfiguration() &&
417 Utils
.isNotEmptyString(this.getSupervisionUrlOcppKey())
419 ChargingStationConfigurationUtils
.setConfigurationKeyValue(
421 this.getSupervisionUrlOcppKey(),
425 this.stationInfo
.supervisionUrls
= url
;
426 this.saveStationInfo();
427 this.configuredSupervisionUrl
= this.getConfiguredSupervisionUrl();
431 public startHeartbeat(): void {
432 if (this.getHeartbeatInterval() > 0 && !this.heartbeatSetInterval
) {
433 this.heartbeatSetInterval
= setInterval(() => {
434 this.ocppRequestService
435 .requestHandler
<HeartbeatRequest
, HeartbeatResponse
>(this, RequestCommand
.HEARTBEAT
)
438 `${this.logPrefix()} Error while sending '${RequestCommand.HEARTBEAT}':`,
442 }, this.getHeartbeatInterval());
444 `${this.logPrefix()} Heartbeat started every ${Utils.formatDurationMilliSeconds(
445 this.getHeartbeatInterval()
448 } else if (this.heartbeatSetInterval
) {
450 `${this.logPrefix()} Heartbeat already started every ${Utils.formatDurationMilliSeconds(
451 this.getHeartbeatInterval()
456 `${this.logPrefix()} Heartbeat interval set to ${this.getHeartbeatInterval()}, not starting the heartbeat`
461 public restartHeartbeat(): void {
463 this.stopHeartbeat();
465 this.startHeartbeat();
468 public restartWebSocketPing(): void {
469 // Stop WebSocket ping
470 this.stopWebSocketPing();
471 // Start WebSocket ping
472 this.startWebSocketPing();
475 public startMeterValues(connectorId
: number, interval
: number): void {
476 if (connectorId
=== 0) {
478 `${this.logPrefix()} Trying to start MeterValues on connector id ${connectorId.toString()}`
482 if (!this.getConnectorStatus(connectorId
)) {
484 `${this.logPrefix()} Trying to start MeterValues on non existing connector id ${connectorId.toString()}`
488 if (this.getConnectorStatus(connectorId
)?.transactionStarted
=== false) {
490 `${this.logPrefix()} Trying to start MeterValues on connector id ${connectorId} with no transaction started`
494 this.getConnectorStatus(connectorId
)?.transactionStarted
=== true &&
495 Utils
.isNullOrUndefined(this.getConnectorStatus(connectorId
)?.transactionId
)
498 `${this.logPrefix()} Trying to start MeterValues on connector id ${connectorId} with no transaction id`
503 this.getConnectorStatus(connectorId
).transactionSetInterval
= setInterval(() => {
504 // FIXME: Implement OCPP version agnostic helpers
505 const meterValue
: MeterValue
= OCPP16ServiceUtils
.buildMeterValue(
508 this.getConnectorStatus(connectorId
).transactionId
,
511 this.ocppRequestService
512 .requestHandler
<MeterValuesRequest
, MeterValuesResponse
>(
514 RequestCommand
.METER_VALUES
,
517 transactionId
: this.getConnectorStatus(connectorId
)?.transactionId
,
518 meterValue
: [meterValue
],
523 `${this.logPrefix()} Error while sending '${RequestCommand.METER_VALUES}':`,
530 `${this.logPrefix()} Charging station ${
531 StandardParametersKey.MeterValueSampleInterval
532 } configuration set to ${interval}, not sending MeterValues`
537 public stopMeterValues(connectorId
: number) {
538 if (this.getConnectorStatus(connectorId
)?.transactionSetInterval
) {
539 clearInterval(this.getConnectorStatus(connectorId
)?.transactionSetInterval
);
543 public start(): void {
544 if (this.started
=== false) {
545 if (this.starting
=== false) {
546 this.starting
= true;
547 if (this.getEnableStatistics() === true) {
548 this.performanceStatistics
?.start();
550 this.openWSConnection();
551 // Monitor charging station template file
552 this.templateFileWatcher
= FileUtils
.watchJsonFile(
554 FileType
.ChargingStationTemplate
,
557 (event
, filename
): void => {
558 if (Utils
.isNotEmptyString(filename
) && event
=== 'change') {
561 `${this.logPrefix()} ${FileType.ChargingStationTemplate} ${
563 } file have changed, reload`
565 this.sharedLRUCache
.deleteChargingStationTemplate(this.stationInfo
?.templateHash
);
569 this.stopAutomaticTransactionGenerator();
571 this.getAutomaticTransactionGeneratorConfigurationFromTemplate()?.enable
=== true
573 this.startAutomaticTransactionGenerator();
575 if (this.getEnableStatistics() === true) {
576 this.performanceStatistics
?.restart();
578 this.performanceStatistics
?.stop();
580 // FIXME?: restart heartbeat and WebSocket ping when their interval values have changed
583 `${this.logPrefix()} ${FileType.ChargingStationTemplate} file monitoring error:`,
591 parentPort
?.postMessage(MessageChannelUtils
.buildStartedMessage(this));
592 this.starting
= false;
594 logger
.warn(`${this.logPrefix()} Charging station is already starting...`);
597 logger
.warn(`${this.logPrefix()} Charging station is already started...`);
601 public async stop(reason
?: StopTransactionReason
): Promise
<void> {
602 if (this.started
=== true) {
603 if (this.stopping
=== false) {
604 this.stopping
= true;
605 await this.stopMessageSequence(reason
);
606 this.closeWSConnection();
607 if (this.getEnableStatistics() === true) {
608 this.performanceStatistics
?.stop();
610 this.sharedLRUCache
.deleteChargingStationConfiguration(this.configurationFileHash
);
611 this.templateFileWatcher
?.close();
612 this.sharedLRUCache
.deleteChargingStationTemplate(this.stationInfo
?.templateHash
);
613 delete this.bootNotificationResponse
;
614 this.started
= false;
615 parentPort
?.postMessage(MessageChannelUtils
.buildStoppedMessage(this));
616 this.stopping
= false;
618 logger
.warn(`${this.logPrefix()} Charging station is already stopping...`);
621 logger
.warn(`${this.logPrefix()} Charging station is already stopped...`);
625 public async reset(reason
?: StopTransactionReason
): Promise
<void> {
626 await this.stop(reason
);
627 await Utils
.sleep(this.stationInfo
.resetTime
);
632 public saveOcppConfiguration(): void {
633 if (this.getOcppPersistentConfiguration()) {
634 this.saveConfiguration();
638 public hasFeatureProfile(featureProfile
: SupportedFeatureProfiles
): boolean | undefined {
639 return ChargingStationConfigurationUtils
.getConfigurationKey(
641 StandardParametersKey
.SupportedFeatureProfiles
642 )?.value
?.includes(featureProfile
);
645 public bufferMessage(message
: string): void {
646 this.messageBuffer
.add(message
);
649 public openWSConnection(
650 options
: WsOptions
= this.stationInfo
?.wsOptions
?? {},
651 params
: { closeOpened
?: boolean; terminateOpened
?: boolean } = {
653 terminateOpened
: false,
656 options
.handshakeTimeout
= options
?.handshakeTimeout
?? this.getConnectionTimeout() * 1000;
657 params
.closeOpened
= params
?.closeOpened
?? false;
658 params
.terminateOpened
= params
?.terminateOpened
?? false;
659 if (this.started
=== false && this.starting
=== false) {
661 `${this.logPrefix()} Cannot open OCPP connection to URL ${this.wsConnectionUrl.toString()} on stopped charging station`
666 !Utils
.isNullOrUndefined(this.stationInfo
.supervisionUser
) &&
667 !Utils
.isNullOrUndefined(this.stationInfo
.supervisionPassword
)
669 options
.auth
= `${this.stationInfo.supervisionUser}:${this.stationInfo.supervisionPassword}`;
671 if (params
?.closeOpened
) {
672 this.closeWSConnection();
674 if (params
?.terminateOpened
) {
675 this.terminateWSConnection();
678 if (this.isWebSocketConnectionOpened() === true) {
680 `${this.logPrefix()} OCPP connection to URL ${this.wsConnectionUrl.toString()} is already opened`
686 `${this.logPrefix()} Open OCPP connection to URL ${this.wsConnectionUrl.toString()}`
689 this.wsConnection
= new WebSocket(
690 this.wsConnectionUrl
,
691 `ocpp${this.stationInfo.ocppVersion ?? OCPPVersion.VERSION_16}`,
695 // Handle WebSocket message
696 this.wsConnection
.on(
698 this.onMessage
.bind(this) as (this: WebSocket
, data
: RawData
, isBinary
: boolean) => void
700 // Handle WebSocket error
701 this.wsConnection
.on(
703 this.onError
.bind(this) as (this: WebSocket
, error
: Error) => void
705 // Handle WebSocket close
706 this.wsConnection
.on(
708 this.onClose
.bind(this) as (this: WebSocket
, code
: number, reason
: Buffer
) => void
710 // Handle WebSocket open
711 this.wsConnection
.on('open', this.onOpen
.bind(this) as (this: WebSocket
) => void);
712 // Handle WebSocket ping
713 this.wsConnection
.on('ping', this.onPing
.bind(this) as (this: WebSocket
, data
: Buffer
) => void);
714 // Handle WebSocket pong
715 this.wsConnection
.on('pong', this.onPong
.bind(this) as (this: WebSocket
, data
: Buffer
) => void);
718 public closeWSConnection(): void {
719 if (this.isWebSocketConnectionOpened() === true) {
720 this.wsConnection
?.close();
721 this.wsConnection
= null;
725 public startAutomaticTransactionGenerator(
726 connectorIds
?: number[],
727 automaticTransactionGeneratorConfiguration
?: AutomaticTransactionGeneratorConfiguration
729 this.automaticTransactionGenerator
= AutomaticTransactionGenerator
.getInstance(
730 automaticTransactionGeneratorConfiguration
??
731 this.getAutomaticTransactionGeneratorConfigurationFromTemplate(),
734 if (Utils
.isNotEmptyArray(connectorIds
)) {
735 for (const connectorId
of connectorIds
) {
736 this.automaticTransactionGenerator
?.startConnector(connectorId
);
739 this.automaticTransactionGenerator
?.start();
741 parentPort
?.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
744 public stopAutomaticTransactionGenerator(connectorIds
?: number[]): void {
745 if (Utils
.isNotEmptyArray(connectorIds
)) {
746 for (const connectorId
of connectorIds
) {
747 this.automaticTransactionGenerator
?.stopConnector(connectorId
);
750 this.automaticTransactionGenerator
?.stop();
752 parentPort
?.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
755 public async stopTransactionOnConnector(
757 reason
= StopTransactionReason
.NONE
758 ): Promise
<StopTransactionResponse
> {
759 const transactionId
= this.getConnectorStatus(connectorId
)?.transactionId
;
761 this.getBeginEndMeterValues() === true &&
762 this.getOcppStrictCompliance() === true &&
763 this.getOutOfOrderEndMeterValues() === false
765 // FIXME: Implement OCPP version agnostic helpers
766 const transactionEndMeterValue
= OCPP16ServiceUtils
.buildTransactionEndMeterValue(
769 this.getEnergyActiveImportRegisterByTransactionId(transactionId
)
771 await this.ocppRequestService
.requestHandler
<MeterValuesRequest
, MeterValuesResponse
>(
773 RequestCommand
.METER_VALUES
,
777 meterValue
: [transactionEndMeterValue
],
781 return this.ocppRequestService
.requestHandler
<StopTransactionRequest
, StopTransactionResponse
>(
783 RequestCommand
.STOP_TRANSACTION
,
786 meterStop
: this.getEnergyActiveImportRegisterByTransactionId(transactionId
, true),
792 private flushMessageBuffer(): void {
793 if (this.messageBuffer
.size
> 0) {
794 for (const message
of this.messageBuffer
.values()) {
796 let commandName
: RequestCommand
;
797 const [messageType
] = JSON
.parse(message
) as OutgoingRequest
| Response
| ErrorResponse
;
798 const isRequest
= messageType
=== MessageType
.CALL_MESSAGE
;
800 [, , commandName
] = JSON
.parse(message
) as OutgoingRequest
;
801 beginId
= PerformanceStatistics
.beginMeasure(commandName
);
803 this.wsConnection
?.send(message
);
804 isRequest
&& PerformanceStatistics
.endMeasure(commandName
, beginId
);
806 `${this.logPrefix()} >> Buffered ${OCPPServiceUtils.getMessageTypeString(
808 )} payload sent: ${message}`
810 this.messageBuffer
.delete(message
);
815 private getSupervisionUrlOcppConfiguration(): boolean {
816 return this.stationInfo
.supervisionUrlOcppConfiguration
?? false;
819 private getSupervisionUrlOcppKey(): string {
820 return this.stationInfo
.supervisionUrlOcppKey
?? VendorParametersKey
.ConnectionUrl
;
823 private getTemplateFromFile(): ChargingStationTemplate
| undefined {
824 let template
: ChargingStationTemplate
;
826 if (this.sharedLRUCache
.hasChargingStationTemplate(this.stationInfo
?.templateHash
)) {
827 template
= this.sharedLRUCache
.getChargingStationTemplate(this.stationInfo
.templateHash
);
829 const measureId
= `${FileType.ChargingStationTemplate} read`;
830 const beginId
= PerformanceStatistics
.beginMeasure(measureId
);
831 template
= JSON
.parse(
832 fs
.readFileSync(this.templateFile
, 'utf8')
833 ) as ChargingStationTemplate
;
834 PerformanceStatistics
.endMeasure(measureId
, beginId
);
835 template
.templateHash
= crypto
836 .createHash(Constants
.DEFAULT_HASH_ALGORITHM
)
837 .update(JSON
.stringify(template
))
839 this.sharedLRUCache
.setChargingStationTemplate(template
);
842 FileUtils
.handleFileException(
844 FileType
.ChargingStationTemplate
,
845 error
as NodeJS
.ErrnoException
,
852 private getStationInfoFromTemplate(): ChargingStationInfo
{
853 const stationTemplate
: ChargingStationTemplate
| undefined = this.getTemplateFromFile();
854 if (Utils
.isNullOrUndefined(stationTemplate
)) {
855 const errorMsg
= `Failed to read charging station template file ${this.templateFile}`;
856 logger
.error(`${this.logPrefix()} ${errorMsg}`);
857 throw new BaseError(errorMsg
);
859 if (Utils
.isEmptyObject(stationTemplate
)) {
860 const errorMsg
= `Empty charging station information from template file ${this.templateFile}`;
861 logger
.error(`${this.logPrefix()} ${errorMsg}`);
862 throw new BaseError(errorMsg
);
864 ChargingStationUtils
.warnTemplateKeysDeprecation(
869 const stationInfo
: ChargingStationInfo
=
870 ChargingStationUtils
.stationTemplateToStationInfo(stationTemplate
);
871 stationInfo
.hashId
= ChargingStationUtils
.getHashId(this.index
, stationTemplate
);
872 stationInfo
.chargingStationId
= ChargingStationUtils
.getChargingStationId(
876 stationInfo
.ocppVersion
= stationTemplate
?.ocppVersion
?? OCPPVersion
.VERSION_16
;
877 ChargingStationUtils
.createSerialNumber(stationTemplate
, stationInfo
);
878 if (Utils
.isNotEmptyArray(stationTemplate
?.power
)) {
879 stationTemplate
.power
= stationTemplate
.power
as number[];
880 const powerArrayRandomIndex
= Math.floor(Utils
.secureRandom() * stationTemplate
.power
.length
);
881 stationInfo
.maximumPower
=
882 stationTemplate
?.powerUnit
=== PowerUnits
.KILO_WATT
883 ? stationTemplate
.power
[powerArrayRandomIndex
] * 1000
884 : stationTemplate
.power
[powerArrayRandomIndex
];
886 stationTemplate
.power
= stationTemplate
?.power
as number;
887 stationInfo
.maximumPower
=
888 stationTemplate
?.powerUnit
=== PowerUnits
.KILO_WATT
889 ? stationTemplate
.power
* 1000
890 : stationTemplate
.power
;
892 stationInfo
.firmwareVersionPattern
=
893 stationTemplate
?.firmwareVersionPattern
?? Constants
.SEMVER_PATTERN
;
895 Utils
.isNotEmptyString(stationInfo
.firmwareVersion
) &&
896 new RegExp(stationInfo
.firmwareVersionPattern
).test(stationInfo
.firmwareVersion
) === false
899 `${this.logPrefix()} Firmware version '${stationInfo.firmwareVersion}' in template file ${
901 } does not match firmware version pattern '${stationInfo.firmwareVersionPattern}'`
904 stationInfo
.firmwareUpgrade
= merge
<FirmwareUpgrade
>(
911 stationTemplate
?.firmwareUpgrade
?? {}
913 stationInfo
.resetTime
= !Utils
.isNullOrUndefined(stationTemplate
?.resetTime
)
914 ? stationTemplate
.resetTime
* 1000
915 : Constants
.CHARGING_STATION_DEFAULT_RESET_TIME
;
916 // Initialize evses or connectors if needed (FIXME: should be factored out)
917 this.initializeConnectorsOrEvses(stationInfo
);
918 stationInfo
.maximumAmperage
= this.getMaximumAmperage(stationInfo
);
919 ChargingStationUtils
.createStationInfoHash(stationInfo
);
923 private getStationInfoFromFile(): ChargingStationInfo
| undefined {
924 let stationInfo
: ChargingStationInfo
| undefined;
925 this.getStationInfoPersistentConfiguration() &&
926 (stationInfo
= this.getConfigurationFromFile()?.stationInfo
);
927 stationInfo
&& ChargingStationUtils
.createStationInfoHash(stationInfo
);
931 private getStationInfo(): ChargingStationInfo
{
932 const stationInfoFromTemplate
: ChargingStationInfo
= this.getStationInfoFromTemplate();
933 const stationInfoFromFile
: ChargingStationInfo
| undefined = this.getStationInfoFromFile();
935 // 1. charging station info from template
936 // 2. charging station info from configuration file
937 // 3. charging station info attribute
938 if (stationInfoFromFile
?.templateHash
=== stationInfoFromTemplate
.templateHash
) {
939 if (this.stationInfo
?.infoHash
=== stationInfoFromFile
?.infoHash
) {
940 return this.stationInfo
;
942 return stationInfoFromFile
;
944 stationInfoFromFile
&&
945 ChargingStationUtils
.propagateSerialNumber(
946 this.getTemplateFromFile(),
948 stationInfoFromTemplate
950 return stationInfoFromTemplate
;
953 private saveStationInfo(): void {
954 if (this.getStationInfoPersistentConfiguration()) {
955 this.saveConfiguration();
959 private getOcppPersistentConfiguration(): boolean {
960 return this.stationInfo
?.ocppPersistentConfiguration
?? true;
963 private getStationInfoPersistentConfiguration(): boolean {
964 return this.stationInfo
?.stationInfoPersistentConfiguration
?? true;
967 private handleUnsupportedVersion(version
: OCPPVersion
) {
968 const errMsg
= `Unsupported protocol version '${version}' configured in template file ${this.templateFile}`;
969 logger
.error(`${this.logPrefix()} ${errMsg}`);
970 throw new BaseError(errMsg
);
973 private initialize(): void {
974 this.configurationFile
= path
.join(
975 path
.dirname(this.templateFile
.replace('station-templates', 'configurations')),
976 `${ChargingStationUtils.getHashId(this.index, this.getTemplateFromFile())}.json`
978 this.stationInfo
= this.getStationInfo();
980 this.stationInfo
.firmwareStatus
=== FirmwareStatus
.Installing
&&
981 Utils
.isNotEmptyString(this.stationInfo
.firmwareVersion
) &&
982 Utils
.isNotEmptyString(this.stationInfo
.firmwareVersionPattern
)
984 const patternGroup
: number | undefined =
985 this.stationInfo
.firmwareUpgrade
?.versionUpgrade
?.patternGroup
??
986 this.stationInfo
.firmwareVersion
?.split('.').length
;
987 const match
= this.stationInfo
?.firmwareVersion
988 ?.match(new RegExp(this.stationInfo
.firmwareVersionPattern
))
989 ?.slice(1, patternGroup
+ 1);
990 const patchLevelIndex
= match
.length
- 1;
991 match
[patchLevelIndex
] = (
992 Utils
.convertToInt(match
[patchLevelIndex
]) +
993 this.stationInfo
.firmwareUpgrade
?.versionUpgrade
?.step
995 this.stationInfo
.firmwareVersion
= match
?.join('.');
997 this.saveStationInfo();
998 // Avoid duplication of connectors or evses related information in RAM
999 delete this.stationInfo
?.Connectors
;
1000 delete this.stationInfo
?.Evses
;
1001 this.configuredSupervisionUrl
= this.getConfiguredSupervisionUrl();
1002 if (this.getEnableStatistics() === true) {
1003 this.performanceStatistics
= PerformanceStatistics
.getInstance(
1004 this.stationInfo
.hashId
,
1005 this.stationInfo
.chargingStationId
,
1006 this.configuredSupervisionUrl
1009 this.bootNotificationRequest
= ChargingStationUtils
.createBootNotificationRequest(
1012 this.powerDivider
= this.getPowerDivider();
1013 // OCPP configuration
1014 this.ocppConfiguration
= this.getOcppConfiguration();
1015 this.initializeOcppConfiguration();
1016 this.initializeOcppServices();
1017 if (this.stationInfo
?.autoRegister
=== true) {
1018 this.bootNotificationResponse
= {
1019 currentTime
: new Date(),
1020 interval
: this.getHeartbeatInterval() / 1000,
1021 status: RegistrationStatusEnumType
.ACCEPTED
,
1026 private initializeOcppServices(): void {
1027 const ocppVersion
= this.stationInfo
.ocppVersion
?? OCPPVersion
.VERSION_16
;
1028 switch (ocppVersion
) {
1029 case OCPPVersion
.VERSION_16
:
1030 this.ocppIncomingRequestService
=
1031 OCPP16IncomingRequestService
.getInstance
<OCPP16IncomingRequestService
>();
1032 this.ocppRequestService
= OCPP16RequestService
.getInstance
<OCPP16RequestService
>(
1033 OCPP16ResponseService
.getInstance
<OCPP16ResponseService
>()
1036 case OCPPVersion
.VERSION_20
:
1037 case OCPPVersion
.VERSION_201
:
1038 this.ocppIncomingRequestService
=
1039 OCPP20IncomingRequestService
.getInstance
<OCPP20IncomingRequestService
>();
1040 this.ocppRequestService
= OCPP20RequestService
.getInstance
<OCPP20RequestService
>(
1041 OCPP20ResponseService
.getInstance
<OCPP20ResponseService
>()
1045 this.handleUnsupportedVersion(ocppVersion
);
1050 private initializeOcppConfiguration(): void {
1052 !ChargingStationConfigurationUtils
.getConfigurationKey(
1054 StandardParametersKey
.HeartbeatInterval
1057 ChargingStationConfigurationUtils
.addConfigurationKey(
1059 StandardParametersKey
.HeartbeatInterval
,
1064 !ChargingStationConfigurationUtils
.getConfigurationKey(
1066 StandardParametersKey
.HeartBeatInterval
1069 ChargingStationConfigurationUtils
.addConfigurationKey(
1071 StandardParametersKey
.HeartBeatInterval
,
1077 this.getSupervisionUrlOcppConfiguration() &&
1078 Utils
.isNotEmptyString(this.getSupervisionUrlOcppKey()) &&
1079 !ChargingStationConfigurationUtils
.getConfigurationKey(this, this.getSupervisionUrlOcppKey())
1081 ChargingStationConfigurationUtils
.addConfigurationKey(
1083 this.getSupervisionUrlOcppKey(),
1084 this.configuredSupervisionUrl
.href
,
1088 !this.getSupervisionUrlOcppConfiguration() &&
1089 Utils
.isNotEmptyString(this.getSupervisionUrlOcppKey()) &&
1090 ChargingStationConfigurationUtils
.getConfigurationKey(this, this.getSupervisionUrlOcppKey())
1092 ChargingStationConfigurationUtils
.deleteConfigurationKey(
1094 this.getSupervisionUrlOcppKey(),
1099 Utils
.isNotEmptyString(this.stationInfo
?.amperageLimitationOcppKey
) &&
1100 !ChargingStationConfigurationUtils
.getConfigurationKey(
1102 this.stationInfo
.amperageLimitationOcppKey
1105 ChargingStationConfigurationUtils
.addConfigurationKey(
1107 this.stationInfo
.amperageLimitationOcppKey
,
1109 this.stationInfo
.maximumAmperage
*
1110 ChargingStationUtils
.getAmperageLimitationUnitDivider(this.stationInfo
)
1115 !ChargingStationConfigurationUtils
.getConfigurationKey(
1117 StandardParametersKey
.SupportedFeatureProfiles
1120 ChargingStationConfigurationUtils
.addConfigurationKey(
1122 StandardParametersKey
.SupportedFeatureProfiles
,
1123 `${SupportedFeatureProfiles.Core},${SupportedFeatureProfiles.FirmwareManagement},${SupportedFeatureProfiles.LocalAuthListManagement},${SupportedFeatureProfiles.SmartCharging},${SupportedFeatureProfiles.RemoteTrigger}`
1126 ChargingStationConfigurationUtils
.addConfigurationKey(
1128 StandardParametersKey
.NumberOfConnectors
,
1129 this.getNumberOfConnectors().toString(),
1134 !ChargingStationConfigurationUtils
.getConfigurationKey(
1136 StandardParametersKey
.MeterValuesSampledData
1139 ChargingStationConfigurationUtils
.addConfigurationKey(
1141 StandardParametersKey
.MeterValuesSampledData
,
1142 MeterValueMeasurand
.ENERGY_ACTIVE_IMPORT_REGISTER
1146 !ChargingStationConfigurationUtils
.getConfigurationKey(
1148 StandardParametersKey
.ConnectorPhaseRotation
1151 const connectorPhaseRotation
= [];
1152 for (const connectorId
of this.connectors
.keys()) {
1154 if (connectorId
=== 0 && this.getNumberOfPhases() === 0) {
1155 connectorPhaseRotation
.push(`${connectorId}.${ConnectorPhaseRotation.RST}`);
1156 } else if (connectorId
> 0 && this.getNumberOfPhases() === 0) {
1157 connectorPhaseRotation
.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`);
1159 } else if (connectorId
> 0 && this.getNumberOfPhases() === 1) {
1160 connectorPhaseRotation
.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`);
1161 } else if (connectorId
> 0 && this.getNumberOfPhases() === 3) {
1162 connectorPhaseRotation
.push(`${connectorId}.${ConnectorPhaseRotation.RST}`);
1165 ChargingStationConfigurationUtils
.addConfigurationKey(
1167 StandardParametersKey
.ConnectorPhaseRotation
,
1168 connectorPhaseRotation
.toString()
1172 !ChargingStationConfigurationUtils
.getConfigurationKey(
1174 StandardParametersKey
.AuthorizeRemoteTxRequests
1177 ChargingStationConfigurationUtils
.addConfigurationKey(
1179 StandardParametersKey
.AuthorizeRemoteTxRequests
,
1184 !ChargingStationConfigurationUtils
.getConfigurationKey(
1186 StandardParametersKey
.LocalAuthListEnabled
1188 ChargingStationConfigurationUtils
.getConfigurationKey(
1190 StandardParametersKey
.SupportedFeatureProfiles
1191 )?.value
?.includes(SupportedFeatureProfiles
.LocalAuthListManagement
)
1193 ChargingStationConfigurationUtils
.addConfigurationKey(
1195 StandardParametersKey
.LocalAuthListEnabled
,
1200 !ChargingStationConfigurationUtils
.getConfigurationKey(
1202 StandardParametersKey
.ConnectionTimeOut
1205 ChargingStationConfigurationUtils
.addConfigurationKey(
1207 StandardParametersKey
.ConnectionTimeOut
,
1208 Constants
.DEFAULT_CONNECTION_TIMEOUT
.toString()
1211 this.saveOcppConfiguration();
1214 private initializeConnectorsOrEvses(stationInfo
: ChargingStationInfo
) {
1215 if (stationInfo
?.Connectors
&& !stationInfo
?.Evses
) {
1216 this.initializeConnectors(stationInfo
);
1217 } else if (stationInfo
?.Evses
&& !stationInfo
?.Connectors
) {
1218 this.initializeEvses(stationInfo
);
1219 } else if (stationInfo
?.Evses
&& stationInfo
?.Connectors
) {
1220 const errorMsg
= `Connectors and evses defined at the same time in template file ${this.templateFile}`;
1221 logger
.error(`${this.logPrefix()} ${errorMsg}`);
1222 throw new BaseError(errorMsg
);
1224 const errorMsg
= `No connectors or evses defined in template file ${this.templateFile}`;
1225 logger
.error(`${this.logPrefix()} ${errorMsg}`);
1226 throw new BaseError(errorMsg
);
1230 private initializeConnectors(stationInfo
: ChargingStationInfo
): void {
1231 if (!stationInfo
?.Connectors
&& this.connectors
.size
=== 0) {
1232 const logMsg
= `No already defined connectors and charging station information from template ${this.templateFile} with no connectors configuration defined`;
1233 logger
.error(`${this.logPrefix()} ${logMsg}`);
1234 throw new BaseError(logMsg
);
1236 if (!stationInfo
?.Connectors
[0]) {
1238 `${this.logPrefix()} Charging station information from template ${
1240 } with no connector id 0 configuration`
1243 if (stationInfo
?.Connectors
) {
1244 const configuredMaxConnectors
=
1245 ChargingStationUtils
.getConfiguredNumberOfConnectors(stationInfo
);
1246 ChargingStationUtils
.checkConfiguredMaxConnectors(
1247 configuredMaxConnectors
,
1251 const connectorsConfigHash
= crypto
1252 .createHash(Constants
.DEFAULT_HASH_ALGORITHM
)
1253 .update(`${JSON.stringify(stationInfo?.Connectors)}${configuredMaxConnectors.toString()}`)
1255 const connectorsConfigChanged
=
1256 this.connectors
?.size
!== 0 && this.connectorsConfigurationHash
!== connectorsConfigHash
;
1257 if (this.connectors
?.size
=== 0 || connectorsConfigChanged
) {
1258 connectorsConfigChanged
&& this.connectors
.clear();
1259 this.connectorsConfigurationHash
= connectorsConfigHash
;
1260 const connectorZeroStatus
= stationInfo
?.Connectors
[0];
1261 // Add connector id 0
1262 if (connectorZeroStatus
&& this.getUseConnectorId0(stationInfo
) === true) {
1263 ChargingStationUtils
.checkStationInfoConnectorStatus(
1265 connectorZeroStatus
,
1269 this.connectors
.set(0, Utils
.cloneObject
<ConnectorStatus
>(connectorZeroStatus
));
1270 this.getConnectorStatus(0).availability
= AvailabilityType
.Operative
;
1271 if (Utils
.isUndefined(this.getConnectorStatus(0)?.chargingProfiles
)) {
1272 this.getConnectorStatus(0).chargingProfiles
= [];
1275 // Add remaining connectors
1276 const templateMaxConnectors
= ChargingStationUtils
.getMaxNumberOfConnectors(
1277 stationInfo
.Connectors
1279 ChargingStationUtils
.checkTemplateMaxConnectors(
1280 templateMaxConnectors
,
1285 configuredMaxConnectors
>
1286 (stationInfo
?.Connectors
[0] ? templateMaxConnectors
- 1 : templateMaxConnectors
) &&
1287 !stationInfo
?.randomConnectors
1290 `${this.logPrefix()} Number of connectors exceeds the number of connector configurations in template ${
1292 }, forcing random connector configurations affectation`
1294 stationInfo
.randomConnectors
= true;
1296 const templateMaxAvailableConnectors
= stationInfo
?.Connectors
[0]
1297 ? templateMaxConnectors
- 1
1298 : templateMaxConnectors
;
1299 if (templateMaxAvailableConnectors
> 0) {
1300 for (let connectorId
= 1; connectorId
<= configuredMaxConnectors
; connectorId
++) {
1301 const templateConnectorId
= stationInfo
?.randomConnectors
1302 ? Utils
.getRandomInteger(templateMaxAvailableConnectors
, 1)
1304 const connectorStatus
= stationInfo
?.Connectors
[templateConnectorId
];
1305 ChargingStationUtils
.checkStationInfoConnectorStatus(
1306 templateConnectorId
,
1311 this.connectors
.set(connectorId
, Utils
.cloneObject
<ConnectorStatus
>(connectorStatus
));
1312 this.getConnectorStatus(connectorId
).availability
= AvailabilityType
.Operative
;
1313 if (Utils
.isUndefined(this.getConnectorStatus(connectorId
)?.chargingProfiles
)) {
1314 this.getConnectorStatus(connectorId
).chargingProfiles
= [];
1316 ChargingStationUtils
.initializeConnectorsMapStatus(this.connectors
, this.logPrefix());
1320 `${this.logPrefix()} Charging station information from template ${
1322 } with no connectors configuration defined, cannot create connectors`
1328 `${this.logPrefix()} Charging station information from template ${
1330 } with no connectors configuration defined, using already defined connectors`
1335 private initializeEvses(stationInfo
: ChargingStationInfo
): void {
1336 if (!stationInfo
?.Evses
&& this.evses
.size
=== 0) {
1337 const logMsg
= `No already defined evses and charging station information from template ${this.templateFile} with no evses configuration defined`;
1338 logger
.error(`${this.logPrefix()} ${logMsg}`);
1339 throw new BaseError(logMsg
);
1341 if (!stationInfo
?.Evses
[0]) {
1343 `${this.logPrefix()} Charging station information from template ${
1345 } with no evse id 0 configuration`
1348 if (stationInfo
?.Evses
) {
1349 const evsesConfigHash
= crypto
1350 .createHash(Constants
.DEFAULT_HASH_ALGORITHM
)
1351 .update(`${JSON.stringify(stationInfo?.Evses)}`)
1353 const evsesConfigChanged
=
1354 this.evses
?.size
!== 0 && this.evsesConfigurationHash
!== evsesConfigHash
;
1355 if (this.evses
?.size
=== 0 || evsesConfigChanged
) {
1356 evsesConfigChanged
&& this.evses
.clear();
1357 this.evsesConfigurationHash
= evsesConfigHash
;
1358 const templateMaxEvses
= ChargingStationUtils
.getMaxNumberOfEvses(stationInfo
?.Evses
);
1359 if (templateMaxEvses
> 0) {
1360 for (const evse
in stationInfo
.Evses
) {
1361 this.evses
.set(Utils
.convertToInt(evse
), {
1362 connectors
: ChargingStationUtils
.buildConnectorsMap(
1363 stationInfo
?.Evses
[evse
]?.Connectors
,
1367 availability
: AvailabilityType
.Operative
,
1369 ChargingStationUtils
.initializeConnectorsMapStatus(
1370 this.evses
.get(Utils
.convertToInt(evse
))?.connectors
,
1376 `${this.logPrefix()} Charging station information from template ${
1378 } with no evses configuration defined, cannot create evses`
1383 `${this.logPrefix()} Charging station information from template ${
1385 } with no evses configuration defined, using already defined evses`
1391 private getConfigurationFromFile(): ChargingStationConfiguration
| undefined {
1392 let configuration
: ChargingStationConfiguration
| undefined;
1393 if (this.configurationFile
&& fs
.existsSync(this.configurationFile
)) {
1395 if (this.sharedLRUCache
.hasChargingStationConfiguration(this.configurationFileHash
)) {
1396 configuration
= this.sharedLRUCache
.getChargingStationConfiguration(
1397 this.configurationFileHash
1400 const measureId
= `${FileType.ChargingStationConfiguration} read`;
1401 const beginId
= PerformanceStatistics
.beginMeasure(measureId
);
1402 configuration
= JSON
.parse(
1403 fs
.readFileSync(this.configurationFile
, 'utf8')
1404 ) as ChargingStationConfiguration
;
1405 PerformanceStatistics
.endMeasure(measureId
, beginId
);
1406 this.configurationFileHash
= configuration
.configurationHash
;
1407 this.sharedLRUCache
.setChargingStationConfiguration(configuration
);
1410 FileUtils
.handleFileException(
1411 this.configurationFile
,
1412 FileType
.ChargingStationConfiguration
,
1413 error
as NodeJS
.ErrnoException
,
1418 return configuration
;
1421 private saveConfiguration(): void {
1422 if (this.configurationFile
) {
1424 if (!fs
.existsSync(path
.dirname(this.configurationFile
))) {
1425 fs
.mkdirSync(path
.dirname(this.configurationFile
), { recursive
: true });
1427 const configurationData
: ChargingStationConfiguration
=
1428 Utils
.cloneObject(this.getConfigurationFromFile()) ?? {};
1429 this.ocppConfiguration
?.configurationKey
&&
1430 (configurationData
.configurationKey
= this.ocppConfiguration
.configurationKey
);
1431 this.stationInfo
&& (configurationData
.stationInfo
= this.stationInfo
);
1432 delete configurationData
.configurationHash
;
1433 const configurationHash
= crypto
1434 .createHash(Constants
.DEFAULT_HASH_ALGORITHM
)
1435 .update(JSON
.stringify(configurationData
))
1437 if (this.configurationFileHash
!== configurationHash
) {
1438 configurationData
.configurationHash
= configurationHash
;
1439 const measureId
= `${FileType.ChargingStationConfiguration} write`;
1440 const beginId
= PerformanceStatistics
.beginMeasure(measureId
);
1441 const fileDescriptor
= fs
.openSync(this.configurationFile
, 'w');
1442 fs
.writeFileSync(fileDescriptor
, JSON
.stringify(configurationData
, null, 2), 'utf8');
1443 fs
.closeSync(fileDescriptor
);
1444 PerformanceStatistics
.endMeasure(measureId
, beginId
);
1445 this.sharedLRUCache
.deleteChargingStationConfiguration(this.configurationFileHash
);
1446 this.configurationFileHash
= configurationHash
;
1447 this.sharedLRUCache
.setChargingStationConfiguration(configurationData
);
1450 `${this.logPrefix()} Not saving unchanged charging station configuration file ${
1451 this.configurationFile
1456 FileUtils
.handleFileException(
1457 this.configurationFile
,
1458 FileType
.ChargingStationConfiguration
,
1459 error
as NodeJS
.ErrnoException
,
1465 `${this.logPrefix()} Trying to save charging station configuration to undefined configuration file`
1470 private getOcppConfigurationFromTemplate(): ChargingStationOcppConfiguration
| undefined {
1471 return this.getTemplateFromFile()?.Configuration
;
1474 private getOcppConfigurationFromFile(): ChargingStationOcppConfiguration
| undefined {
1475 let configuration
: ChargingStationConfiguration
| undefined;
1476 if (this.getOcppPersistentConfiguration() === true) {
1477 const configurationFromFile
= this.getConfigurationFromFile();
1478 configuration
= configurationFromFile
?.configurationKey
&& configurationFromFile
;
1480 if (!Utils
.isNullOrUndefined(configuration
)) {
1481 delete configuration
.stationInfo
;
1482 delete configuration
.configurationHash
;
1484 return configuration
;
1487 private getOcppConfiguration(): ChargingStationOcppConfiguration
| undefined {
1488 let ocppConfiguration
: ChargingStationOcppConfiguration
| undefined =
1489 this.getOcppConfigurationFromFile();
1490 if (!ocppConfiguration
) {
1491 ocppConfiguration
= this.getOcppConfigurationFromTemplate();
1493 return ocppConfiguration
;
1496 private async onOpen(): Promise
<void> {
1497 if (this.isWebSocketConnectionOpened() === true) {
1499 `${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.toString()} succeeded`
1501 if (this.isRegistered() === false) {
1502 // Send BootNotification
1503 let registrationRetryCount
= 0;
1505 this.bootNotificationResponse
= await this.ocppRequestService
.requestHandler
<
1506 BootNotificationRequest
,
1507 BootNotificationResponse
1508 >(this, RequestCommand
.BOOT_NOTIFICATION
, this.bootNotificationRequest
, {
1509 skipBufferingOnError
: true,
1511 if (this.isRegistered() === false) {
1512 this.getRegistrationMaxRetries() !== -1 && registrationRetryCount
++;
1514 this?.bootNotificationResponse
?.interval
1515 ? this.bootNotificationResponse
.interval
* 1000
1516 : Constants
.OCPP_DEFAULT_BOOT_NOTIFICATION_INTERVAL
1520 this.isRegistered() === false &&
1521 (registrationRetryCount
<= this.getRegistrationMaxRetries() ||
1522 this.getRegistrationMaxRetries() === -1)
1525 if (this.isRegistered() === true) {
1526 if (this.isInAcceptedState() === true) {
1527 await this.startMessageSequence();
1531 `${this.logPrefix()} Registration failure: max retries reached (${this.getRegistrationMaxRetries()}) or retry disabled (${this.getRegistrationMaxRetries()})`
1534 this.wsConnectionRestarted
= false;
1535 this.autoReconnectRetryCount
= 0;
1536 parentPort
?.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
1539 `${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.toString()} failed`
1544 private async onClose(code
: number, reason
: Buffer
): Promise
<void> {
1547 case WebSocketCloseEventStatusCode
.CLOSE_NORMAL
:
1548 case WebSocketCloseEventStatusCode
.CLOSE_NO_STATUS
:
1550 `${this.logPrefix()} WebSocket normally closed with status '${Utils.getWebSocketCloseEventStatusString(
1552 )}' and reason '${reason.toString()}'`
1554 this.autoReconnectRetryCount
= 0;
1559 `${this.logPrefix()} WebSocket abnormally closed with status '${Utils.getWebSocketCloseEventStatusString(
1561 )}' and reason '${reason.toString()}'`
1563 this.started
=== true && (await this.reconnect());
1566 parentPort
?.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
1569 private getCachedRequest(messageType
: MessageType
, messageId
: string): CachedRequest
| undefined {
1570 const cachedRequest
= this.requests
.get(messageId
);
1571 if (Array.isArray(cachedRequest
) === true) {
1572 return cachedRequest
;
1574 throw new OCPPError(
1575 ErrorType
.PROTOCOL_ERROR
,
1576 `Cached request for message id ${messageId} ${OCPPServiceUtils.getMessageTypeString(
1578 )} is not an array`,
1580 cachedRequest
as JsonType
1584 private async handleIncomingMessage(request
: IncomingRequest
): Promise
<void> {
1585 const [messageType
, messageId
, commandName
, commandPayload
] = request
;
1586 if (this.getEnableStatistics() === true) {
1587 this.performanceStatistics
?.addRequestStatistic(commandName
, messageType
);
1590 `${this.logPrefix()} << Command '${commandName}' received request payload: ${JSON.stringify(
1594 // Process the message
1595 await this.ocppIncomingRequestService
.incomingRequestHandler(
1603 private handleResponseMessage(response
: Response
): void {
1604 const [messageType
, messageId
, commandPayload
] = response
;
1605 if (this.requests
.has(messageId
) === false) {
1607 throw new OCPPError(
1608 ErrorType
.INTERNAL_ERROR
,
1609 `Response for unknown message id ${messageId}`,
1615 const [responseCallback
, , requestCommandName
, requestPayload
] = this.getCachedRequest(
1620 `${this.logPrefix()} << Command '${
1621 requestCommandName ?? Constants.UNKNOWN_COMMAND
1622 }' received response payload: ${JSON.stringify(response)}`
1624 responseCallback(commandPayload
, requestPayload
);
1627 private handleErrorMessage(errorResponse
: ErrorResponse
): void {
1628 const [messageType
, messageId
, errorType
, errorMessage
, errorDetails
] = errorResponse
;
1629 if (this.requests
.has(messageId
) === false) {
1631 throw new OCPPError(
1632 ErrorType
.INTERNAL_ERROR
,
1633 `Error response for unknown message id ${messageId}`,
1635 { errorType
, errorMessage
, errorDetails
}
1638 const [, errorCallback
, requestCommandName
] = this.getCachedRequest(messageType
, messageId
);
1640 `${this.logPrefix()} << Command '${
1641 requestCommandName ?? Constants.UNKNOWN_COMMAND
1642 }' received error response payload: ${JSON.stringify(errorResponse)}`
1644 errorCallback(new OCPPError(errorType
, errorMessage
, requestCommandName
, errorDetails
));
1647 private async onMessage(data
: RawData
): Promise
<void> {
1648 let request
: IncomingRequest
| Response
| ErrorResponse
;
1649 let messageType
: number;
1652 request
= JSON
.parse(data
.toString()) as IncomingRequest
| Response
| ErrorResponse
;
1653 if (Array.isArray(request
) === true) {
1654 [messageType
] = request
;
1655 // Check the type of message
1656 switch (messageType
) {
1658 case MessageType
.CALL_MESSAGE
:
1659 await this.handleIncomingMessage(request
as IncomingRequest
);
1662 case MessageType
.CALL_RESULT_MESSAGE
:
1663 this.handleResponseMessage(request
as Response
);
1666 case MessageType
.CALL_ERROR_MESSAGE
:
1667 this.handleErrorMessage(request
as ErrorResponse
);
1671 // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1672 errMsg
= `Wrong message type ${messageType}`;
1673 logger
.error(`${this.logPrefix()} ${errMsg}`);
1674 throw new OCPPError(ErrorType
.PROTOCOL_ERROR
, errMsg
);
1676 parentPort
?.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
1678 throw new OCPPError(ErrorType
.PROTOCOL_ERROR
, 'Incoming message is not an array', null, {
1683 let commandName
: IncomingRequestCommand
;
1684 let requestCommandName
: RequestCommand
| IncomingRequestCommand
;
1685 let errorCallback
: ErrorCallback
;
1686 const [, messageId
] = request
;
1687 switch (messageType
) {
1688 case MessageType
.CALL_MESSAGE
:
1689 [, , commandName
] = request
as IncomingRequest
;
1691 await this.ocppRequestService
.sendError(this, messageId
, error
as OCPPError
, commandName
);
1693 case MessageType
.CALL_RESULT_MESSAGE
:
1694 case MessageType
.CALL_ERROR_MESSAGE
:
1695 if (this.requests
.has(messageId
) === true) {
1696 [, errorCallback
, requestCommandName
] = this.getCachedRequest(messageType
, messageId
);
1697 // Reject the deferred promise in case of error at response handling (rejecting an already fulfilled promise is a no-op)
1698 errorCallback(error
as OCPPError
, false);
1700 // Remove the request from the cache in case of error at response handling
1701 this.requests
.delete(messageId
);
1705 if (error
instanceof OCPPError
=== false) {
1707 `${this.logPrefix()} Error thrown at incoming OCPP command '${
1708 commandName ?? requestCommandName ?? Constants.UNKNOWN_COMMAND
1709 }' message '${data.toString()}' handling is not an OCPPError:`,
1714 `${this.logPrefix()} Incoming OCPP command '${
1715 commandName ?? requestCommandName ?? Constants.UNKNOWN_COMMAND
1716 }' message '${data.toString()}'${
1717 messageType !== MessageType.CALL_MESSAGE
1718 ? ` matching cached request
'${JSON.stringify(this.requests.get(messageId))}'`
1720 } processing error:`,
1726 private onPing(): void {
1727 logger
.debug(`${this.logPrefix()} Received a WS ping (rfc6455) from the server`);
1730 private onPong(): void {
1731 logger
.debug(`${this.logPrefix()} Received a WS pong (rfc6455) from the server`);
1734 private onError(error
: WSError
): void {
1735 this.closeWSConnection();
1736 logger
.error(`${this.logPrefix()} WebSocket error:`, error
);
1739 private getEnergyActiveImportRegister(connectorStatus
: ConnectorStatus
, rounded
= false): number {
1740 if (this.getMeteringPerTransaction() === true) {
1743 ? Math.round(connectorStatus
?.transactionEnergyActiveImportRegisterValue
)
1744 : connectorStatus
?.transactionEnergyActiveImportRegisterValue
) ?? 0
1749 ? Math.round(connectorStatus
?.energyActiveImportRegisterValue
)
1750 : connectorStatus
?.energyActiveImportRegisterValue
) ?? 0
1754 private getUseConnectorId0(stationInfo
?: ChargingStationInfo
): boolean {
1755 const localStationInfo
= stationInfo
?? this.stationInfo
;
1756 return localStationInfo
?.useConnectorId0
?? true;
1759 private getNumberOfRunningTransactions(): number {
1761 for (const connectorId
of this.connectors
.keys()) {
1762 if (connectorId
> 0 && this.getConnectorStatus(connectorId
)?.transactionStarted
=== true) {
1769 private async stopRunningTransactions(reason
= StopTransactionReason
.NONE
): Promise
<void> {
1770 for (const connectorId
of this.connectors
.keys()) {
1771 if (connectorId
> 0 && this.getConnectorStatus(connectorId
)?.transactionStarted
=== true) {
1772 await this.stopTransactionOnConnector(connectorId
, reason
);
1778 private getConnectionTimeout(): number {
1780 ChargingStationConfigurationUtils
.getConfigurationKey(
1782 StandardParametersKey
.ConnectionTimeOut
1787 ChargingStationConfigurationUtils
.getConfigurationKey(
1789 StandardParametersKey
.ConnectionTimeOut
1791 ) ?? Constants
.DEFAULT_CONNECTION_TIMEOUT
1794 return Constants
.DEFAULT_CONNECTION_TIMEOUT
;
1797 // -1 for unlimited, 0 for disabling
1798 private getAutoReconnectMaxRetries(): number | undefined {
1799 if (!Utils
.isUndefined(this.stationInfo
.autoReconnectMaxRetries
)) {
1800 return this.stationInfo
.autoReconnectMaxRetries
;
1802 if (!Utils
.isUndefined(Configuration
.getAutoReconnectMaxRetries())) {
1803 return Configuration
.getAutoReconnectMaxRetries();
1809 private getRegistrationMaxRetries(): number | undefined {
1810 if (!Utils
.isUndefined(this.stationInfo
.registrationMaxRetries
)) {
1811 return this.stationInfo
.registrationMaxRetries
;
1816 private getPowerDivider(): number {
1817 let powerDivider
= this.getNumberOfConnectors();
1818 if (this.stationInfo
?.powerSharedByConnectors
) {
1819 powerDivider
= this.getNumberOfRunningTransactions();
1821 return powerDivider
;
1824 private getMaximumAmperage(stationInfo
: ChargingStationInfo
): number | undefined {
1825 const maximumPower
= this.getMaximumPower(stationInfo
);
1826 switch (this.getCurrentOutType(stationInfo
)) {
1827 case CurrentType
.AC
:
1828 return ACElectricUtils
.amperagePerPhaseFromPower(
1829 this.getNumberOfPhases(stationInfo
),
1830 maximumPower
/ this.getNumberOfConnectors(),
1831 this.getVoltageOut(stationInfo
)
1833 case CurrentType
.DC
:
1834 return DCElectricUtils
.amperage(maximumPower
, this.getVoltageOut(stationInfo
));
1838 private getAmperageLimitation(): number | undefined {
1840 Utils
.isNotEmptyString(this.stationInfo
?.amperageLimitationOcppKey
) &&
1841 ChargingStationConfigurationUtils
.getConfigurationKey(
1843 this.stationInfo
.amperageLimitationOcppKey
1848 ChargingStationConfigurationUtils
.getConfigurationKey(
1850 this.stationInfo
.amperageLimitationOcppKey
1852 ) / ChargingStationUtils
.getAmperageLimitationUnitDivider(this.stationInfo
)
1857 private async startMessageSequence(): Promise
<void> {
1858 if (this.stationInfo
?.autoRegister
=== true) {
1859 await this.ocppRequestService
.requestHandler
<
1860 BootNotificationRequest
,
1861 BootNotificationResponse
1862 >(this, RequestCommand
.BOOT_NOTIFICATION
, this.bootNotificationRequest
, {
1863 skipBufferingOnError
: true,
1866 // Start WebSocket ping
1867 this.startWebSocketPing();
1869 this.startHeartbeat();
1870 // Initialize connectors status
1871 for (const connectorId
of this.connectors
.keys()) {
1872 let connectorStatus
: ConnectorStatusEnum
| undefined;
1873 if (connectorId
=== 0) {
1876 !this.getConnectorStatus(connectorId
)?.status &&
1877 (this.isChargingStationAvailable() === false ||
1878 this.isConnectorAvailable(connectorId
) === false)
1880 connectorStatus
= ConnectorStatusEnum
.Unavailable
;
1882 !this.getConnectorStatus(connectorId
)?.status &&
1883 this.getConnectorStatus(connectorId
)?.bootStatus
1885 // Set boot status in template at startup
1886 connectorStatus
= this.getConnectorStatus(connectorId
)?.bootStatus
;
1887 } else if (this.getConnectorStatus(connectorId
)?.status) {
1888 // Set previous status at startup
1889 connectorStatus
= this.getConnectorStatus(connectorId
)?.status;
1891 // Set default status
1892 connectorStatus
= ConnectorStatusEnum
.Available
;
1894 await OCPPServiceUtils
.sendAndSetConnectorStatus(this, connectorId
, connectorStatus
);
1896 if (this.stationInfo
?.firmwareStatus
=== FirmwareStatus
.Installing
) {
1897 await this.ocppRequestService
.requestHandler
<
1898 FirmwareStatusNotificationRequest
,
1899 FirmwareStatusNotificationResponse
1900 >(this, RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1901 status: FirmwareStatus
.Installed
,
1903 this.stationInfo
.firmwareStatus
= FirmwareStatus
.Installed
;
1907 if (this.getAutomaticTransactionGeneratorConfigurationFromTemplate()?.enable
=== true) {
1908 this.startAutomaticTransactionGenerator();
1910 this.wsConnectionRestarted
=== true && this.flushMessageBuffer();
1913 private async stopMessageSequence(
1914 reason
: StopTransactionReason
= StopTransactionReason
.NONE
1916 // Stop WebSocket ping
1917 this.stopWebSocketPing();
1919 this.stopHeartbeat();
1920 // Stop ongoing transactions
1921 if (this.automaticTransactionGenerator
?.started
=== true) {
1922 this.stopAutomaticTransactionGenerator();
1924 await this.stopRunningTransactions(reason
);
1926 for (const connectorId
of this.connectors
.keys()) {
1927 if (connectorId
> 0) {
1928 await this.ocppRequestService
.requestHandler
<
1929 StatusNotificationRequest
,
1930 StatusNotificationResponse
1933 RequestCommand
.STATUS_NOTIFICATION
,
1934 OCPPServiceUtils
.buildStatusNotificationRequest(
1937 ConnectorStatusEnum
.Unavailable
1940 delete this.getConnectorStatus(connectorId
)?.status;
1945 private startWebSocketPing(): void {
1946 const webSocketPingInterval
: number = ChargingStationConfigurationUtils
.getConfigurationKey(
1948 StandardParametersKey
.WebSocketPingInterval
1950 ? Utils
.convertToInt(
1951 ChargingStationConfigurationUtils
.getConfigurationKey(
1953 StandardParametersKey
.WebSocketPingInterval
1957 if (webSocketPingInterval
> 0 && !this.webSocketPingSetInterval
) {
1958 this.webSocketPingSetInterval
= setInterval(() => {
1959 if (this.isWebSocketConnectionOpened() === true) {
1960 this.wsConnection
?.ping();
1962 }, webSocketPingInterval
* 1000);
1964 `${this.logPrefix()} WebSocket ping started every ${Utils.formatDurationSeconds(
1965 webSocketPingInterval
1968 } else if (this.webSocketPingSetInterval
) {
1970 `${this.logPrefix()} WebSocket ping already started every ${Utils.formatDurationSeconds(
1971 webSocketPingInterval
1976 `${this.logPrefix()} WebSocket ping interval set to ${webSocketPingInterval}, not starting the WebSocket ping`
1981 private stopWebSocketPing(): void {
1982 if (this.webSocketPingSetInterval
) {
1983 clearInterval(this.webSocketPingSetInterval
);
1984 delete this.webSocketPingSetInterval
;
1988 private getConfiguredSupervisionUrl(): URL
{
1989 const supervisionUrls
= this.stationInfo
?.supervisionUrls
?? Configuration
.getSupervisionUrls();
1990 if (Utils
.isNotEmptyArray(supervisionUrls
)) {
1991 let configuredSupervisionUrlIndex
: number;
1992 switch (Configuration
.getSupervisionUrlDistribution()) {
1993 case SupervisionUrlDistribution
.RANDOM
:
1994 configuredSupervisionUrlIndex
= Math.floor(Utils
.secureRandom() * supervisionUrls
.length
);
1996 case SupervisionUrlDistribution
.ROUND_ROBIN
:
1997 case SupervisionUrlDistribution
.CHARGING_STATION_AFFINITY
:
1999 Object.values(SupervisionUrlDistribution
).includes(
2000 Configuration
.getSupervisionUrlDistribution()
2003 `${this.logPrefix()} Unknown supervision url distribution '${Configuration.getSupervisionUrlDistribution()}' from values '${SupervisionUrlDistribution.toString()}', defaulting to ${
2004 SupervisionUrlDistribution.CHARGING_STATION_AFFINITY
2007 configuredSupervisionUrlIndex
= (this.index
- 1) % supervisionUrls
.length
;
2010 return new URL(supervisionUrls
[configuredSupervisionUrlIndex
]);
2012 return new URL(supervisionUrls
as string);
2015 private stopHeartbeat(): void {
2016 if (this.heartbeatSetInterval
) {
2017 clearInterval(this.heartbeatSetInterval
);
2018 delete this.heartbeatSetInterval
;
2022 private terminateWSConnection(): void {
2023 if (this.isWebSocketConnectionOpened() === true) {
2024 this.wsConnection
?.terminate();
2025 this.wsConnection
= null;
2029 private getReconnectExponentialDelay(): boolean {
2030 return this.stationInfo
?.reconnectExponentialDelay
?? false;
2033 private async reconnect(): Promise
<void> {
2034 // Stop WebSocket ping
2035 this.stopWebSocketPing();
2037 this.stopHeartbeat();
2038 // Stop the ATG if needed
2039 if (this.automaticTransactionGenerator
?.configuration
?.stopOnConnectionFailure
=== true) {
2040 this.stopAutomaticTransactionGenerator();
2043 this.autoReconnectRetryCount
< this.getAutoReconnectMaxRetries() ||
2044 this.getAutoReconnectMaxRetries() === -1
2046 this.autoReconnectRetryCount
++;
2047 const reconnectDelay
= this.getReconnectExponentialDelay()
2048 ? Utils
.exponentialDelay(this.autoReconnectRetryCount
)
2049 : this.getConnectionTimeout() * 1000;
2050 const reconnectDelayWithdraw
= 1000;
2051 const reconnectTimeout
=
2052 reconnectDelay
&& reconnectDelay
- reconnectDelayWithdraw
> 0
2053 ? reconnectDelay
- reconnectDelayWithdraw
2056 `${this.logPrefix()} WebSocket connection retry in ${Utils.roundTo(
2059 )}ms, timeout ${reconnectTimeout}ms`
2061 await Utils
.sleep(reconnectDelay
);
2063 `${this.logPrefix()} WebSocket connection retry #${this.autoReconnectRetryCount.toString()}`
2065 this.openWSConnection(
2067 ...(this.stationInfo
?.wsOptions
?? {}),
2068 handshakeTimeout
: reconnectTimeout
,
2070 { closeOpened
: true }
2072 this.wsConnectionRestarted
= true;
2073 } else if (this.getAutoReconnectMaxRetries() !== -1) {
2075 `${this.logPrefix()} WebSocket connection retries failure: maximum retries reached (${
2076 this.autoReconnectRetryCount
2077 }) or retries disabled (${this.getAutoReconnectMaxRetries()})`
2082 private getAutomaticTransactionGeneratorConfigurationFromTemplate():
2083 | AutomaticTransactionGeneratorConfiguration
2085 return this.getTemplateFromFile()?.AutomaticTransactionGenerator
;