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
'worker_threads';
9 import merge from
'just-merge';
10 import WebSocket
, { type RawData
} from
'ws';
12 import { AuthorizedTagsCache
} from
'./AuthorizedTagsCache';
13 import { AutomaticTransactionGenerator
} from
'./AutomaticTransactionGenerator';
14 import { ChargingStationConfigurationUtils
} from
'./ChargingStationConfigurationUtils';
15 import { ChargingStationUtils
} from
'./ChargingStationUtils';
16 import { ChargingStationWorkerBroadcastChannel
} from
'./ChargingStationWorkerBroadcastChannel';
17 import { MessageChannelUtils
} from
'./MessageChannelUtils';
18 import { OCPP16IncomingRequestService
} from
'./ocpp/1.6/OCPP16IncomingRequestService';
19 import { OCPP16RequestService
} from
'./ocpp/1.6/OCPP16RequestService';
20 import { OCPP16ResponseService
} from
'./ocpp/1.6/OCPP16ResponseService';
21 import { OCPP16ServiceUtils
} from
'./ocpp/1.6/OCPP16ServiceUtils';
22 import { OCPP20IncomingRequestService
} from
'./ocpp/2.0/OCPP20IncomingRequestService';
23 import { OCPP20RequestService
} from
'./ocpp/2.0/OCPP20RequestService';
24 import { OCPP20ResponseService
} from
'./ocpp/2.0/OCPP20ResponseService';
25 import type { OCPPIncomingRequestService
} from
'./ocpp/OCPPIncomingRequestService';
26 import type { OCPPRequestService
} from
'./ocpp/OCPPRequestService';
27 import { OCPPServiceUtils
} from
'./ocpp/OCPPServiceUtils';
28 import { SharedLRUCache
} from
'./SharedLRUCache';
29 import { BaseError
, OCPPError
} from
'../exception';
30 import { PerformanceStatistics
} from
'../performance/PerformanceStatistics';
32 type AutomaticTransactionGeneratorConfiguration
,
34 type BootNotificationRequest
,
35 type BootNotificationResponse
,
37 type ChargingStationConfiguration
,
38 type ChargingStationInfo
,
39 type ChargingStationOcppConfiguration
,
40 type ChargingStationTemplate
,
41 ConnectorPhaseRotation
,
50 type FirmwareStatusNotificationRequest
,
51 type FirmwareStatusNotificationResponse
,
53 type HeartbeatRequest
,
54 type HeartbeatResponse
,
56 type IncomingRequestCommand
,
61 type MeterValuesRequest
,
62 type MeterValuesResponse
,
66 RegistrationStatusEnumType
,
69 type ResponseCallback
,
70 StandardParametersKey
,
71 type StatusNotificationRequest
,
72 type StatusNotificationResponse
,
73 StopTransactionReason
,
74 type StopTransactionRequest
,
75 type StopTransactionResponse
,
76 SupervisionUrlDistribution
,
77 SupportedFeatureProfiles
,
78 VendorDefaultParametersKey
,
80 WebSocketCloseEventStatusCode
,
83 import { Configuration
} from
'../utils/Configuration';
84 import { Constants
} from
'../utils/Constants';
85 import { ACElectricUtils
, DCElectricUtils
} from
'../utils/ElectricUtils';
86 import { FileUtils
} from
'../utils/FileUtils';
87 import { logger
} from
'../utils/Logger';
88 import { Utils
} from
'../utils/Utils';
90 export class ChargingStation
{
91 public readonly index
: number;
92 public readonly templateFile
: string;
93 public stationInfo
!: ChargingStationInfo
;
94 public started
: boolean;
95 public starting
: boolean;
96 public authorizedTagsCache
: AuthorizedTagsCache
;
97 public automaticTransactionGenerator
!: AutomaticTransactionGenerator
| undefined;
98 public ocppConfiguration
!: ChargingStationOcppConfiguration
| undefined;
99 public wsConnection
!: WebSocket
| null;
100 public readonly connectors
: Map
<number, ConnectorStatus
>;
101 public readonly requests
: Map
<string, CachedRequest
>;
102 public performanceStatistics
!: PerformanceStatistics
| undefined;
103 public heartbeatSetInterval
!: NodeJS
.Timeout
;
104 public ocppRequestService
!: OCPPRequestService
;
105 public bootNotificationRequest
!: BootNotificationRequest
;
106 public bootNotificationResponse
!: BootNotificationResponse
| undefined;
107 public powerDivider
!: number;
108 private stopping
: boolean;
109 private configurationFile
!: string;
110 private configurationFileHash
!: string;
111 private connectorsConfigurationHash
!: string;
112 private ocppIncomingRequestService
!: OCPPIncomingRequestService
;
113 private readonly messageBuffer
: Set
<string>;
114 private configuredSupervisionUrl
!: URL
;
115 private configuredSupervisionUrlIndex
!: number;
116 private wsConnectionRestarted
: boolean;
117 private autoReconnectRetryCount
: number;
118 private templateFileWatcher
!: fs
.FSWatcher
| undefined;
119 private readonly sharedLRUCache
: SharedLRUCache
;
120 private webSocketPingSetInterval
!: NodeJS
.Timeout
;
121 private readonly chargingStationWorkerBroadcastChannel
: ChargingStationWorkerBroadcastChannel
;
123 constructor(index
: number, templateFile
: string) {
124 this.started
= false;
125 this.starting
= false;
126 this.stopping
= false;
127 this.wsConnectionRestarted
= false;
128 this.autoReconnectRetryCount
= 0;
130 this.templateFile
= templateFile
;
131 this.connectors
= new Map
<number, ConnectorStatus
>();
132 this.requests
= new Map
<string, CachedRequest
>();
133 this.messageBuffer
= new Set
<string>();
134 this.sharedLRUCache
= SharedLRUCache
.getInstance();
135 this.authorizedTagsCache
= AuthorizedTagsCache
.getInstance();
136 this.chargingStationWorkerBroadcastChannel
= new ChargingStationWorkerBroadcastChannel(this);
141 private get
wsConnectionUrl(): URL
{
144 this.getSupervisionUrlOcppConfiguration()
145 ? ChargingStationConfigurationUtils.getConfigurationKey(
147 this.getSupervisionUrlOcppKey()
149 : this.configuredSupervisionUrl.href
150 }/${this.stationInfo.chargingStationId}`
154 public logPrefix
= (): string => {
155 return Utils
.logPrefix(
157 (Utils.isNotEmptyString(this?.stationInfo?.chargingStationId) &&
158 this?.stationInfo?.chargingStationId) ??
159 ChargingStationUtils.getChargingStationId(this.index, this.getTemplateFromFile()) ??
165 public hasAuthorizedTags(): boolean {
166 return Utils
.isNotEmptyArray(
167 this.authorizedTagsCache
.getAuthorizedTags(
168 ChargingStationUtils
.getAuthorizationFile(this.stationInfo
)
173 public getEnableStatistics(): boolean {
174 return this.stationInfo
.enableStatistics
?? false;
177 public getMustAuthorizeAtRemoteStart(): boolean {
178 return this.stationInfo
.mustAuthorizeAtRemoteStart
?? true;
181 public getPayloadSchemaValidation(): boolean {
182 return this.stationInfo
.payloadSchemaValidation
?? true;
185 public getNumberOfPhases(stationInfo
?: ChargingStationInfo
): number | undefined {
186 const localStationInfo
: ChargingStationInfo
= stationInfo
?? this.stationInfo
;
187 switch (this.getCurrentOutType(stationInfo
)) {
189 return !Utils
.isUndefined(localStationInfo
.numberOfPhases
)
190 ? localStationInfo
.numberOfPhases
197 public isWebSocketConnectionOpened(): boolean {
198 return this?.wsConnection
?.readyState
=== WebSocket
.OPEN
;
201 public getRegistrationStatus(): RegistrationStatusEnumType
| undefined {
202 return this?.bootNotificationResponse
?.status;
205 public isInUnknownState(): boolean {
206 return Utils
.isNullOrUndefined(this?.bootNotificationResponse
?.status);
209 public isInPendingState(): boolean {
210 return this?.bootNotificationResponse
?.status === RegistrationStatusEnumType
.PENDING
;
213 public isInAcceptedState(): boolean {
214 return this?.bootNotificationResponse
?.status === RegistrationStatusEnumType
.ACCEPTED
;
217 public isInRejectedState(): boolean {
218 return this?.bootNotificationResponse
?.status === RegistrationStatusEnumType
.REJECTED
;
221 public isRegistered(): boolean {
223 this.isInUnknownState() === false &&
224 (this.isInAcceptedState() === true || this.isInPendingState() === true)
228 public isChargingStationAvailable(): boolean {
229 return this.getConnectorStatus(0)?.availability
=== AvailabilityType
.OPERATIVE
;
232 public isConnectorAvailable(id
: number): boolean {
233 return id
> 0 && this.getConnectorStatus(id
)?.availability
=== AvailabilityType
.OPERATIVE
;
236 public getNumberOfConnectors(): number {
237 return this.connectors
.get(0) ? this.connectors
.size
- 1 : this.connectors
.size
;
240 public getConnectorStatus(id
: number): ConnectorStatus
| undefined {
241 return this.connectors
.get(id
);
244 public getCurrentOutType(stationInfo
?: ChargingStationInfo
): CurrentType
{
245 return (stationInfo
?? this.stationInfo
)?.currentOutType
?? CurrentType
.AC
;
248 public getOcppStrictCompliance(): boolean {
249 return this.stationInfo
?.ocppStrictCompliance
?? false;
252 public getVoltageOut(stationInfo
?: ChargingStationInfo
): number | undefined {
253 const defaultVoltageOut
= ChargingStationUtils
.getDefaultVoltageOut(
254 this.getCurrentOutType(stationInfo
),
258 const localStationInfo
: ChargingStationInfo
= stationInfo
?? this.stationInfo
;
259 return !Utils
.isUndefined(localStationInfo
.voltageOut
)
260 ? localStationInfo
.voltageOut
264 public getMaximumPower(stationInfo
?: ChargingStationInfo
): number {
265 const localStationInfo
= stationInfo
?? this.stationInfo
;
266 return (localStationInfo
['maxPower'] as number) ?? localStationInfo
.maximumPower
;
269 public getConnectorMaximumAvailablePower(connectorId
: number): number {
270 let connectorAmperageLimitationPowerLimit
: number;
272 !Utils
.isNullOrUndefined(this.getAmperageLimitation()) &&
273 this.getAmperageLimitation() < this.stationInfo
?.maximumAmperage
275 connectorAmperageLimitationPowerLimit
=
276 (this.getCurrentOutType() === CurrentType
.AC
277 ? ACElectricUtils
.powerTotal(
278 this.getNumberOfPhases(),
279 this.getVoltageOut(),
280 this.getAmperageLimitation() * this.getNumberOfConnectors()
282 : DCElectricUtils
.power(this.getVoltageOut(), this.getAmperageLimitation())) /
285 const connectorMaximumPower
= this.getMaximumPower() / this.powerDivider
;
286 const connectorChargingProfilesPowerLimit
=
287 ChargingStationUtils
.getChargingStationConnectorChargingProfilesPowerLimit(this, connectorId
);
289 isNaN(connectorMaximumPower
) ? Infinity : connectorMaximumPower
,
290 isNaN(connectorAmperageLimitationPowerLimit
)
292 : connectorAmperageLimitationPowerLimit
,
293 isNaN(connectorChargingProfilesPowerLimit
) ? Infinity : connectorChargingProfilesPowerLimit
297 public getTransactionIdTag(transactionId
: number): string | undefined {
298 for (const connectorId
of this.connectors
.keys()) {
301 this.getConnectorStatus(connectorId
)?.transactionId
=== transactionId
303 return this.getConnectorStatus(connectorId
)?.transactionIdTag
;
308 public getOutOfOrderEndMeterValues(): boolean {
309 return this.stationInfo
?.outOfOrderEndMeterValues
?? false;
312 public getBeginEndMeterValues(): boolean {
313 return this.stationInfo
?.beginEndMeterValues
?? false;
316 public getMeteringPerTransaction(): boolean {
317 return this.stationInfo
?.meteringPerTransaction
?? true;
320 public getTransactionDataMeterValues(): boolean {
321 return this.stationInfo
?.transactionDataMeterValues
?? false;
324 public getMainVoltageMeterValues(): boolean {
325 return this.stationInfo
?.mainVoltageMeterValues
?? true;
328 public getPhaseLineToLineVoltageMeterValues(): boolean {
329 return this.stationInfo
?.phaseLineToLineVoltageMeterValues
?? false;
332 public getCustomValueLimitationMeterValues(): boolean {
333 return this.stationInfo
?.customValueLimitationMeterValues
?? true;
336 public getConnectorIdByTransactionId(transactionId
: number): number | undefined {
337 for (const connectorId
of this.connectors
.keys()) {
340 this.getConnectorStatus(connectorId
)?.transactionId
=== transactionId
347 public getEnergyActiveImportRegisterByTransactionId(
348 transactionId
: number,
351 return this.getEnergyActiveImportRegister(
352 this.getConnectorStatus(this.getConnectorIdByTransactionId(transactionId
)),
357 public getEnergyActiveImportRegisterByConnectorId(connectorId
: number, rounded
= false): number {
358 return this.getEnergyActiveImportRegister(this.getConnectorStatus(connectorId
), rounded
);
361 public getAuthorizeRemoteTxRequests(): boolean {
362 const authorizeRemoteTxRequests
= ChargingStationConfigurationUtils
.getConfigurationKey(
364 StandardParametersKey
.AuthorizeRemoteTxRequests
366 return authorizeRemoteTxRequests
367 ? Utils
.convertToBoolean(authorizeRemoteTxRequests
.value
)
371 public getLocalAuthListEnabled(): boolean {
372 const localAuthListEnabled
= ChargingStationConfigurationUtils
.getConfigurationKey(
374 StandardParametersKey
.LocalAuthListEnabled
376 return localAuthListEnabled
? Utils
.convertToBoolean(localAuthListEnabled
.value
) : false;
379 public startHeartbeat(): void {
381 this.getHeartbeatInterval() &&
382 this.getHeartbeatInterval() > 0 &&
383 !this.heartbeatSetInterval
385 this.heartbeatSetInterval
= setInterval(() => {
386 this.ocppRequestService
387 .requestHandler
<HeartbeatRequest
, HeartbeatResponse
>(this, RequestCommand
.HEARTBEAT
)
390 `${this.logPrefix()} Error while sending '${RequestCommand.HEARTBEAT}':`,
394 }, this.getHeartbeatInterval());
396 `${this.logPrefix()} Heartbeat started every ${Utils.formatDurationMilliSeconds(
397 this.getHeartbeatInterval()
400 } else if (this.heartbeatSetInterval
) {
402 `${this.logPrefix()} Heartbeat already started every ${Utils.formatDurationMilliSeconds(
403 this.getHeartbeatInterval()
408 `${this.logPrefix()} Heartbeat interval set to ${
409 this.getHeartbeatInterval()
410 ? Utils.formatDurationMilliSeconds(this.getHeartbeatInterval())
411 : this.getHeartbeatInterval()
412 }, not starting the heartbeat`
417 public restartHeartbeat(): void {
419 this.stopHeartbeat();
421 this.startHeartbeat();
424 public restartWebSocketPing(): void {
425 // Stop WebSocket ping
426 this.stopWebSocketPing();
427 // Start WebSocket ping
428 this.startWebSocketPing();
431 public startMeterValues(connectorId
: number, interval
: number): void {
432 if (connectorId
=== 0) {
434 `${this.logPrefix()} Trying to start MeterValues on connector Id ${connectorId.toString()}`
438 if (!this.getConnectorStatus(connectorId
)) {
440 `${this.logPrefix()} Trying to start MeterValues on non existing connector Id ${connectorId.toString()}`
444 if (this.getConnectorStatus(connectorId
)?.transactionStarted
=== false) {
446 `${this.logPrefix()} Trying to start MeterValues on connector Id ${connectorId} with no transaction started`
450 this.getConnectorStatus(connectorId
)?.transactionStarted
=== true &&
451 Utils
.isNullOrUndefined(this.getConnectorStatus(connectorId
)?.transactionId
)
454 `${this.logPrefix()} Trying to start MeterValues on connector Id ${connectorId} with no transaction id`
459 this.getConnectorStatus(connectorId
).transactionSetInterval
= setInterval(() => {
460 // FIXME: Implement OCPP version agnostic helpers
461 const meterValue
: MeterValue
= OCPP16ServiceUtils
.buildMeterValue(
464 this.getConnectorStatus(connectorId
).transactionId
,
467 this.ocppRequestService
468 .requestHandler
<MeterValuesRequest
, MeterValuesResponse
>(
470 RequestCommand
.METER_VALUES
,
473 transactionId
: this.getConnectorStatus(connectorId
)?.transactionId
,
474 meterValue
: [meterValue
],
479 `${this.logPrefix()} Error while sending '${RequestCommand.METER_VALUES}':`,
486 `${this.logPrefix()} Charging station ${
487 StandardParametersKey.MeterValueSampleInterval
488 } configuration set to ${
489 interval ? Utils.formatDurationMilliSeconds(interval) : interval
490 }, not sending MeterValues`
495 public start(): void {
496 if (this.started
=== false) {
497 if (this.starting
=== false) {
498 this.starting
= true;
499 if (this.getEnableStatistics() === true) {
500 this.performanceStatistics
?.start();
502 this.openWSConnection();
503 // Monitor charging station template file
504 this.templateFileWatcher
= FileUtils
.watchJsonFile(
506 FileType
.ChargingStationTemplate
,
509 (event
, filename
): void => {
510 if (Utils
.isNotEmptyString(filename
) && event
=== 'change') {
513 `${this.logPrefix()} ${FileType.ChargingStationTemplate} ${
515 } file have changed, reload`
517 this.sharedLRUCache
.deleteChargingStationTemplate(this.stationInfo
?.templateHash
);
521 this.stopAutomaticTransactionGenerator();
523 this.getAutomaticTransactionGeneratorConfigurationFromTemplate()?.enable
=== true
525 this.startAutomaticTransactionGenerator();
527 if (this.getEnableStatistics() === true) {
528 this.performanceStatistics
?.restart();
530 this.performanceStatistics
?.stop();
532 // FIXME?: restart heartbeat and WebSocket ping when their interval values have changed
535 `${this.logPrefix()} ${FileType.ChargingStationTemplate} file monitoring error:`,
543 parentPort
?.postMessage(MessageChannelUtils
.buildStartedMessage(this));
544 this.starting
= false;
546 logger
.warn(`${this.logPrefix()} Charging station is already starting...`);
549 logger
.warn(`${this.logPrefix()} Charging station is already started...`);
553 public async stop(reason
?: StopTransactionReason
): Promise
<void> {
554 if (this.started
=== true) {
555 if (this.stopping
=== false) {
556 this.stopping
= true;
557 await this.stopMessageSequence(reason
);
558 this.closeWSConnection();
559 if (this.getEnableStatistics() === true) {
560 this.performanceStatistics
?.stop();
562 this.sharedLRUCache
.deleteChargingStationConfiguration(this.configurationFileHash
);
563 this.templateFileWatcher
?.close();
564 this.sharedLRUCache
.deleteChargingStationTemplate(this.stationInfo
?.templateHash
);
565 this.bootNotificationResponse
= undefined;
566 this.started
= false;
567 parentPort
?.postMessage(MessageChannelUtils
.buildStoppedMessage(this));
568 this.stopping
= false;
570 logger
.warn(`${this.logPrefix()} Charging station is already stopping...`);
573 logger
.warn(`${this.logPrefix()} Charging station is already stopped...`);
577 public async reset(reason
?: StopTransactionReason
): Promise
<void> {
578 await this.stop(reason
);
579 await Utils
.sleep(this.stationInfo
.resetTime
);
584 public saveOcppConfiguration(): void {
585 if (this.getOcppPersistentConfiguration()) {
586 this.saveConfiguration();
590 public resetConnectorStatus(connectorId
: number): void {
591 this.getConnectorStatus(connectorId
).idTagLocalAuthorized
= false;
592 this.getConnectorStatus(connectorId
).idTagAuthorized
= false;
593 this.getConnectorStatus(connectorId
).transactionRemoteStarted
= false;
594 this.getConnectorStatus(connectorId
).transactionStarted
= false;
595 delete this.getConnectorStatus(connectorId
)?.localAuthorizeIdTag
;
596 delete this.getConnectorStatus(connectorId
)?.authorizeIdTag
;
597 delete this.getConnectorStatus(connectorId
)?.transactionId
;
598 delete this.getConnectorStatus(connectorId
)?.transactionIdTag
;
599 this.getConnectorStatus(connectorId
).transactionEnergyActiveImportRegisterValue
= 0;
600 delete this.getConnectorStatus(connectorId
)?.transactionBeginMeterValue
;
601 this.stopMeterValues(connectorId
);
602 parentPort
?.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
605 public hasFeatureProfile(featureProfile
: SupportedFeatureProfiles
): boolean | undefined {
606 return ChargingStationConfigurationUtils
.getConfigurationKey(
608 StandardParametersKey
.SupportedFeatureProfiles
609 )?.value
?.includes(featureProfile
);
612 public bufferMessage(message
: string): void {
613 this.messageBuffer
.add(message
);
616 public openWSConnection(
617 options
: WsOptions
= this.stationInfo
?.wsOptions
?? {},
618 params
: { closeOpened
?: boolean; terminateOpened
?: boolean } = {
620 terminateOpened
: false,
623 options
.handshakeTimeout
= options
?.handshakeTimeout
?? this.getConnectionTimeout() * 1000;
624 params
.closeOpened
= params
?.closeOpened
?? false;
625 params
.terminateOpened
= params
?.terminateOpened
?? false;
626 if (this.started
=== false && this.starting
=== false) {
628 `${this.logPrefix()} Cannot open OCPP connection to URL ${this.wsConnectionUrl.toString()} on stopped charging station`
633 !Utils
.isNullOrUndefined(this.stationInfo
.supervisionUser
) &&
634 !Utils
.isNullOrUndefined(this.stationInfo
.supervisionPassword
)
636 options
.auth
= `${this.stationInfo.supervisionUser}:${this.stationInfo.supervisionPassword}`;
638 if (params
?.closeOpened
) {
639 this.closeWSConnection();
641 if (params
?.terminateOpened
) {
642 this.terminateWSConnection();
644 const ocppVersion
= this.stationInfo
.ocppVersion
?? OCPPVersion
.VERSION_16
;
645 let protocol
: string;
646 switch (ocppVersion
) {
647 case OCPPVersion
.VERSION_16
:
648 case OCPPVersion
.VERSION_20
:
649 case OCPPVersion
.VERSION_201
:
650 protocol
= `ocpp${ocppVersion}`;
653 this.handleUnsupportedVersion(ocppVersion
);
657 if (this.isWebSocketConnectionOpened() === true) {
659 `${this.logPrefix()} OCPP connection to URL ${this.wsConnectionUrl.toString()} is already opened`
665 `${this.logPrefix()} Open OCPP connection to URL ${this.wsConnectionUrl.toString()}`
668 this.wsConnection
= new WebSocket(this.wsConnectionUrl
, protocol
, options
);
670 // Handle WebSocket message
671 this.wsConnection
.on(
673 this.onMessage
.bind(this) as (this: WebSocket
, data
: RawData
, isBinary
: boolean) => void
675 // Handle WebSocket error
676 this.wsConnection
.on(
678 this.onError
.bind(this) as (this: WebSocket
, error
: Error) => void
680 // Handle WebSocket close
681 this.wsConnection
.on(
683 this.onClose
.bind(this) as (this: WebSocket
, code
: number, reason
: Buffer
) => void
685 // Handle WebSocket open
686 this.wsConnection
.on('open', this.onOpen
.bind(this) as (this: WebSocket
) => void);
687 // Handle WebSocket ping
688 this.wsConnection
.on('ping', this.onPing
.bind(this) as (this: WebSocket
, data
: Buffer
) => void);
689 // Handle WebSocket pong
690 this.wsConnection
.on('pong', this.onPong
.bind(this) as (this: WebSocket
, data
: Buffer
) => void);
693 public closeWSConnection(): void {
694 if (this.isWebSocketConnectionOpened() === true) {
695 this.wsConnection
?.close();
696 this.wsConnection
= null;
700 public startAutomaticTransactionGenerator(
701 connectorIds
?: number[],
702 automaticTransactionGeneratorConfiguration
?: AutomaticTransactionGeneratorConfiguration
704 this.automaticTransactionGenerator
= AutomaticTransactionGenerator
.getInstance(
705 automaticTransactionGeneratorConfiguration
??
706 this.getAutomaticTransactionGeneratorConfigurationFromTemplate(),
709 if (Utils
.isNotEmptyArray(connectorIds
)) {
710 for (const connectorId
of connectorIds
) {
711 this.automaticTransactionGenerator
?.startConnector(connectorId
);
714 this.automaticTransactionGenerator
?.start();
716 parentPort
?.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
719 public stopAutomaticTransactionGenerator(connectorIds
?: number[]): void {
720 if (Utils
.isNotEmptyArray(connectorIds
)) {
721 for (const connectorId
of connectorIds
) {
722 this.automaticTransactionGenerator
?.stopConnector(connectorId
);
725 this.automaticTransactionGenerator
?.stop();
727 parentPort
?.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
730 public async stopTransactionOnConnector(
732 reason
= StopTransactionReason
.NONE
733 ): Promise
<StopTransactionResponse
> {
734 const transactionId
= this.getConnectorStatus(connectorId
)?.transactionId
;
736 this.getBeginEndMeterValues() === true &&
737 this.getOcppStrictCompliance() === true &&
738 this.getOutOfOrderEndMeterValues() === false
740 // FIXME: Implement OCPP version agnostic helpers
741 const transactionEndMeterValue
= OCPP16ServiceUtils
.buildTransactionEndMeterValue(
744 this.getEnergyActiveImportRegisterByTransactionId(transactionId
)
746 await this.ocppRequestService
.requestHandler
<MeterValuesRequest
, MeterValuesResponse
>(
748 RequestCommand
.METER_VALUES
,
752 meterValue
: [transactionEndMeterValue
],
756 return this.ocppRequestService
.requestHandler
<StopTransactionRequest
, StopTransactionResponse
>(
758 RequestCommand
.STOP_TRANSACTION
,
761 meterStop
: this.getEnergyActiveImportRegisterByTransactionId(transactionId
, true),
767 private flushMessageBuffer(): void {
768 if (this.messageBuffer
.size
> 0) {
769 this.messageBuffer
.forEach((message
) => {
771 let commandName
: RequestCommand
;
772 const [messageType
] = JSON
.parse(message
) as OutgoingRequest
| Response
| ErrorResponse
;
773 const isRequest
= messageType
=== MessageType
.CALL_MESSAGE
;
775 [, , commandName
] = JSON
.parse(message
) as OutgoingRequest
;
776 beginId
= PerformanceStatistics
.beginMeasure(commandName
);
778 this.wsConnection
?.send(message
);
779 isRequest
&& PerformanceStatistics
.endMeasure(commandName
, beginId
);
781 `${this.logPrefix()} >> Buffered ${OCPPServiceUtils.getMessageTypeString(
783 )} payload sent: ${message}`
785 this.messageBuffer
.delete(message
);
790 private getSupervisionUrlOcppConfiguration(): boolean {
791 return this.stationInfo
.supervisionUrlOcppConfiguration
?? false;
794 private getSupervisionUrlOcppKey(): string {
795 return this.stationInfo
.supervisionUrlOcppKey
?? VendorDefaultParametersKey
.ConnectionUrl
;
798 private getTemplateFromFile(): ChargingStationTemplate
| undefined {
799 let template
: ChargingStationTemplate
;
801 if (this.sharedLRUCache
.hasChargingStationTemplate(this.stationInfo
?.templateHash
)) {
802 template
= this.sharedLRUCache
.getChargingStationTemplate(this.stationInfo
.templateHash
);
804 const measureId
= `${FileType.ChargingStationTemplate} read`;
805 const beginId
= PerformanceStatistics
.beginMeasure(measureId
);
806 template
= JSON
.parse(
807 fs
.readFileSync(this.templateFile
, 'utf8')
808 ) as ChargingStationTemplate
;
809 PerformanceStatistics
.endMeasure(measureId
, beginId
);
810 template
.templateHash
= crypto
811 .createHash(Constants
.DEFAULT_HASH_ALGORITHM
)
812 .update(JSON
.stringify(template
))
814 this.sharedLRUCache
.setChargingStationTemplate(template
);
817 FileUtils
.handleFileException(
819 FileType
.ChargingStationTemplate
,
820 error
as NodeJS
.ErrnoException
,
827 private getStationInfoFromTemplate(): ChargingStationInfo
{
828 const stationTemplate
: ChargingStationTemplate
| undefined = this.getTemplateFromFile();
829 if (Utils
.isNullOrUndefined(stationTemplate
)) {
830 const errorMsg
= `Failed to read charging station template file ${this.templateFile}`;
831 logger
.error(`${this.logPrefix()} ${errorMsg}`);
832 throw new BaseError(errorMsg
);
834 if (Utils
.isEmptyObject(stationTemplate
)) {
835 const errorMsg
= `Empty charging station information from template file ${this.templateFile}`;
836 logger
.error(`${this.logPrefix()} ${errorMsg}`);
837 throw new BaseError(errorMsg
);
839 // Deprecation template keys section
840 ChargingStationUtils
.warnDeprecatedTemplateKey(
845 "Use 'supervisionUrls' instead"
847 ChargingStationUtils
.convertDeprecatedTemplateKey(
852 const stationInfo
: ChargingStationInfo
=
853 ChargingStationUtils
.stationTemplateToStationInfo(stationTemplate
);
854 stationInfo
.hashId
= ChargingStationUtils
.getHashId(this.index
, stationTemplate
);
855 stationInfo
.chargingStationId
= ChargingStationUtils
.getChargingStationId(
859 stationInfo
.ocppVersion
= stationTemplate
?.ocppVersion
?? OCPPVersion
.VERSION_16
;
860 ChargingStationUtils
.createSerialNumber(stationTemplate
, stationInfo
);
861 if (Utils
.isNotEmptyArray(stationTemplate
?.power
)) {
862 stationTemplate
.power
= stationTemplate
.power
as number[];
863 const powerArrayRandomIndex
= Math.floor(Utils
.secureRandom() * stationTemplate
.power
.length
);
864 stationInfo
.maximumPower
=
865 stationTemplate
?.powerUnit
=== PowerUnits
.KILO_WATT
866 ? stationTemplate
.power
[powerArrayRandomIndex
] * 1000
867 : stationTemplate
.power
[powerArrayRandomIndex
];
869 stationTemplate
.power
= stationTemplate
?.power
as number;
870 stationInfo
.maximumPower
=
871 stationTemplate
?.powerUnit
=== PowerUnits
.KILO_WATT
872 ? stationTemplate
.power
* 1000
873 : stationTemplate
.power
;
875 stationInfo
.firmwareVersionPattern
=
876 stationTemplate
?.firmwareVersionPattern
?? Constants
.SEMVER_PATTERN
;
878 Utils
.isNotEmptyString(stationInfo
.firmwareVersion
) &&
879 new RegExp(stationInfo
.firmwareVersionPattern
).test(stationInfo
.firmwareVersion
) === false
882 `${this.logPrefix()} Firmware version '${stationInfo.firmwareVersion}' in template file ${
884 } does not match firmware version pattern '${stationInfo.firmwareVersionPattern}'`
887 stationInfo
.firmwareUpgrade
= merge
<FirmwareUpgrade
>(
894 stationTemplate
?.firmwareUpgrade
?? {}
896 stationInfo
.resetTime
= !Utils
.isNullOrUndefined(stationTemplate
?.resetTime
)
897 ? stationTemplate
.resetTime
* 1000
898 : Constants
.CHARGING_STATION_DEFAULT_RESET_TIME
;
899 const configuredMaxConnectors
=
900 ChargingStationUtils
.getConfiguredNumberOfConnectors(stationTemplate
);
901 ChargingStationUtils
.checkConfiguredMaxConnectors(
902 configuredMaxConnectors
,
906 const templateMaxConnectors
=
907 ChargingStationUtils
.getTemplateMaxNumberOfConnectors(stationTemplate
);
908 ChargingStationUtils
.checkTemplateMaxConnectors(
909 templateMaxConnectors
,
914 configuredMaxConnectors
>
915 (stationTemplate
?.Connectors
[0] ? templateMaxConnectors
- 1 : templateMaxConnectors
) &&
916 !stationTemplate
?.randomConnectors
919 `${this.logPrefix()} Number of connectors exceeds the number of connector configurations in template ${
921 }, forcing random connector configurations affectation`
923 stationInfo
.randomConnectors
= true;
925 // Build connectors if needed (FIXME: should be factored out)
926 this.initializeConnectors(stationInfo
, configuredMaxConnectors
, templateMaxConnectors
);
927 stationInfo
.maximumAmperage
= this.getMaximumAmperage(stationInfo
);
928 ChargingStationUtils
.createStationInfoHash(stationInfo
);
932 private getStationInfoFromFile(): ChargingStationInfo
| undefined {
933 let stationInfo
: ChargingStationInfo
| undefined;
934 this.getStationInfoPersistentConfiguration() &&
935 (stationInfo
= this.getConfigurationFromFile()?.stationInfo
);
936 stationInfo
&& ChargingStationUtils
.createStationInfoHash(stationInfo
);
940 private getStationInfo(): ChargingStationInfo
{
941 const stationInfoFromTemplate
: ChargingStationInfo
= this.getStationInfoFromTemplate();
942 const stationInfoFromFile
: ChargingStationInfo
| undefined = this.getStationInfoFromFile();
943 // Priority: charging station info from template > charging station info from configuration file > charging station info attribute
944 if (stationInfoFromFile
?.templateHash
=== stationInfoFromTemplate
.templateHash
) {
945 if (this.stationInfo
?.infoHash
=== stationInfoFromFile
?.infoHash
) {
946 return this.stationInfo
;
948 return stationInfoFromFile
;
950 stationInfoFromFile
&&
951 ChargingStationUtils
.propagateSerialNumber(
952 this.getTemplateFromFile(),
954 stationInfoFromTemplate
956 return stationInfoFromTemplate
;
959 private saveStationInfo(): void {
960 if (this.getStationInfoPersistentConfiguration()) {
961 this.saveConfiguration();
965 private getOcppPersistentConfiguration(): boolean {
966 return this.stationInfo
?.ocppPersistentConfiguration
?? true;
969 private getStationInfoPersistentConfiguration(): boolean {
970 return this.stationInfo
?.stationInfoPersistentConfiguration
?? true;
973 private handleUnsupportedVersion(version
: OCPPVersion
) {
974 const errMsg
= `Unsupported protocol version '${version}' configured in template file ${this.templateFile}`;
975 logger
.error(`${this.logPrefix()} ${errMsg}`);
976 throw new BaseError(errMsg
);
979 private initialize(): void {
980 this.configurationFile
= path
.join(
981 path
.dirname(this.templateFile
.replace('station-templates', 'configurations')),
982 `${ChargingStationUtils.getHashId(this.index, this.getTemplateFromFile())}.json`
984 this.stationInfo
= this.getStationInfo();
985 this.saveStationInfo();
986 // Avoid duplication of connectors related information in RAM
987 this.stationInfo
?.Connectors
&& delete this.stationInfo
.Connectors
;
988 this.configuredSupervisionUrl
= this.getConfiguredSupervisionUrl();
989 if (this.getEnableStatistics() === true) {
990 this.performanceStatistics
= PerformanceStatistics
.getInstance(
991 this.stationInfo
.hashId
,
992 this.stationInfo
.chargingStationId
,
993 this.configuredSupervisionUrl
996 this.bootNotificationRequest
= ChargingStationUtils
.createBootNotificationRequest(
999 this.powerDivider
= this.getPowerDivider();
1000 // OCPP configuration
1001 this.ocppConfiguration
= this.getOcppConfiguration();
1002 this.initializeOcppConfiguration();
1003 const ocppVersion
= this.stationInfo
.ocppVersion
?? OCPPVersion
.VERSION_16
;
1004 switch (ocppVersion
) {
1005 case OCPPVersion
.VERSION_16
:
1006 this.ocppIncomingRequestService
=
1007 OCPP16IncomingRequestService
.getInstance
<OCPP16IncomingRequestService
>();
1008 this.ocppRequestService
= OCPP16RequestService
.getInstance
<OCPP16RequestService
>(
1009 OCPP16ResponseService
.getInstance
<OCPP16ResponseService
>()
1012 case OCPPVersion
.VERSION_20
:
1013 case OCPPVersion
.VERSION_201
:
1014 this.ocppIncomingRequestService
=
1015 OCPP20IncomingRequestService
.getInstance
<OCPP20IncomingRequestService
>();
1016 this.ocppRequestService
= OCPP20RequestService
.getInstance
<OCPP20RequestService
>(
1017 OCPP20ResponseService
.getInstance
<OCPP20ResponseService
>()
1021 this.handleUnsupportedVersion(ocppVersion
);
1024 if (this.stationInfo
?.autoRegister
=== true) {
1025 this.bootNotificationResponse
= {
1026 currentTime
: new Date(),
1027 interval
: this.getHeartbeatInterval() / 1000,
1028 status: RegistrationStatusEnumType
.ACCEPTED
,
1032 this.stationInfo
.firmwareStatus
=== FirmwareStatus
.Installing
&&
1033 Utils
.isNotEmptyString(this.stationInfo
.firmwareVersion
) &&
1034 Utils
.isNotEmptyString(this.stationInfo
.firmwareVersionPattern
)
1036 const patternGroup
: number | undefined =
1037 this.stationInfo
.firmwareUpgrade
?.versionUpgrade
?.patternGroup
??
1038 this.stationInfo
.firmwareVersion
?.split('.').length
;
1039 const match
= this.stationInfo
?.firmwareVersion
1040 ?.match(new RegExp(this.stationInfo
.firmwareVersionPattern
))
1041 ?.slice(1, patternGroup
+ 1);
1042 const patchLevelIndex
= match
.length
- 1;
1043 match
[patchLevelIndex
] = (
1044 Utils
.convertToInt(match
[patchLevelIndex
]) +
1045 this.stationInfo
.firmwareUpgrade
?.versionUpgrade
?.step
1047 this.stationInfo
.firmwareVersion
= match
?.join('.');
1051 private initializeOcppConfiguration(): void {
1053 !ChargingStationConfigurationUtils
.getConfigurationKey(
1055 StandardParametersKey
.HeartbeatInterval
1058 ChargingStationConfigurationUtils
.addConfigurationKey(
1060 StandardParametersKey
.HeartbeatInterval
,
1065 !ChargingStationConfigurationUtils
.getConfigurationKey(
1067 StandardParametersKey
.HeartBeatInterval
1070 ChargingStationConfigurationUtils
.addConfigurationKey(
1072 StandardParametersKey
.HeartBeatInterval
,
1078 this.getSupervisionUrlOcppConfiguration() &&
1079 !ChargingStationConfigurationUtils
.getConfigurationKey(this, this.getSupervisionUrlOcppKey())
1081 ChargingStationConfigurationUtils
.addConfigurationKey(
1083 this.getSupervisionUrlOcppKey(),
1084 this.configuredSupervisionUrl
.href
,
1088 !this.getSupervisionUrlOcppConfiguration() &&
1089 ChargingStationConfigurationUtils
.getConfigurationKey(this, this.getSupervisionUrlOcppKey())
1091 ChargingStationConfigurationUtils
.deleteConfigurationKey(
1093 this.getSupervisionUrlOcppKey(),
1098 Utils
.isNotEmptyString(this.stationInfo
?.amperageLimitationOcppKey
) &&
1099 !ChargingStationConfigurationUtils
.getConfigurationKey(
1101 this.stationInfo
.amperageLimitationOcppKey
1104 ChargingStationConfigurationUtils
.addConfigurationKey(
1106 this.stationInfo
.amperageLimitationOcppKey
,
1108 this.stationInfo
.maximumAmperage
*
1109 ChargingStationUtils
.getAmperageLimitationUnitDivider(this.stationInfo
)
1114 !ChargingStationConfigurationUtils
.getConfigurationKey(
1116 StandardParametersKey
.SupportedFeatureProfiles
1119 ChargingStationConfigurationUtils
.addConfigurationKey(
1121 StandardParametersKey
.SupportedFeatureProfiles
,
1122 `${SupportedFeatureProfiles.Core},${SupportedFeatureProfiles.FirmwareManagement},${SupportedFeatureProfiles.LocalAuthListManagement},${SupportedFeatureProfiles.SmartCharging},${SupportedFeatureProfiles.RemoteTrigger}`
1125 ChargingStationConfigurationUtils
.addConfigurationKey(
1127 StandardParametersKey
.NumberOfConnectors
,
1128 this.getNumberOfConnectors().toString(),
1133 !ChargingStationConfigurationUtils
.getConfigurationKey(
1135 StandardParametersKey
.MeterValuesSampledData
1138 ChargingStationConfigurationUtils
.addConfigurationKey(
1140 StandardParametersKey
.MeterValuesSampledData
,
1141 MeterValueMeasurand
.ENERGY_ACTIVE_IMPORT_REGISTER
1145 !ChargingStationConfigurationUtils
.getConfigurationKey(
1147 StandardParametersKey
.ConnectorPhaseRotation
1150 const connectorPhaseRotation
= [];
1151 for (const connectorId
of this.connectors
.keys()) {
1153 if (connectorId
=== 0 && this.getNumberOfPhases() === 0) {
1154 connectorPhaseRotation
.push(`${connectorId}.${ConnectorPhaseRotation.RST}`);
1155 } else if (connectorId
> 0 && this.getNumberOfPhases() === 0) {
1156 connectorPhaseRotation
.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`);
1158 } else if (connectorId
> 0 && this.getNumberOfPhases() === 1) {
1159 connectorPhaseRotation
.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`);
1160 } else if (connectorId
> 0 && this.getNumberOfPhases() === 3) {
1161 connectorPhaseRotation
.push(`${connectorId}.${ConnectorPhaseRotation.RST}`);
1164 ChargingStationConfigurationUtils
.addConfigurationKey(
1166 StandardParametersKey
.ConnectorPhaseRotation
,
1167 connectorPhaseRotation
.toString()
1171 !ChargingStationConfigurationUtils
.getConfigurationKey(
1173 StandardParametersKey
.AuthorizeRemoteTxRequests
1176 ChargingStationConfigurationUtils
.addConfigurationKey(
1178 StandardParametersKey
.AuthorizeRemoteTxRequests
,
1183 !ChargingStationConfigurationUtils
.getConfigurationKey(
1185 StandardParametersKey
.LocalAuthListEnabled
1187 ChargingStationConfigurationUtils
.getConfigurationKey(
1189 StandardParametersKey
.SupportedFeatureProfiles
1190 )?.value
?.includes(SupportedFeatureProfiles
.LocalAuthListManagement
)
1192 ChargingStationConfigurationUtils
.addConfigurationKey(
1194 StandardParametersKey
.LocalAuthListEnabled
,
1199 !ChargingStationConfigurationUtils
.getConfigurationKey(
1201 StandardParametersKey
.ConnectionTimeOut
1204 ChargingStationConfigurationUtils
.addConfigurationKey(
1206 StandardParametersKey
.ConnectionTimeOut
,
1207 Constants
.DEFAULT_CONNECTION_TIMEOUT
.toString()
1210 this.saveOcppConfiguration();
1213 private initializeConnectors(
1214 stationInfo
: ChargingStationInfo
,
1215 configuredMaxConnectors
: number,
1216 templateMaxConnectors
: number
1218 if (!stationInfo
?.Connectors
&& this.connectors
.size
=== 0) {
1219 const logMsg
= `No already defined connectors and charging station information from template ${this.templateFile} with no connectors configuration defined`;
1220 logger
.error(`${this.logPrefix()} ${logMsg}`);
1221 throw new BaseError(logMsg
);
1223 if (!stationInfo
?.Connectors
[0]) {
1225 `${this.logPrefix()} Charging station information from template ${
1227 } with no connector Id 0 configuration`
1230 if (stationInfo
?.Connectors
) {
1231 const connectorsConfigHash
= crypto
1232 .createHash(Constants
.DEFAULT_HASH_ALGORITHM
)
1233 .update(`${JSON.stringify(stationInfo?.Connectors)}${configuredMaxConnectors.toString()}`)
1235 const connectorsConfigChanged
=
1236 this.connectors
?.size
!== 0 && this.connectorsConfigurationHash
!== connectorsConfigHash
;
1237 if (this.connectors
?.size
=== 0 || connectorsConfigChanged
) {
1238 connectorsConfigChanged
&& this.connectors
.clear();
1239 this.connectorsConfigurationHash
= connectorsConfigHash
;
1240 // Add connector Id 0
1241 let lastConnector
= '0';
1242 for (lastConnector
in stationInfo
?.Connectors
) {
1243 const connectorStatus
= stationInfo
?.Connectors
[lastConnector
];
1244 const lastConnectorId
= Utils
.convertToInt(lastConnector
);
1246 lastConnectorId
=== 0 &&
1247 this.getUseConnectorId0(stationInfo
) === true &&
1250 this.checkStationInfoConnectorStatus(lastConnectorId
, connectorStatus
);
1251 this.connectors
.set(
1253 Utils
.cloneObject
<ConnectorStatus
>(connectorStatus
)
1255 this.getConnectorStatus(lastConnectorId
).availability
= AvailabilityType
.OPERATIVE
;
1256 if (Utils
.isUndefined(this.getConnectorStatus(lastConnectorId
)?.chargingProfiles
)) {
1257 this.getConnectorStatus(lastConnectorId
).chargingProfiles
= [];
1261 // Generate all connectors
1262 if ((stationInfo
?.Connectors
[0] ? templateMaxConnectors
- 1 : templateMaxConnectors
) > 0) {
1263 for (let index
= 1; index
<= configuredMaxConnectors
; index
++) {
1264 const randConnectorId
= stationInfo
?.randomConnectors
1265 ? Utils
.getRandomInteger(Utils
.convertToInt(lastConnector
), 1)
1267 const connectorStatus
= stationInfo
?.Connectors
[randConnectorId
.toString()];
1268 this.checkStationInfoConnectorStatus(randConnectorId
, connectorStatus
);
1269 this.connectors
.set(index
, Utils
.cloneObject
<ConnectorStatus
>(connectorStatus
));
1270 this.getConnectorStatus(index
).availability
= AvailabilityType
.OPERATIVE
;
1271 if (Utils
.isUndefined(this.getConnectorStatus(index
)?.chargingProfiles
)) {
1272 this.getConnectorStatus(index
).chargingProfiles
= [];
1279 `${this.logPrefix()} Charging station information from template ${
1281 } with no connectors configuration defined, using already defined connectors`
1284 // Initialize transaction attributes on connectors
1285 for (const connectorId
of this.connectors
.keys()) {
1286 if (connectorId
> 0 && this.getConnectorStatus(connectorId
)?.transactionStarted
=== true) {
1288 `${this.logPrefix()} Connector ${connectorId} at initialization has a transaction started: ${
1289 this.getConnectorStatus(connectorId)?.transactionId
1295 (this.getConnectorStatus(connectorId
)?.transactionStarted
=== undefined ||
1296 this.getConnectorStatus(connectorId
)?.transactionStarted
=== null)
1298 this.initializeConnectorStatus(connectorId
);
1303 private checkStationInfoConnectorStatus(
1304 connectorId
: number,
1305 connectorStatus
: ConnectorStatus
1307 if (!Utils
.isNullOrUndefined(connectorStatus
?.status)) {
1309 `${this.logPrefix()} Charging station information from template ${
1311 } with connector ${connectorId} status configuration defined, undefine it`
1313 connectorStatus
.status = undefined;
1317 private getConfigurationFromFile(): ChargingStationConfiguration
| undefined {
1318 let configuration
: ChargingStationConfiguration
| undefined;
1319 if (this.configurationFile
&& fs
.existsSync(this.configurationFile
)) {
1321 if (this.sharedLRUCache
.hasChargingStationConfiguration(this.configurationFileHash
)) {
1322 configuration
= this.sharedLRUCache
.getChargingStationConfiguration(
1323 this.configurationFileHash
1326 const measureId
= `${FileType.ChargingStationConfiguration} read`;
1327 const beginId
= PerformanceStatistics
.beginMeasure(measureId
);
1328 configuration
= JSON
.parse(
1329 fs
.readFileSync(this.configurationFile
, 'utf8')
1330 ) as ChargingStationConfiguration
;
1331 PerformanceStatistics
.endMeasure(measureId
, beginId
);
1332 this.configurationFileHash
= configuration
.configurationHash
;
1333 this.sharedLRUCache
.setChargingStationConfiguration(configuration
);
1336 FileUtils
.handleFileException(
1337 this.configurationFile
,
1338 FileType
.ChargingStationConfiguration
,
1339 error
as NodeJS
.ErrnoException
,
1344 return configuration
;
1347 private saveConfiguration(): void {
1348 if (this.configurationFile
) {
1350 if (!fs
.existsSync(path
.dirname(this.configurationFile
))) {
1351 fs
.mkdirSync(path
.dirname(this.configurationFile
), { recursive
: true });
1353 const configurationData
: ChargingStationConfiguration
=
1354 this.getConfigurationFromFile() ?? {};
1355 this.ocppConfiguration
?.configurationKey
&&
1356 (configurationData
.configurationKey
= this.ocppConfiguration
.configurationKey
);
1357 this.stationInfo
&& (configurationData
.stationInfo
= this.stationInfo
);
1358 delete configurationData
.configurationHash
;
1359 const configurationHash
= crypto
1360 .createHash(Constants
.DEFAULT_HASH_ALGORITHM
)
1361 .update(JSON
.stringify(configurationData
))
1363 if (this.configurationFileHash
!== configurationHash
) {
1364 configurationData
.configurationHash
= configurationHash
;
1365 const measureId
= `${FileType.ChargingStationConfiguration} write`;
1366 const beginId
= PerformanceStatistics
.beginMeasure(measureId
);
1367 const fileDescriptor
= fs
.openSync(this.configurationFile
, 'w');
1368 fs
.writeFileSync(fileDescriptor
, JSON
.stringify(configurationData
, null, 2), 'utf8');
1369 fs
.closeSync(fileDescriptor
);
1370 PerformanceStatistics
.endMeasure(measureId
, beginId
);
1371 this.sharedLRUCache
.deleteChargingStationConfiguration(this.configurationFileHash
);
1372 this.configurationFileHash
= configurationHash
;
1373 this.sharedLRUCache
.setChargingStationConfiguration(configurationData
);
1376 `${this.logPrefix()} Not saving unchanged charging station configuration file ${
1377 this.configurationFile
1382 FileUtils
.handleFileException(
1383 this.configurationFile
,
1384 FileType
.ChargingStationConfiguration
,
1385 error
as NodeJS
.ErrnoException
,
1391 `${this.logPrefix()} Trying to save charging station configuration to undefined configuration file`
1396 private getOcppConfigurationFromTemplate(): ChargingStationOcppConfiguration
| undefined {
1397 return this.getTemplateFromFile()?.Configuration
;
1400 private getOcppConfigurationFromFile(): ChargingStationOcppConfiguration
| undefined {
1401 let configuration
: ChargingStationConfiguration
| undefined;
1402 if (this.getOcppPersistentConfiguration() === true) {
1403 const configurationFromFile
= this.getConfigurationFromFile();
1404 configuration
= configurationFromFile
?.configurationKey
&& configurationFromFile
;
1406 configuration
&& delete configuration
.stationInfo
;
1407 return configuration
;
1410 private getOcppConfiguration(): ChargingStationOcppConfiguration
| undefined {
1411 let ocppConfiguration
: ChargingStationOcppConfiguration
| undefined =
1412 this.getOcppConfigurationFromFile();
1413 if (!ocppConfiguration
) {
1414 ocppConfiguration
= this.getOcppConfigurationFromTemplate();
1416 return ocppConfiguration
;
1419 private async onOpen(): Promise
<void> {
1420 if (this.isWebSocketConnectionOpened() === true) {
1422 `${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.toString()} succeeded`
1424 if (this.isRegistered() === false) {
1425 // Send BootNotification
1426 let registrationRetryCount
= 0;
1428 this.bootNotificationResponse
= await this.ocppRequestService
.requestHandler
<
1429 BootNotificationRequest
,
1430 BootNotificationResponse
1431 >(this, RequestCommand
.BOOT_NOTIFICATION
, this.bootNotificationRequest
, {
1432 skipBufferingOnError
: true,
1434 if (this.isRegistered() === false) {
1435 this.getRegistrationMaxRetries() !== -1 && registrationRetryCount
++;
1437 this?.bootNotificationResponse
?.interval
1438 ? this.bootNotificationResponse
.interval
* 1000
1439 : Constants
.OCPP_DEFAULT_BOOT_NOTIFICATION_INTERVAL
1443 this.isRegistered() === false &&
1444 (registrationRetryCount
<= this.getRegistrationMaxRetries() ||
1445 this.getRegistrationMaxRetries() === -1)
1448 if (this.isRegistered() === true) {
1449 if (this.isInAcceptedState() === true) {
1450 await this.startMessageSequence();
1454 `${this.logPrefix()} Registration failure: max retries reached (${this.getRegistrationMaxRetries()}) or retry disabled (${this.getRegistrationMaxRetries()})`
1457 this.wsConnectionRestarted
= false;
1458 this.autoReconnectRetryCount
= 0;
1459 parentPort
?.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
1462 `${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.toString()} failed`
1467 private async onClose(code
: number, reason
: Buffer
): Promise
<void> {
1470 case WebSocketCloseEventStatusCode
.CLOSE_NORMAL
:
1471 case WebSocketCloseEventStatusCode
.CLOSE_NO_STATUS
:
1473 `${this.logPrefix()} WebSocket normally closed with status '${Utils.getWebSocketCloseEventStatusString(
1475 )}' and reason '${reason.toString()}'`
1477 this.autoReconnectRetryCount
= 0;
1482 `${this.logPrefix()} WebSocket abnormally closed with status '${Utils.getWebSocketCloseEventStatusString(
1484 )}' and reason '${reason.toString()}'`
1486 this.started
=== true && (await this.reconnect());
1489 parentPort
?.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
1492 private async onMessage(data
: RawData
): Promise
<void> {
1493 let messageType
: number;
1494 let messageId
: string;
1495 let commandName
: IncomingRequestCommand
;
1496 let commandPayload
: JsonType
;
1497 let errorType
: ErrorType
;
1498 let errorMessage
: string;
1499 let errorDetails
: JsonType
;
1500 let responseCallback
: ResponseCallback
;
1501 let errorCallback
: ErrorCallback
;
1502 let requestCommandName
: RequestCommand
| IncomingRequestCommand
;
1503 let requestPayload
: JsonType
;
1504 let cachedRequest
: CachedRequest
;
1507 const request
= JSON
.parse(data
.toString()) as IncomingRequest
| Response
| ErrorResponse
;
1508 if (Array.isArray(request
) === true) {
1509 [messageType
, messageId
] = request
;
1510 // Check the type of message
1511 switch (messageType
) {
1513 case MessageType
.CALL_MESSAGE
:
1514 [, , commandName
, commandPayload
] = request
as IncomingRequest
;
1515 if (this.getEnableStatistics() === true) {
1516 this.performanceStatistics
?.addRequestStatistic(commandName
, messageType
);
1519 `${this.logPrefix()} << Command '${commandName}' received request payload: ${JSON.stringify(
1523 // Process the message
1524 await this.ocppIncomingRequestService
.incomingRequestHandler(
1532 case MessageType
.CALL_RESULT_MESSAGE
:
1533 [, , commandPayload
] = request
as Response
;
1534 if (this.requests
.has(messageId
) === false) {
1536 throw new OCPPError(
1537 ErrorType
.INTERNAL_ERROR
,
1538 `Response for unknown message id ${messageId}`,
1544 cachedRequest
= this.requests
.get(messageId
);
1545 if (Array.isArray(cachedRequest
) === true) {
1546 [responseCallback
, errorCallback
, requestCommandName
, requestPayload
] = cachedRequest
;
1548 throw new OCPPError(
1549 ErrorType
.PROTOCOL_ERROR
,
1550 `Cached request for message id ${messageId} response is not an array`,
1552 cachedRequest
as unknown
as JsonType
1556 `${this.logPrefix()} << Command '${
1557 requestCommandName ?? Constants.UNKNOWN_COMMAND
1558 }' received response payload: ${JSON.stringify(request)}`
1560 responseCallback(commandPayload
, requestPayload
);
1563 case MessageType
.CALL_ERROR_MESSAGE
:
1564 [, , errorType
, errorMessage
, errorDetails
] = request
as ErrorResponse
;
1565 if (this.requests
.has(messageId
) === false) {
1567 throw new OCPPError(
1568 ErrorType
.INTERNAL_ERROR
,
1569 `Error response for unknown message id ${messageId}`,
1571 { errorType
, errorMessage
, errorDetails
}
1574 cachedRequest
= this.requests
.get(messageId
);
1575 if (Array.isArray(cachedRequest
) === true) {
1576 [, errorCallback
, requestCommandName
] = cachedRequest
;
1578 throw new OCPPError(
1579 ErrorType
.PROTOCOL_ERROR
,
1580 `Cached request for message id ${messageId} error response is not an array`,
1582 cachedRequest
as unknown
as JsonType
1586 `${this.logPrefix()} << Command '${
1587 requestCommandName ?? Constants.UNKNOWN_COMMAND
1588 }' received error response payload: ${JSON.stringify(request)}`
1590 errorCallback(new OCPPError(errorType
, errorMessage
, requestCommandName
, errorDetails
));
1594 // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1595 errMsg
= `Wrong message type ${messageType}`;
1596 logger
.error(`${this.logPrefix()} ${errMsg}`);
1597 throw new OCPPError(ErrorType
.PROTOCOL_ERROR
, errMsg
);
1599 parentPort
?.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
1601 throw new OCPPError(ErrorType
.PROTOCOL_ERROR
, 'Incoming message is not an array', null, {
1608 `${this.logPrefix()} Incoming OCPP command '${
1609 commandName ?? requestCommandName ?? Constants.UNKNOWN_COMMAND
1610 }' message '${data.toString()}'${
1611 messageType !== MessageType.CALL_MESSAGE
1612 ? ` matching cached request
'${JSON.stringify(this.requests.get(messageId))}'`
1614 } processing error:`,
1617 if (error
instanceof OCPPError
=== false) {
1619 `${this.logPrefix()} Error thrown at incoming OCPP command '${
1620 commandName ?? requestCommandName ?? Constants.UNKNOWN_COMMAND
1621 }' message '${data.toString()}' handling is not an OCPPError:`,
1625 switch (messageType
) {
1626 case MessageType
.CALL_MESSAGE
:
1628 await this.ocppRequestService
.sendError(
1632 commandName
?? requestCommandName
?? null
1635 case MessageType
.CALL_RESULT_MESSAGE
:
1636 case MessageType
.CALL_ERROR_MESSAGE
:
1637 if (errorCallback
) {
1638 // Reject the deferred promise in case of error at response handling (rejecting an already fulfilled promise is a no-op)
1639 errorCallback(error
as OCPPError
, false);
1641 // Remove the request from the cache in case of error at response handling
1642 this.requests
.delete(messageId
);
1649 private onPing(): void {
1650 logger
.debug(`${this.logPrefix()} Received a WS ping (rfc6455) from the server`);
1653 private onPong(): void {
1654 logger
.debug(`${this.logPrefix()} Received a WS pong (rfc6455) from the server`);
1657 private onError(error
: WSError
): void {
1658 this.closeWSConnection();
1659 logger
.error(`${this.logPrefix()} WebSocket error:`, error
);
1662 private getEnergyActiveImportRegister(connectorStatus
: ConnectorStatus
, rounded
= false): number {
1663 if (this.getMeteringPerTransaction() === true) {
1666 ? Math.round(connectorStatus
?.transactionEnergyActiveImportRegisterValue
)
1667 : connectorStatus
?.transactionEnergyActiveImportRegisterValue
) ?? 0
1672 ? Math.round(connectorStatus
?.energyActiveImportRegisterValue
)
1673 : connectorStatus
?.energyActiveImportRegisterValue
) ?? 0
1677 private getUseConnectorId0(stationInfo
?: ChargingStationInfo
): boolean {
1678 const localStationInfo
= stationInfo
?? this.stationInfo
;
1679 return localStationInfo
?.useConnectorId0
?? true;
1682 private getNumberOfRunningTransactions(): number {
1684 for (const connectorId
of this.connectors
.keys()) {
1685 if (connectorId
> 0 && this.getConnectorStatus(connectorId
)?.transactionStarted
=== true) {
1692 private async stopRunningTransactions(reason
= StopTransactionReason
.NONE
): Promise
<void> {
1693 for (const connectorId
of this.connectors
.keys()) {
1694 if (connectorId
> 0 && this.getConnectorStatus(connectorId
)?.transactionStarted
=== true) {
1695 await this.stopTransactionOnConnector(connectorId
, reason
);
1701 private getConnectionTimeout(): number {
1703 ChargingStationConfigurationUtils
.getConfigurationKey(
1705 StandardParametersKey
.ConnectionTimeOut
1710 ChargingStationConfigurationUtils
.getConfigurationKey(
1712 StandardParametersKey
.ConnectionTimeOut
1714 ) ?? Constants
.DEFAULT_CONNECTION_TIMEOUT
1717 return Constants
.DEFAULT_CONNECTION_TIMEOUT
;
1720 // -1 for unlimited, 0 for disabling
1721 private getAutoReconnectMaxRetries(): number | undefined {
1722 if (!Utils
.isUndefined(this.stationInfo
.autoReconnectMaxRetries
)) {
1723 return this.stationInfo
.autoReconnectMaxRetries
;
1725 if (!Utils
.isUndefined(Configuration
.getAutoReconnectMaxRetries())) {
1726 return Configuration
.getAutoReconnectMaxRetries();
1732 private getRegistrationMaxRetries(): number | undefined {
1733 if (!Utils
.isUndefined(this.stationInfo
.registrationMaxRetries
)) {
1734 return this.stationInfo
.registrationMaxRetries
;
1739 private getPowerDivider(): number {
1740 let powerDivider
= this.getNumberOfConnectors();
1741 if (this.stationInfo
?.powerSharedByConnectors
) {
1742 powerDivider
= this.getNumberOfRunningTransactions();
1744 return powerDivider
;
1747 private getMaximumAmperage(stationInfo
: ChargingStationInfo
): number | undefined {
1748 const maximumPower
= this.getMaximumPower(stationInfo
);
1749 switch (this.getCurrentOutType(stationInfo
)) {
1750 case CurrentType
.AC
:
1751 return ACElectricUtils
.amperagePerPhaseFromPower(
1752 this.getNumberOfPhases(stationInfo
),
1753 maximumPower
/ this.getNumberOfConnectors(),
1754 this.getVoltageOut(stationInfo
)
1756 case CurrentType
.DC
:
1757 return DCElectricUtils
.amperage(maximumPower
, this.getVoltageOut(stationInfo
));
1761 private getAmperageLimitation(): number | undefined {
1763 Utils
.isNotEmptyString(this.stationInfo
?.amperageLimitationOcppKey
) &&
1764 ChargingStationConfigurationUtils
.getConfigurationKey(
1766 this.stationInfo
.amperageLimitationOcppKey
1771 ChargingStationConfigurationUtils
.getConfigurationKey(
1773 this.stationInfo
.amperageLimitationOcppKey
1775 ) / ChargingStationUtils
.getAmperageLimitationUnitDivider(this.stationInfo
)
1780 private async startMessageSequence(): Promise
<void> {
1781 if (this.stationInfo
?.autoRegister
=== true) {
1782 await this.ocppRequestService
.requestHandler
<
1783 BootNotificationRequest
,
1784 BootNotificationResponse
1785 >(this, RequestCommand
.BOOT_NOTIFICATION
, this.bootNotificationRequest
, {
1786 skipBufferingOnError
: true,
1789 // Start WebSocket ping
1790 this.startWebSocketPing();
1792 this.startHeartbeat();
1793 // Initialize connectors status
1794 for (const connectorId
of this.connectors
.keys()) {
1795 let connectorStatus
: ConnectorStatusEnum
| undefined;
1796 if (connectorId
=== 0) {
1799 !this.getConnectorStatus(connectorId
)?.status &&
1800 (this.isChargingStationAvailable() === false ||
1801 this.isConnectorAvailable(connectorId
) === false)
1803 connectorStatus
= ConnectorStatusEnum
.UNAVAILABLE
;
1805 !this.getConnectorStatus(connectorId
)?.status &&
1806 this.getConnectorStatus(connectorId
)?.bootStatus
1808 // Set boot status in template at startup
1809 connectorStatus
= this.getConnectorStatus(connectorId
)?.bootStatus
;
1810 } else if (this.getConnectorStatus(connectorId
)?.status) {
1811 // Set previous status at startup
1812 connectorStatus
= this.getConnectorStatus(connectorId
)?.status;
1814 // Set default status
1815 connectorStatus
= ConnectorStatusEnum
.AVAILABLE
;
1817 await this.ocppRequestService
.requestHandler
<
1818 StatusNotificationRequest
,
1819 StatusNotificationResponse
1822 RequestCommand
.STATUS_NOTIFICATION
,
1823 OCPPServiceUtils
.buildStatusNotificationRequest(this, connectorId
, connectorStatus
)
1825 this.getConnectorStatus(connectorId
).status = connectorStatus
;
1827 if (this.stationInfo
?.firmwareStatus
=== FirmwareStatus
.Installing
) {
1828 await this.ocppRequestService
.requestHandler
<
1829 FirmwareStatusNotificationRequest
,
1830 FirmwareStatusNotificationResponse
1831 >(this, RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1832 status: FirmwareStatus
.Installed
,
1834 this.stationInfo
.firmwareStatus
= FirmwareStatus
.Installed
;
1838 if (this.getAutomaticTransactionGeneratorConfigurationFromTemplate()?.enable
=== true) {
1839 this.startAutomaticTransactionGenerator();
1841 this.wsConnectionRestarted
=== true && this.flushMessageBuffer();
1844 private async stopMessageSequence(
1845 reason
: StopTransactionReason
= StopTransactionReason
.NONE
1847 // Stop WebSocket ping
1848 this.stopWebSocketPing();
1850 this.stopHeartbeat();
1851 // Stop ongoing transactions
1852 if (this.automaticTransactionGenerator
?.started
=== true) {
1853 this.stopAutomaticTransactionGenerator();
1855 await this.stopRunningTransactions(reason
);
1857 for (const connectorId
of this.connectors
.keys()) {
1858 if (connectorId
> 0) {
1859 await this.ocppRequestService
.requestHandler
<
1860 StatusNotificationRequest
,
1861 StatusNotificationResponse
1864 RequestCommand
.STATUS_NOTIFICATION
,
1865 OCPPServiceUtils
.buildStatusNotificationRequest(
1868 ConnectorStatusEnum
.UNAVAILABLE
1871 this.getConnectorStatus(connectorId
).status = undefined;
1876 private startWebSocketPing(): void {
1877 const webSocketPingInterval
: number = ChargingStationConfigurationUtils
.getConfigurationKey(
1879 StandardParametersKey
.WebSocketPingInterval
1881 ? Utils
.convertToInt(
1882 ChargingStationConfigurationUtils
.getConfigurationKey(
1884 StandardParametersKey
.WebSocketPingInterval
1888 if (webSocketPingInterval
> 0 && !this.webSocketPingSetInterval
) {
1889 this.webSocketPingSetInterval
= setInterval(() => {
1890 if (this.isWebSocketConnectionOpened() === true) {
1891 this.wsConnection
?.ping();
1893 }, webSocketPingInterval
* 1000);
1895 `${this.logPrefix()} WebSocket ping started every ${Utils.formatDurationSeconds(
1896 webSocketPingInterval
1899 } else if (this.webSocketPingSetInterval
) {
1901 `${this.logPrefix()} WebSocket ping already started every ${Utils.formatDurationSeconds(
1902 webSocketPingInterval
1907 `${this.logPrefix()} WebSocket ping interval set to ${
1908 webSocketPingInterval
1909 ? Utils.formatDurationSeconds(webSocketPingInterval)
1910 : webSocketPingInterval
1911 }, not starting the WebSocket ping`
1916 private stopWebSocketPing(): void {
1917 if (this.webSocketPingSetInterval
) {
1918 clearInterval(this.webSocketPingSetInterval
);
1922 private getConfiguredSupervisionUrl(): URL
{
1923 const supervisionUrls
= this.stationInfo
?.supervisionUrls
?? Configuration
.getSupervisionUrls();
1924 if (Utils
.isNotEmptyArray(supervisionUrls
)) {
1925 switch (Configuration
.getSupervisionUrlDistribution()) {
1926 case SupervisionUrlDistribution
.ROUND_ROBIN
:
1928 this.configuredSupervisionUrlIndex
= (this.index
- 1) % supervisionUrls
.length
;
1930 case SupervisionUrlDistribution
.RANDOM
:
1931 this.configuredSupervisionUrlIndex
= Math.floor(
1932 Utils
.secureRandom() * supervisionUrls
.length
1935 case SupervisionUrlDistribution
.CHARGING_STATION_AFFINITY
:
1936 this.configuredSupervisionUrlIndex
= (this.index
- 1) % supervisionUrls
.length
;
1940 `${this.logPrefix()} Unknown supervision url distribution '${Configuration.getSupervisionUrlDistribution()}' from values '${SupervisionUrlDistribution.toString()}', defaulting to ${
1941 SupervisionUrlDistribution.CHARGING_STATION_AFFINITY
1944 this.configuredSupervisionUrlIndex
= (this.index
- 1) % supervisionUrls
.length
;
1947 return new URL(supervisionUrls
[this.configuredSupervisionUrlIndex
]);
1949 return new URL(supervisionUrls
as string);
1952 private getHeartbeatInterval(): number {
1953 const HeartbeatInterval
= ChargingStationConfigurationUtils
.getConfigurationKey(
1955 StandardParametersKey
.HeartbeatInterval
1957 if (HeartbeatInterval
) {
1958 return Utils
.convertToInt(HeartbeatInterval
.value
) * 1000;
1960 const HeartBeatInterval
= ChargingStationConfigurationUtils
.getConfigurationKey(
1962 StandardParametersKey
.HeartBeatInterval
1964 if (HeartBeatInterval
) {
1965 return Utils
.convertToInt(HeartBeatInterval
.value
) * 1000;
1967 this.stationInfo
?.autoRegister
=== false &&
1969 `${this.logPrefix()} Heartbeat interval configuration key not set, using default value: ${
1970 Constants.DEFAULT_HEARTBEAT_INTERVAL
1973 return Constants
.DEFAULT_HEARTBEAT_INTERVAL
;
1976 private stopHeartbeat(): void {
1977 if (this.heartbeatSetInterval
) {
1978 clearInterval(this.heartbeatSetInterval
);
1982 private terminateWSConnection(): void {
1983 if (this.isWebSocketConnectionOpened() === true) {
1984 this.wsConnection
?.terminate();
1985 this.wsConnection
= null;
1989 private stopMeterValues(connectorId
: number) {
1990 if (this.getConnectorStatus(connectorId
)?.transactionSetInterval
) {
1991 clearInterval(this.getConnectorStatus(connectorId
)?.transactionSetInterval
);
1995 private getReconnectExponentialDelay(): boolean {
1996 return this.stationInfo
?.reconnectExponentialDelay
?? false;
1999 private async reconnect(): Promise
<void> {
2000 // Stop WebSocket ping
2001 this.stopWebSocketPing();
2003 this.stopHeartbeat();
2004 // Stop the ATG if needed
2005 if (this.automaticTransactionGenerator
?.configuration
?.stopOnConnectionFailure
=== true) {
2006 this.stopAutomaticTransactionGenerator();
2009 this.autoReconnectRetryCount
< this.getAutoReconnectMaxRetries() ||
2010 this.getAutoReconnectMaxRetries() === -1
2012 this.autoReconnectRetryCount
++;
2013 const reconnectDelay
= this.getReconnectExponentialDelay()
2014 ? Utils
.exponentialDelay(this.autoReconnectRetryCount
)
2015 : this.getConnectionTimeout() * 1000;
2016 const reconnectDelayWithdraw
= 1000;
2017 const reconnectTimeout
=
2018 reconnectDelay
&& reconnectDelay
- reconnectDelayWithdraw
> 0
2019 ? reconnectDelay
- reconnectDelayWithdraw
2022 `${this.logPrefix()} WebSocket connection retry in ${Utils.roundTo(
2025 )}ms, timeout ${reconnectTimeout}ms`
2027 await Utils
.sleep(reconnectDelay
);
2029 `${this.logPrefix()} WebSocket connection retry #${this.autoReconnectRetryCount.toString()}`
2031 this.openWSConnection(
2032 { ...(this.stationInfo
?.wsOptions
?? {}), handshakeTimeout
: reconnectTimeout
},
2033 { closeOpened
: true }
2035 this.wsConnectionRestarted
= true;
2036 } else if (this.getAutoReconnectMaxRetries() !== -1) {
2038 `${this.logPrefix()} WebSocket connection retries failure: maximum retries reached (${
2039 this.autoReconnectRetryCount
2040 }) or retries disabled (${this.getAutoReconnectMaxRetries()})`
2045 private getAutomaticTransactionGeneratorConfigurationFromTemplate():
2046 | AutomaticTransactionGeneratorConfiguration
2048 return this.getTemplateFromFile()?.AutomaticTransactionGenerator
;
2051 private initializeConnectorStatus(connectorId
: number): void {
2052 this.getConnectorStatus(connectorId
).idTagLocalAuthorized
= false;
2053 this.getConnectorStatus(connectorId
).idTagAuthorized
= false;
2054 this.getConnectorStatus(connectorId
).transactionRemoteStarted
= false;
2055 this.getConnectorStatus(connectorId
).transactionStarted
= false;
2056 this.getConnectorStatus(connectorId
).energyActiveImportRegisterValue
= 0;
2057 this.getConnectorStatus(connectorId
).transactionEnergyActiveImportRegisterValue
= 0;