1 // Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
3 import crypto from
'crypto';
5 import path from
'path';
6 import { URL
} from
'url';
7 import { parentPort
} from
'worker_threads';
9 import WebSocket
, { Data
, RawData
} from
'ws';
11 import BaseError from
'../exception/BaseError';
12 import OCPPError from
'../exception/OCPPError';
13 import PerformanceStatistics from
'../performance/PerformanceStatistics';
14 import type { AutomaticTransactionGeneratorConfiguration
} from
'../types/AutomaticTransactionGenerator';
15 import type ChargingStationConfiguration from
'../types/ChargingStationConfiguration';
16 import type ChargingStationInfo from
'../types/ChargingStationInfo';
17 import type ChargingStationOcppConfiguration from
'../types/ChargingStationOcppConfiguration';
18 import ChargingStationTemplate
, {
22 } from
'../types/ChargingStationTemplate';
23 import { SupervisionUrlDistribution
} from
'../types/ConfigurationData';
24 import type { ConnectorStatus
} from
'../types/ConnectorStatus';
25 import { FileType
} from
'../types/FileType';
26 import type { JsonType
} from
'../types/JsonType';
27 import { ChargePointErrorCode
} from
'../types/ocpp/ChargePointErrorCode';
28 import { ChargePointStatus
} from
'../types/ocpp/ChargePointStatus';
29 import { ChargingProfile
, ChargingRateUnitType
} from
'../types/ocpp/ChargingProfile';
31 ConnectorPhaseRotation
,
32 StandardParametersKey
,
33 SupportedFeatureProfiles
,
34 VendorDefaultParametersKey
,
35 } from
'../types/ocpp/Configuration';
36 import { ErrorType
} from
'../types/ocpp/ErrorType';
37 import { MessageType
} from
'../types/ocpp/MessageType';
38 import { MeterValue
, MeterValueMeasurand
} from
'../types/ocpp/MeterValues';
39 import { OCPPVersion
} from
'../types/ocpp/OCPPVersion';
42 BootNotificationRequest
,
46 IncomingRequestCommand
,
49 StatusNotificationRequest
,
50 } from
'../types/ocpp/Requests';
52 BootNotificationResponse
,
58 StatusNotificationResponse
,
59 } from
'../types/ocpp/Responses';
61 StopTransactionReason
,
62 StopTransactionRequest
,
63 StopTransactionResponse
,
64 } from
'../types/ocpp/Transaction';
65 import { WSError
, WebSocketCloseEventStatusCode
} from
'../types/WebSocket';
66 import Configuration from
'../utils/Configuration';
67 import Constants from
'../utils/Constants';
68 import { ACElectricUtils
, DCElectricUtils
} from
'../utils/ElectricUtils';
69 import FileUtils from
'../utils/FileUtils';
70 import logger from
'../utils/Logger';
71 import Utils from
'../utils/Utils';
72 import AuthorizedTagsCache from
'./AuthorizedTagsCache';
73 import AutomaticTransactionGenerator from
'./AutomaticTransactionGenerator';
74 import { ChargingStationConfigurationUtils
} from
'./ChargingStationConfigurationUtils';
75 import { ChargingStationUtils
} from
'./ChargingStationUtils';
76 import ChargingStationWorkerBroadcastChannel from
'./ChargingStationWorkerBroadcastChannel';
77 import { MessageChannelUtils
} from
'./MessageChannelUtils';
78 import OCPP16IncomingRequestService from
'./ocpp/1.6/OCPP16IncomingRequestService';
79 import OCPP16RequestService from
'./ocpp/1.6/OCPP16RequestService';
80 import OCPP16ResponseService from
'./ocpp/1.6/OCPP16ResponseService';
81 import { OCPP16ServiceUtils
} from
'./ocpp/1.6/OCPP16ServiceUtils';
82 import type OCPPIncomingRequestService from
'./ocpp/OCPPIncomingRequestService';
83 import type OCPPRequestService from
'./ocpp/OCPPRequestService';
84 import SharedLRUCache from
'./SharedLRUCache';
86 export default class ChargingStation
{
87 public readonly templateFile
: string;
88 public stationInfo
!: ChargingStationInfo
;
89 public started
: boolean;
90 public authorizedTagsCache
: AuthorizedTagsCache
;
91 public automaticTransactionGenerator
!: AutomaticTransactionGenerator
;
92 public ocppConfiguration
!: ChargingStationOcppConfiguration
;
93 public wsConnection
!: WebSocket
;
94 public readonly connectors
: Map
<number, ConnectorStatus
>;
95 public readonly requests
: Map
<string, CachedRequest
>;
96 public performanceStatistics
!: PerformanceStatistics
;
97 public heartbeatSetInterval
!: NodeJS
.Timeout
;
98 public ocppRequestService
!: OCPPRequestService
;
99 public bootNotificationRequest
!: BootNotificationRequest
;
100 public bootNotificationResponse
!: BootNotificationResponse
| null;
101 public powerDivider
!: number;
102 private readonly index
: number;
103 private configurationFile
!: string;
104 private configurationFileHash
!: string;
105 private connectorsConfigurationHash
!: string;
106 private ocppIncomingRequestService
!: OCPPIncomingRequestService
;
107 private readonly messageBuffer
: Set
<string>;
108 private configuredSupervisionUrl
!: URL
;
109 private wsConnectionRestarted
: boolean;
110 private autoReconnectRetryCount
: number;
111 private templateFileWatcher
!: fs
.FSWatcher
;
112 private readonly sharedLRUCache
: SharedLRUCache
;
113 private webSocketPingSetInterval
!: NodeJS
.Timeout
;
114 private readonly chargingStationWorkerBroadcastChannel
: ChargingStationWorkerBroadcastChannel
;
116 constructor(index
: number, templateFile
: string) {
118 this.templateFile
= templateFile
;
119 this.connectors
= new Map
<number, ConnectorStatus
>();
120 this.requests
= new Map
<string, CachedRequest
>();
121 this.messageBuffer
= new Set
<string>();
122 this.sharedLRUCache
= SharedLRUCache
.getInstance();
123 this.authorizedTagsCache
= AuthorizedTagsCache
.getInstance();
124 this.chargingStationWorkerBroadcastChannel
= new ChargingStationWorkerBroadcastChannel(this);
125 this.started
= false;
126 this.wsConnectionRestarted
= false;
127 this.autoReconnectRetryCount
= 0;
132 private get
wsConnectionUrl(): URL
{
134 (this.getSupervisionUrlOcppConfiguration()
135 ? ChargingStationConfigurationUtils
.getConfigurationKey(
137 this.getSupervisionUrlOcppKey()
139 : this.configuredSupervisionUrl
.href
) +
141 this.stationInfo
.chargingStationId
145 public logPrefix(): string {
146 return Utils
.logPrefix(
148 this?.stationInfo?.chargingStationId ??
149 ChargingStationUtils.getChargingStationId(this.index, this.getTemplateFromFile())
154 public getRandomIdTag(): string {
155 const authorizationFile
= ChargingStationUtils
.getAuthorizationFile(this.stationInfo
);
156 const index
= Math.floor(
157 Utils
.secureRandom() * this.authorizedTagsCache
.getAuthorizedTags(authorizationFile
).length
159 return this.authorizedTagsCache
.getAuthorizedTags(authorizationFile
)[index
];
162 public hasAuthorizedTags(): boolean {
163 return !Utils
.isEmptyArray(
164 this.authorizedTagsCache
.getAuthorizedTags(
165 ChargingStationUtils
.getAuthorizationFile(this.stationInfo
)
170 public getEnableStatistics(): boolean | undefined {
171 return !Utils
.isUndefined(this.stationInfo
.enableStatistics
)
172 ? this.stationInfo
.enableStatistics
176 public getMustAuthorizeAtRemoteStart(): boolean | undefined {
177 return this.stationInfo
.mustAuthorizeAtRemoteStart
?? true;
180 public getPayloadSchemaValidation(): boolean | undefined {
181 return this.stationInfo
.payloadSchemaValidation
?? true;
184 public getNumberOfPhases(stationInfo
?: ChargingStationInfo
): number | undefined {
185 const localStationInfo
: ChargingStationInfo
= stationInfo
?? this.stationInfo
;
186 switch (this.getCurrentOutType(stationInfo
)) {
188 return !Utils
.isUndefined(localStationInfo
.numberOfPhases
)
189 ? localStationInfo
.numberOfPhases
196 public isWebSocketConnectionOpened(): boolean {
197 return this?.wsConnection
?.readyState
=== WebSocket
.OPEN
;
200 public getRegistrationStatus(): RegistrationStatus
{
201 return this?.bootNotificationResponse
?.status;
204 public isInUnknownState(): boolean {
205 return Utils
.isNullOrUndefined(this?.bootNotificationResponse
?.status);
208 public isInPendingState(): boolean {
209 return this?.bootNotificationResponse
?.status === RegistrationStatus
.PENDING
;
212 public isInAcceptedState(): boolean {
213 return this?.bootNotificationResponse
?.status === RegistrationStatus
.ACCEPTED
;
216 public isInRejectedState(): boolean {
217 return this?.bootNotificationResponse
?.status === RegistrationStatus
.REJECTED
;
220 public isRegistered(): boolean {
221 return !this.isInUnknownState() && (this.isInAcceptedState() || this.isInPendingState());
224 public isChargingStationAvailable(): boolean {
225 return this.getConnectorStatus(0).availability
=== AvailabilityType
.OPERATIVE
;
228 public isConnectorAvailable(id
: number): boolean {
229 return id
> 0 && this.getConnectorStatus(id
).availability
=== AvailabilityType
.OPERATIVE
;
232 public getNumberOfConnectors(): number {
233 return this.connectors
.get(0) ? this.connectors
.size
- 1 : this.connectors
.size
;
236 public getConnectorStatus(id
: number): ConnectorStatus
{
237 return this.connectors
.get(id
);
240 public getCurrentOutType(stationInfo
?: ChargingStationInfo
): CurrentType
{
241 return (stationInfo
?? this.stationInfo
).currentOutType
?? CurrentType
.AC
;
244 public getOcppStrictCompliance(): boolean {
245 return this.stationInfo
?.ocppStrictCompliance
?? false;
248 public getVoltageOut(stationInfo
?: ChargingStationInfo
): number | undefined {
249 const defaultVoltageOut
= ChargingStationUtils
.getDefaultVoltageOut(
250 this.getCurrentOutType(stationInfo
),
254 const localStationInfo
: ChargingStationInfo
= stationInfo
?? this.stationInfo
;
255 return !Utils
.isUndefined(localStationInfo
.voltageOut
)
256 ? localStationInfo
.voltageOut
260 public getConnectorMaximumAvailablePower(connectorId
: number): number {
261 let connectorAmperageLimitationPowerLimit
: number;
263 !Utils
.isNullOrUndefined(this.getAmperageLimitation()) &&
264 this.getAmperageLimitation() < this.stationInfo
.maximumAmperage
266 connectorAmperageLimitationPowerLimit
=
267 (this.getCurrentOutType() === CurrentType
.AC
268 ? ACElectricUtils
.powerTotal(
269 this.getNumberOfPhases(),
270 this.getVoltageOut(),
271 this.getAmperageLimitation() * this.getNumberOfConnectors()
273 : DCElectricUtils
.power(this.getVoltageOut(), this.getAmperageLimitation())) /
276 const connectorMaximumPower
= this.getMaximumPower() / this.powerDivider
;
277 const connectorChargingProfilePowerLimit
= this.getChargingProfilePowerLimit(connectorId
);
279 isNaN(connectorMaximumPower
) ? Infinity : connectorMaximumPower
,
280 isNaN(connectorAmperageLimitationPowerLimit
)
282 : connectorAmperageLimitationPowerLimit
,
283 isNaN(connectorChargingProfilePowerLimit
) ? Infinity : connectorChargingProfilePowerLimit
287 public getTransactionIdTag(transactionId
: number): string | undefined {
288 for (const connectorId
of this.connectors
.keys()) {
289 if (connectorId
> 0 && this.getConnectorStatus(connectorId
).transactionId
=== transactionId
) {
290 return this.getConnectorStatus(connectorId
).transactionIdTag
;
295 public getOutOfOrderEndMeterValues(): boolean {
296 return this.stationInfo
?.outOfOrderEndMeterValues
?? false;
299 public getBeginEndMeterValues(): boolean {
300 return this.stationInfo
?.beginEndMeterValues
?? false;
303 public getMeteringPerTransaction(): boolean {
304 return this.stationInfo
?.meteringPerTransaction
?? true;
307 public getTransactionDataMeterValues(): boolean {
308 return this.stationInfo
?.transactionDataMeterValues
?? false;
311 public getMainVoltageMeterValues(): boolean {
312 return this.stationInfo
?.mainVoltageMeterValues
?? true;
315 public getPhaseLineToLineVoltageMeterValues(): boolean {
316 return this.stationInfo
?.phaseLineToLineVoltageMeterValues
?? false;
319 public getCustomValueLimitationMeterValues(): boolean {
320 return this.stationInfo
?.customValueLimitationMeterValues
?? true;
323 public getConnectorIdByTransactionId(transactionId
: number): number | undefined {
324 for (const connectorId
of this.connectors
.keys()) {
327 this.getConnectorStatus(connectorId
)?.transactionId
=== transactionId
334 public getEnergyActiveImportRegisterByTransactionId(
335 transactionId
: number,
338 return this.getEnergyActiveImportRegister(
339 this.getConnectorStatus(this.getConnectorIdByTransactionId(transactionId
)),
344 public getEnergyActiveImportRegisterByConnectorId(connectorId
: number): number {
345 return this.getEnergyActiveImportRegister(this.getConnectorStatus(connectorId
));
348 public getAuthorizeRemoteTxRequests(): boolean {
349 const authorizeRemoteTxRequests
= ChargingStationConfigurationUtils
.getConfigurationKey(
351 StandardParametersKey
.AuthorizeRemoteTxRequests
353 return authorizeRemoteTxRequests
354 ? Utils
.convertToBoolean(authorizeRemoteTxRequests
.value
)
358 public getLocalAuthListEnabled(): boolean {
359 const localAuthListEnabled
= ChargingStationConfigurationUtils
.getConfigurationKey(
361 StandardParametersKey
.LocalAuthListEnabled
363 return localAuthListEnabled
? Utils
.convertToBoolean(localAuthListEnabled
.value
) : false;
366 public startHeartbeat(): void {
368 this.getHeartbeatInterval() &&
369 this.getHeartbeatInterval() > 0 &&
370 !this.heartbeatSetInterval
372 // eslint-disable-next-line @typescript-eslint/no-misused-promises
373 this.heartbeatSetInterval
= setInterval(async (): Promise
<void> => {
374 await this.ocppRequestService
.requestHandler
<HeartbeatRequest
, HeartbeatResponse
>(
376 RequestCommand
.HEARTBEAT
378 }, this.getHeartbeatInterval());
381 ' Heartbeat started every ' +
382 Utils
.formatDurationMilliSeconds(this.getHeartbeatInterval())
384 } else if (this.heartbeatSetInterval
) {
387 ' Heartbeat already started every ' +
388 Utils
.formatDurationMilliSeconds(this.getHeartbeatInterval())
392 `${this.logPrefix()} Heartbeat interval set to ${
393 this.getHeartbeatInterval()
394 ? Utils.formatDurationMilliSeconds(this.getHeartbeatInterval())
395 : this.getHeartbeatInterval()
396 }, not starting the heartbeat`
401 public restartHeartbeat(): void {
403 this.stopHeartbeat();
405 this.startHeartbeat();
408 public restartWebSocketPing(): void {
409 // Stop WebSocket ping
410 this.stopWebSocketPing();
411 // Start WebSocket ping
412 this.startWebSocketPing();
415 public startMeterValues(connectorId
: number, interval
: number): void {
416 if (connectorId
=== 0) {
418 `${this.logPrefix()} Trying to start MeterValues on connector Id ${connectorId.toString()}`
422 if (!this.getConnectorStatus(connectorId
)) {
424 `${this.logPrefix()} Trying to start MeterValues on non existing connector Id ${connectorId.toString()}`
428 if (this.getConnectorStatus(connectorId
)?.transactionStarted
=== false) {
430 `${this.logPrefix()} Trying to start MeterValues on connector Id ${connectorId} with no transaction started`
434 this.getConnectorStatus(connectorId
)?.transactionStarted
=== true &&
435 !this.getConnectorStatus(connectorId
)?.transactionId
438 `${this.logPrefix()} Trying to start MeterValues on connector Id ${connectorId} with no transaction id`
443 // eslint-disable-next-line @typescript-eslint/no-misused-promises
444 this.getConnectorStatus(connectorId
).transactionSetInterval
= setInterval(
445 // eslint-disable-next-line @typescript-eslint/no-misused-promises
446 async (): Promise
<void> => {
447 // FIXME: Implement OCPP version agnostic helpers
448 const meterValue
: MeterValue
= OCPP16ServiceUtils
.buildMeterValue(
451 this.getConnectorStatus(connectorId
).transactionId
,
454 await this.ocppRequestService
.requestHandler
<MeterValuesRequest
, MeterValuesResponse
>(
456 RequestCommand
.METER_VALUES
,
459 transactionId
: this.getConnectorStatus(connectorId
).transactionId
,
460 meterValue
: [meterValue
],
468 `${this.logPrefix()} Charging station ${
469 StandardParametersKey.MeterValueSampleInterval
470 } configuration set to ${
471 interval ? Utils.formatDurationMilliSeconds(interval) : interval
472 }, not sending MeterValues`
477 public start(): void {
478 if (this.getEnableStatistics()) {
479 this.performanceStatistics
.start();
481 this.openWSConnection();
482 // Monitor charging station template file
483 this.templateFileWatcher
= FileUtils
.watchJsonFile(
485 FileType
.ChargingStationTemplate
,
488 (event
, filename
): void => {
489 if (filename
&& event
=== 'change') {
492 `${this.logPrefix()} ${FileType.ChargingStationTemplate} ${
494 } file have changed, reload`
496 this.sharedLRUCache
.deleteChargingStationTemplate(this.stationInfo
?.templateHash
);
500 this.stopAutomaticTransactionGenerator();
501 if (this.getAutomaticTransactionGeneratorConfigurationFromTemplate()?.enable
) {
502 this.startAutomaticTransactionGenerator();
504 if (this.getEnableStatistics()) {
505 this.performanceStatistics
.restart();
507 this.performanceStatistics
.stop();
509 // FIXME?: restart heartbeat and WebSocket ping when their interval values have changed
512 `${this.logPrefix()} ${FileType.ChargingStationTemplate} file monitoring error:`,
519 parentPort
.postMessage(MessageChannelUtils
.buildStartedMessage(this));
522 public async stop(): Promise
<void> {
523 for (const connectorId
of this.connectors
.keys()) {
524 if (connectorId
> 0) {
525 await this.ocppRequestService
.requestHandler
<
526 StatusNotificationRequest
,
527 StatusNotificationResponse
528 >(this, RequestCommand
.STATUS_NOTIFICATION
, {
530 status: ChargePointStatus
.UNAVAILABLE
,
531 errorCode
: ChargePointErrorCode
.NO_ERROR
,
533 this.getConnectorStatus(connectorId
).status = ChargePointStatus
.UNAVAILABLE
;
536 this.closeWSConnection();
537 if (this.getEnableStatistics()) {
538 this.performanceStatistics
.stop();
540 this.sharedLRUCache
.deleteChargingStationConfiguration(this.configurationFileHash
);
541 this.templateFileWatcher
.close();
542 this.sharedLRUCache
.deleteChargingStationTemplate(this.stationInfo
?.templateHash
);
543 this.bootNotificationResponse
= null;
544 this.started
= false;
545 parentPort
.postMessage(MessageChannelUtils
.buildStoppedMessage(this));
548 public async reset(): Promise
<void> {
550 await Utils
.sleep(this.stationInfo
.resetTime
);
555 public saveOcppConfiguration(): void {
556 if (this.getOcppPersistentConfiguration()) {
557 this.saveConfiguration();
561 public getChargingProfilePowerLimit(connectorId
: number): number | undefined {
562 let limit
: number, matchingChargingProfile
: ChargingProfile
;
563 let chargingProfiles
: ChargingProfile
[] = [];
564 // Get charging profiles for connector and sort by stack level
565 chargingProfiles
= this.getConnectorStatus(connectorId
).chargingProfiles
.sort(
566 (a
, b
) => b
.stackLevel
- a
.stackLevel
568 // Get profiles on connector 0
569 if (this.getConnectorStatus(0).chargingProfiles
) {
570 chargingProfiles
.push(
571 ...this.getConnectorStatus(0).chargingProfiles
.sort((a
, b
) => b
.stackLevel
- a
.stackLevel
)
574 if (!Utils
.isEmptyArray(chargingProfiles
)) {
575 const result
= ChargingStationUtils
.getLimitFromChargingProfiles(
579 if (!Utils
.isNullOrUndefined(result
)) {
580 limit
= result
.limit
;
581 matchingChargingProfile
= result
.matchingChargingProfile
;
582 switch (this.getCurrentOutType()) {
585 matchingChargingProfile
.chargingSchedule
.chargingRateUnit
===
586 ChargingRateUnitType
.WATT
588 : ACElectricUtils
.powerTotal(this.getNumberOfPhases(), this.getVoltageOut(), limit
);
592 matchingChargingProfile
.chargingSchedule
.chargingRateUnit
===
593 ChargingRateUnitType
.WATT
595 : DCElectricUtils
.power(this.getVoltageOut(), limit
);
597 const connectorMaximumPower
= this.getMaximumPower() / this.powerDivider
;
598 if (limit
> connectorMaximumPower
) {
600 `${this.logPrefix()} Charging profile id ${
601 matchingChargingProfile.chargingProfileId
602 } limit is greater than connector id ${connectorId} maximum, dump charging profiles' stack: %j`,
603 this.getConnectorStatus(connectorId
).chargingProfiles
605 limit
= connectorMaximumPower
;
612 public setChargingProfile(connectorId
: number, cp
: ChargingProfile
): void {
613 if (Utils
.isNullOrUndefined(this.getConnectorStatus(connectorId
).chargingProfiles
)) {
615 `${this.logPrefix()} Trying to set a charging profile on connectorId ${connectorId} with an uninitialized charging profiles array attribute, applying deferred initialization`
617 this.getConnectorStatus(connectorId
).chargingProfiles
= [];
619 if (Array.isArray(this.getConnectorStatus(connectorId
).chargingProfiles
) === false) {
621 `${this.logPrefix()} Trying to set a charging profile on connectorId ${connectorId} with an improper attribute type for the charging profiles array, applying proper type initialization`
623 this.getConnectorStatus(connectorId
).chargingProfiles
= [];
625 let cpReplaced
= false;
626 if (!Utils
.isEmptyArray(this.getConnectorStatus(connectorId
).chargingProfiles
)) {
627 this.getConnectorStatus(connectorId
).chargingProfiles
?.forEach(
628 (chargingProfile
: ChargingProfile
, index
: number) => {
630 chargingProfile
.chargingProfileId
=== cp
.chargingProfileId
||
631 (chargingProfile
.stackLevel
=== cp
.stackLevel
&&
632 chargingProfile
.chargingProfilePurpose
=== cp
.chargingProfilePurpose
)
634 this.getConnectorStatus(connectorId
).chargingProfiles
[index
] = cp
;
640 !cpReplaced
&& this.getConnectorStatus(connectorId
).chargingProfiles
?.push(cp
);
643 public resetConnectorStatus(connectorId
: number): void {
644 this.getConnectorStatus(connectorId
).idTagLocalAuthorized
= false;
645 this.getConnectorStatus(connectorId
).idTagAuthorized
= false;
646 this.getConnectorStatus(connectorId
).transactionRemoteStarted
= false;
647 this.getConnectorStatus(connectorId
).transactionStarted
= false;
648 delete this.getConnectorStatus(connectorId
).localAuthorizeIdTag
;
649 delete this.getConnectorStatus(connectorId
).authorizeIdTag
;
650 delete this.getConnectorStatus(connectorId
).transactionId
;
651 delete this.getConnectorStatus(connectorId
).transactionIdTag
;
652 this.getConnectorStatus(connectorId
).transactionEnergyActiveImportRegisterValue
= 0;
653 delete this.getConnectorStatus(connectorId
).transactionBeginMeterValue
;
654 this.stopMeterValues(connectorId
);
657 public hasFeatureProfile(featureProfile
: SupportedFeatureProfiles
) {
658 return ChargingStationConfigurationUtils
.getConfigurationKey(
660 StandardParametersKey
.SupportedFeatureProfiles
661 )?.value
.includes(featureProfile
);
664 public bufferMessage(message
: string): void {
665 this.messageBuffer
.add(message
);
668 public openWSConnection(
669 options
: WsOptions
= this.stationInfo
?.wsOptions
?? {},
670 params
: { closeOpened
?: boolean; terminateOpened
?: boolean } = {
672 terminateOpened
: false,
675 options
.handshakeTimeout
= options
?.handshakeTimeout
?? this.getConnectionTimeout() * 1000;
676 params
.closeOpened
= params
?.closeOpened
?? false;
677 params
.terminateOpened
= params
?.terminateOpened
?? false;
679 !Utils
.isNullOrUndefined(this.stationInfo
.supervisionUser
) &&
680 !Utils
.isNullOrUndefined(this.stationInfo
.supervisionPassword
)
682 options
.auth
= `${this.stationInfo.supervisionUser}:${this.stationInfo.supervisionPassword}`;
684 if (params
?.closeOpened
) {
685 this.closeWSConnection();
687 if (params
?.terminateOpened
) {
688 this.terminateWSConnection();
690 let protocol
: string;
691 switch (this.getOcppVersion()) {
692 case OCPPVersion
.VERSION_16
:
693 protocol
= 'ocpp' + OCPPVersion
.VERSION_16
;
696 this.handleUnsupportedVersion(this.getOcppVersion());
700 if (this.isWebSocketConnectionOpened()) {
702 `${this.logPrefix()} OCPP connection to URL ${this.wsConnectionUrl.toString()} is already opened`
708 `${this.logPrefix()} Open OCPP connection to URL ${this.wsConnectionUrl.toString()}`
711 this.wsConnection
= new WebSocket(this.wsConnectionUrl
, protocol
, options
);
713 // Handle WebSocket message
714 this.wsConnection
.on(
716 this.onMessage
.bind(this) as (this: WebSocket
, data
: RawData
, isBinary
: boolean) => void
718 // Handle WebSocket error
719 this.wsConnection
.on(
721 this.onError
.bind(this) as (this: WebSocket
, error
: Error) => void
723 // Handle WebSocket close
724 this.wsConnection
.on(
726 this.onClose
.bind(this) as (this: WebSocket
, code
: number, reason
: Buffer
) => void
728 // Handle WebSocket open
729 this.wsConnection
.on('open', this.onOpen
.bind(this) as (this: WebSocket
) => void);
730 // Handle WebSocket ping
731 this.wsConnection
.on('ping', this.onPing
.bind(this) as (this: WebSocket
, data
: Buffer
) => void);
732 // Handle WebSocket pong
733 this.wsConnection
.on('pong', this.onPong
.bind(this) as (this: WebSocket
, data
: Buffer
) => void);
736 public closeWSConnection(): void {
737 if (this.isWebSocketConnectionOpened()) {
738 this.wsConnection
.close();
739 this.wsConnection
= null;
743 public startAutomaticTransactionGenerator(connectorIds
?: number[]): void {
744 if (!this.automaticTransactionGenerator
) {
745 this.automaticTransactionGenerator
= AutomaticTransactionGenerator
.getInstance(
746 this.getAutomaticTransactionGeneratorConfigurationFromTemplate(),
750 if (!Utils
.isEmptyArray(connectorIds
)) {
751 for (const connectorId
of connectorIds
) {
752 this.automaticTransactionGenerator
.startConnector(connectorId
);
755 this.automaticTransactionGenerator
.start();
759 public stopAutomaticTransactionGenerator(connectorIds
?: number[]): void {
760 if (!Utils
.isEmptyArray(connectorIds
)) {
761 for (const connectorId
of connectorIds
) {
762 this.automaticTransactionGenerator
?.stopConnector(connectorId
);
765 this.automaticTransactionGenerator
?.stop();
766 this.automaticTransactionGenerator
= null;
770 public getNumberOfRunningTransactions(): number {
772 for (const connectorId
of this.connectors
.keys()) {
773 if (connectorId
> 0 && this.getConnectorStatus(connectorId
)?.transactionStarted
=== true) {
780 public async stopRunningTransactions(reason
= StopTransactionReason
.NONE
): Promise
<void> {
781 for (const connectorId
of this.connectors
.keys()) {
782 if (connectorId
> 0 && this.getConnectorStatus(connectorId
)?.transactionStarted
=== true) {
783 await this.stopTransactionOnConnector(connectorId
, reason
);
788 public async stopTransactionOnConnector(
790 reason
= StopTransactionReason
.NONE
791 ): Promise
<StopTransactionResponse
> {
792 const transactionId
= this.getConnectorStatus(connectorId
).transactionId
;
794 this.getBeginEndMeterValues() &&
795 this.getOcppStrictCompliance() &&
796 !this.getOutOfOrderEndMeterValues()
798 // FIXME: Implement OCPP version agnostic helpers
799 const transactionEndMeterValue
= OCPP16ServiceUtils
.buildTransactionEndMeterValue(
802 this.getEnergyActiveImportRegisterByTransactionId(transactionId
)
804 await this.ocppRequestService
.requestHandler
<MeterValuesRequest
, MeterValuesResponse
>(
806 RequestCommand
.METER_VALUES
,
810 meterValue
: [transactionEndMeterValue
],
814 return this.ocppRequestService
.requestHandler
<StopTransactionRequest
, StopTransactionResponse
>(
816 RequestCommand
.STOP_TRANSACTION
,
819 meterStop
: this.getEnergyActiveImportRegisterByTransactionId(transactionId
, true),
820 idTag
: this.getTransactionIdTag(transactionId
),
826 private flushMessageBuffer(): void {
827 if (this.messageBuffer
.size
> 0) {
828 this.messageBuffer
.forEach((message
) => {
829 // TODO: evaluate the need to track performance
830 this.wsConnection
.send(message
);
831 this.messageBuffer
.delete(message
);
836 private getSupervisionUrlOcppConfiguration(): boolean {
837 return this.stationInfo
.supervisionUrlOcppConfiguration
?? false;
840 private getSupervisionUrlOcppKey(): string {
841 return this.stationInfo
.supervisionUrlOcppKey
?? VendorDefaultParametersKey
.ConnectionUrl
;
844 private getTemplateFromFile(): ChargingStationTemplate
| null {
845 let template
: ChargingStationTemplate
= null;
847 if (this.sharedLRUCache
.hasChargingStationTemplate(this.stationInfo
?.templateHash
)) {
848 template
= this.sharedLRUCache
.getChargingStationTemplate(this.stationInfo
.templateHash
);
850 const measureId
= `${FileType.ChargingStationTemplate} read`;
851 const beginId
= PerformanceStatistics
.beginMeasure(measureId
);
852 template
= JSON
.parse(
853 fs
.readFileSync(this.templateFile
, 'utf8')
854 ) as ChargingStationTemplate
;
855 PerformanceStatistics
.endMeasure(measureId
, beginId
);
856 template
.templateHash
= crypto
857 .createHash(Constants
.DEFAULT_HASH_ALGORITHM
)
858 .update(JSON
.stringify(template
))
860 this.sharedLRUCache
.setChargingStationTemplate(template
);
863 FileUtils
.handleFileException(
865 FileType
.ChargingStationTemplate
,
867 error
as NodeJS
.ErrnoException
873 private getStationInfoFromTemplate(): ChargingStationInfo
{
874 const stationTemplate
: ChargingStationTemplate
= this.getTemplateFromFile();
875 if (Utils
.isNullOrUndefined(stationTemplate
)) {
876 const errorMsg
= 'Failed to read charging station template file';
877 logger
.error(`${this.logPrefix()} ${errorMsg}`);
878 throw new BaseError(errorMsg
);
880 if (Utils
.isEmptyObject(stationTemplate
)) {
881 const errorMsg
= `Empty charging station information from template file ${this.templateFile}`;
882 logger
.error(`${this.logPrefix()} ${errorMsg}`);
883 throw new BaseError(errorMsg
);
885 // Deprecation template keys section
886 ChargingStationUtils
.warnDeprecatedTemplateKey(
891 "Use 'supervisionUrls' instead"
893 ChargingStationUtils
.convertDeprecatedTemplateKey(
898 const stationInfo
: ChargingStationInfo
=
899 ChargingStationUtils
.stationTemplateToStationInfo(stationTemplate
);
900 stationInfo
.hashId
= ChargingStationUtils
.getHashId(this.index
, stationTemplate
);
901 stationInfo
.chargingStationId
= ChargingStationUtils
.getChargingStationId(
905 ChargingStationUtils
.createSerialNumber(stationTemplate
, stationInfo
);
906 if (!Utils
.isEmptyArray(stationTemplate
.power
)) {
907 stationTemplate
.power
= stationTemplate
.power
as number[];
908 const powerArrayRandomIndex
= Math.floor(Utils
.secureRandom() * stationTemplate
.power
.length
);
909 stationInfo
.maximumPower
=
910 stationTemplate
.powerUnit
=== PowerUnits
.KILO_WATT
911 ? stationTemplate
.power
[powerArrayRandomIndex
] * 1000
912 : stationTemplate
.power
[powerArrayRandomIndex
];
914 stationTemplate
.power
= stationTemplate
.power
as number;
915 stationInfo
.maximumPower
=
916 stationTemplate
.powerUnit
=== PowerUnits
.KILO_WATT
917 ? stationTemplate
.power
* 1000
918 : stationTemplate
.power
;
920 stationInfo
.resetTime
= stationTemplate
.resetTime
921 ? stationTemplate
.resetTime
* 1000
922 : Constants
.CHARGING_STATION_DEFAULT_RESET_TIME
;
923 const configuredMaxConnectors
= ChargingStationUtils
.getConfiguredNumberOfConnectors(
927 ChargingStationUtils
.checkConfiguredMaxConnectors(
928 configuredMaxConnectors
,
932 const templateMaxConnectors
=
933 ChargingStationUtils
.getTemplateMaxNumberOfConnectors(stationTemplate
);
934 ChargingStationUtils
.checkTemplateMaxConnectors(
935 templateMaxConnectors
,
940 configuredMaxConnectors
>
941 (stationTemplate
?.Connectors
[0] ? templateMaxConnectors
- 1 : templateMaxConnectors
) &&
942 !stationTemplate
?.randomConnectors
945 `${this.logPrefix()} Number of connectors exceeds the number of connector configurations in template ${
947 }, forcing random connector configurations affectation`
949 stationInfo
.randomConnectors
= true;
951 // Build connectors if needed (FIXME: should be factored out)
952 this.initializeConnectors(stationInfo
, configuredMaxConnectors
, templateMaxConnectors
);
953 stationInfo
.maximumAmperage
= this.getMaximumAmperage(stationInfo
);
954 ChargingStationUtils
.createStationInfoHash(stationInfo
);
958 private getStationInfoFromFile(): ChargingStationInfo
| null {
959 let stationInfo
: ChargingStationInfo
= null;
960 this.getStationInfoPersistentConfiguration() &&
961 (stationInfo
= this.getConfigurationFromFile()?.stationInfo
?? null);
962 stationInfo
&& ChargingStationUtils
.createStationInfoHash(stationInfo
);
966 private getStationInfo(): ChargingStationInfo
{
967 const stationInfoFromTemplate
: ChargingStationInfo
= this.getStationInfoFromTemplate();
968 const stationInfoFromFile
: ChargingStationInfo
= this.getStationInfoFromFile();
969 // Priority: charging station info from template > charging station info from configuration file > charging station info attribute
970 if (stationInfoFromFile
?.templateHash
=== stationInfoFromTemplate
.templateHash
) {
971 if (this.stationInfo
?.infoHash
=== stationInfoFromFile
?.infoHash
) {
972 return this.stationInfo
;
974 return stationInfoFromFile
;
976 stationInfoFromFile
&&
977 ChargingStationUtils
.propagateSerialNumber(
978 this.getTemplateFromFile(),
980 stationInfoFromTemplate
982 return stationInfoFromTemplate
;
985 private saveStationInfo(): void {
986 if (this.getStationInfoPersistentConfiguration()) {
987 this.saveConfiguration();
991 private getOcppVersion(): OCPPVersion
{
992 return this.stationInfo
.ocppVersion
?? OCPPVersion
.VERSION_16
;
995 private getOcppPersistentConfiguration(): boolean {
996 return this.stationInfo
?.ocppPersistentConfiguration
?? true;
999 private getStationInfoPersistentConfiguration(): boolean {
1000 return this.stationInfo
?.stationInfoPersistentConfiguration
?? true;
1003 private handleUnsupportedVersion(version
: OCPPVersion
) {
1004 const errMsg
= `Unsupported protocol version '${version}' configured in template file ${this.templateFile}`;
1005 logger
.error(`${this.logPrefix()} ${errMsg}`);
1006 throw new BaseError(errMsg
);
1009 private initialize(): void {
1010 this.configurationFile
= path
.join(
1011 path
.dirname(this.templateFile
.replace('station-templates', 'configurations')),
1012 ChargingStationUtils
.getHashId(this.index
, this.getTemplateFromFile()) + '.json'
1014 this.stationInfo
= this.getStationInfo();
1015 this.saveStationInfo();
1016 logger
.info(`${this.logPrefix()} Charging station hashId '${this.stationInfo.hashId}'`);
1017 // Avoid duplication of connectors related information in RAM
1018 this.stationInfo
?.Connectors
&& delete this.stationInfo
.Connectors
;
1019 this.configuredSupervisionUrl
= this.getConfiguredSupervisionUrl();
1020 if (this.getEnableStatistics()) {
1021 this.performanceStatistics
= PerformanceStatistics
.getInstance(
1022 this.stationInfo
.hashId
,
1023 this.stationInfo
.chargingStationId
,
1024 this.configuredSupervisionUrl
1027 this.bootNotificationRequest
= ChargingStationUtils
.createBootNotificationRequest(
1030 this.powerDivider
= this.getPowerDivider();
1031 // OCPP configuration
1032 this.ocppConfiguration
= this.getOcppConfiguration();
1033 this.initializeOcppConfiguration();
1034 switch (this.getOcppVersion()) {
1035 case OCPPVersion
.VERSION_16
:
1036 this.ocppIncomingRequestService
=
1037 OCPP16IncomingRequestService
.getInstance
<OCPP16IncomingRequestService
>();
1038 this.ocppRequestService
= OCPP16RequestService
.getInstance
<OCPP16RequestService
>(
1039 OCPP16ResponseService
.getInstance
<OCPP16ResponseService
>()
1043 this.handleUnsupportedVersion(this.getOcppVersion());
1046 if (this.stationInfo
?.autoRegister
) {
1047 this.bootNotificationResponse
= {
1048 currentTime
: new Date().toISOString(),
1049 interval
: this.getHeartbeatInterval() / 1000,
1050 status: RegistrationStatus
.ACCEPTED
,
1055 private initializeOcppConfiguration(): void {
1057 !ChargingStationConfigurationUtils
.getConfigurationKey(
1059 StandardParametersKey
.HeartbeatInterval
1062 ChargingStationConfigurationUtils
.addConfigurationKey(
1064 StandardParametersKey
.HeartbeatInterval
,
1069 !ChargingStationConfigurationUtils
.getConfigurationKey(
1071 StandardParametersKey
.HeartBeatInterval
1074 ChargingStationConfigurationUtils
.addConfigurationKey(
1076 StandardParametersKey
.HeartBeatInterval
,
1082 this.getSupervisionUrlOcppConfiguration() &&
1083 !ChargingStationConfigurationUtils
.getConfigurationKey(this, this.getSupervisionUrlOcppKey())
1085 ChargingStationConfigurationUtils
.addConfigurationKey(
1087 this.getSupervisionUrlOcppKey(),
1088 this.configuredSupervisionUrl
.href
,
1092 !this.getSupervisionUrlOcppConfiguration() &&
1093 ChargingStationConfigurationUtils
.getConfigurationKey(this, this.getSupervisionUrlOcppKey())
1095 ChargingStationConfigurationUtils
.deleteConfigurationKey(
1097 this.getSupervisionUrlOcppKey(),
1102 this.stationInfo
.amperageLimitationOcppKey
&&
1103 !ChargingStationConfigurationUtils
.getConfigurationKey(
1105 this.stationInfo
.amperageLimitationOcppKey
1108 ChargingStationConfigurationUtils
.addConfigurationKey(
1110 this.stationInfo
.amperageLimitationOcppKey
,
1112 this.stationInfo
.maximumAmperage
*
1113 ChargingStationUtils
.getAmperageLimitationUnitDivider(this.stationInfo
)
1118 !ChargingStationConfigurationUtils
.getConfigurationKey(
1120 StandardParametersKey
.SupportedFeatureProfiles
1123 ChargingStationConfigurationUtils
.addConfigurationKey(
1125 StandardParametersKey
.SupportedFeatureProfiles
,
1126 `${SupportedFeatureProfiles.Core},${SupportedFeatureProfiles.FirmwareManagement},${SupportedFeatureProfiles.LocalAuthListManagement},${SupportedFeatureProfiles.SmartCharging},${SupportedFeatureProfiles.RemoteTrigger}`
1129 ChargingStationConfigurationUtils
.addConfigurationKey(
1131 StandardParametersKey
.NumberOfConnectors
,
1132 this.getNumberOfConnectors().toString(),
1137 !ChargingStationConfigurationUtils
.getConfigurationKey(
1139 StandardParametersKey
.MeterValuesSampledData
1142 ChargingStationConfigurationUtils
.addConfigurationKey(
1144 StandardParametersKey
.MeterValuesSampledData
,
1145 MeterValueMeasurand
.ENERGY_ACTIVE_IMPORT_REGISTER
1149 !ChargingStationConfigurationUtils
.getConfigurationKey(
1151 StandardParametersKey
.ConnectorPhaseRotation
1154 const connectorPhaseRotation
= [];
1155 for (const connectorId
of this.connectors
.keys()) {
1157 if (connectorId
=== 0 && this.getNumberOfPhases() === 0) {
1158 connectorPhaseRotation
.push(`${connectorId}.${ConnectorPhaseRotation.RST}`);
1159 } else if (connectorId
> 0 && this.getNumberOfPhases() === 0) {
1160 connectorPhaseRotation
.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`);
1162 } else if (connectorId
> 0 && this.getNumberOfPhases() === 1) {
1163 connectorPhaseRotation
.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`);
1164 } else if (connectorId
> 0 && this.getNumberOfPhases() === 3) {
1165 connectorPhaseRotation
.push(`${connectorId}.${ConnectorPhaseRotation.RST}`);
1168 ChargingStationConfigurationUtils
.addConfigurationKey(
1170 StandardParametersKey
.ConnectorPhaseRotation
,
1171 connectorPhaseRotation
.toString()
1175 !ChargingStationConfigurationUtils
.getConfigurationKey(
1177 StandardParametersKey
.AuthorizeRemoteTxRequests
1180 ChargingStationConfigurationUtils
.addConfigurationKey(
1182 StandardParametersKey
.AuthorizeRemoteTxRequests
,
1187 !ChargingStationConfigurationUtils
.getConfigurationKey(
1189 StandardParametersKey
.LocalAuthListEnabled
1191 ChargingStationConfigurationUtils
.getConfigurationKey(
1193 StandardParametersKey
.SupportedFeatureProfiles
1194 )?.value
.includes(SupportedFeatureProfiles
.LocalAuthListManagement
)
1196 ChargingStationConfigurationUtils
.addConfigurationKey(
1198 StandardParametersKey
.LocalAuthListEnabled
,
1203 !ChargingStationConfigurationUtils
.getConfigurationKey(
1205 StandardParametersKey
.ConnectionTimeOut
1208 ChargingStationConfigurationUtils
.addConfigurationKey(
1210 StandardParametersKey
.ConnectionTimeOut
,
1211 Constants
.DEFAULT_CONNECTION_TIMEOUT
.toString()
1214 this.saveOcppConfiguration();
1217 private initializeConnectors(
1218 stationInfo
: ChargingStationInfo
,
1219 configuredMaxConnectors
: number,
1220 templateMaxConnectors
: number
1222 if (!stationInfo
?.Connectors
&& this.connectors
.size
=== 0) {
1223 const logMsg
= `No already defined connectors and charging station information from template ${this.templateFile} with no connectors configuration defined`;
1224 logger
.error(`${this.logPrefix()} ${logMsg}`);
1225 throw new BaseError(logMsg
);
1227 if (!stationInfo
?.Connectors
[0]) {
1229 `${this.logPrefix()} Charging station information from template ${
1231 } with no connector Id 0 configuration`
1234 if (stationInfo
?.Connectors
) {
1235 const connectorsConfigHash
= crypto
1236 .createHash(Constants
.DEFAULT_HASH_ALGORITHM
)
1237 .update(JSON
.stringify(stationInfo
?.Connectors
) + configuredMaxConnectors
.toString())
1239 const connectorsConfigChanged
=
1240 this.connectors
?.size
!== 0 && this.connectorsConfigurationHash
!== connectorsConfigHash
;
1241 if (this.connectors
?.size
=== 0 || connectorsConfigChanged
) {
1242 connectorsConfigChanged
&& this.connectors
.clear();
1243 this.connectorsConfigurationHash
= connectorsConfigHash
;
1244 // Add connector Id 0
1245 let lastConnector
= '0';
1246 for (lastConnector
in stationInfo
?.Connectors
) {
1247 const lastConnectorId
= Utils
.convertToInt(lastConnector
);
1249 lastConnectorId
=== 0 &&
1250 this.getUseConnectorId0(stationInfo
) &&
1251 stationInfo
?.Connectors
[lastConnector
]
1253 this.connectors
.set(
1255 Utils
.cloneObject
<ConnectorStatus
>(stationInfo
?.Connectors
[lastConnector
])
1257 this.getConnectorStatus(lastConnectorId
).availability
= AvailabilityType
.OPERATIVE
;
1258 if (Utils
.isUndefined(this.getConnectorStatus(lastConnectorId
)?.chargingProfiles
)) {
1259 this.getConnectorStatus(lastConnectorId
).chargingProfiles
= [];
1263 // Generate all connectors
1264 if ((stationInfo
?.Connectors
[0] ? templateMaxConnectors
- 1 : templateMaxConnectors
) > 0) {
1265 for (let index
= 1; index
<= configuredMaxConnectors
; index
++) {
1266 const randConnectorId
= stationInfo
?.randomConnectors
1267 ? Utils
.getRandomInteger(Utils
.convertToInt(lastConnector
), 1)
1269 this.connectors
.set(
1271 Utils
.cloneObject
<ConnectorStatus
>(stationInfo
?.Connectors
[randConnectorId
])
1273 this.getConnectorStatus(index
).availability
= AvailabilityType
.OPERATIVE
;
1274 if (Utils
.isUndefined(this.getConnectorStatus(index
)?.chargingProfiles
)) {
1275 this.getConnectorStatus(index
).chargingProfiles
= [];
1282 `${this.logPrefix()} Charging station information from template ${
1284 } with no connectors configuration defined, using already defined connectors`
1287 // Initialize transaction attributes on connectors
1288 for (const connectorId
of this.connectors
.keys()) {
1289 if (connectorId
> 0 && this.getConnectorStatus(connectorId
)?.transactionStarted
=== false) {
1290 this.initializeConnectorStatus(connectorId
);
1295 private getConfigurationFromFile(): ChargingStationConfiguration
| null {
1296 let configuration
: ChargingStationConfiguration
= null;
1297 if (this.configurationFile
&& fs
.existsSync(this.configurationFile
)) {
1299 if (this.sharedLRUCache
.hasChargingStationConfiguration(this.configurationFileHash
)) {
1300 configuration
= this.sharedLRUCache
.getChargingStationConfiguration(
1301 this.configurationFileHash
1304 const measureId
= `${FileType.ChargingStationConfiguration} read`;
1305 const beginId
= PerformanceStatistics
.beginMeasure(measureId
);
1306 configuration
= JSON
.parse(
1307 fs
.readFileSync(this.configurationFile
, 'utf8')
1308 ) as ChargingStationConfiguration
;
1309 PerformanceStatistics
.endMeasure(measureId
, beginId
);
1310 this.configurationFileHash
= configuration
.configurationHash
;
1311 this.sharedLRUCache
.setChargingStationConfiguration(configuration
);
1314 FileUtils
.handleFileException(
1316 FileType
.ChargingStationConfiguration
,
1317 this.configurationFile
,
1318 error
as NodeJS
.ErrnoException
1322 return configuration
;
1325 private saveConfiguration(): void {
1326 if (this.configurationFile
) {
1328 if (!fs
.existsSync(path
.dirname(this.configurationFile
))) {
1329 fs
.mkdirSync(path
.dirname(this.configurationFile
), { recursive
: true });
1331 const configurationData
: ChargingStationConfiguration
=
1332 this.getConfigurationFromFile() ?? {};
1333 this.ocppConfiguration
?.configurationKey
&&
1334 (configurationData
.configurationKey
= this.ocppConfiguration
.configurationKey
);
1335 this.stationInfo
&& (configurationData
.stationInfo
= this.stationInfo
);
1336 delete configurationData
.configurationHash
;
1337 const configurationHash
= crypto
1338 .createHash(Constants
.DEFAULT_HASH_ALGORITHM
)
1339 .update(JSON
.stringify(configurationData
))
1341 if (this.configurationFileHash
!== configurationHash
) {
1342 configurationData
.configurationHash
= configurationHash
;
1343 const measureId
= `${FileType.ChargingStationConfiguration} write`;
1344 const beginId
= PerformanceStatistics
.beginMeasure(measureId
);
1345 const fileDescriptor
= fs
.openSync(this.configurationFile
, 'w');
1346 fs
.writeFileSync(fileDescriptor
, JSON
.stringify(configurationData
, null, 2), 'utf8');
1347 fs
.closeSync(fileDescriptor
);
1348 PerformanceStatistics
.endMeasure(measureId
, beginId
);
1349 this.sharedLRUCache
.deleteChargingStationConfiguration(this.configurationFileHash
);
1350 this.configurationFileHash
= configurationHash
;
1351 this.sharedLRUCache
.setChargingStationConfiguration(configurationData
);
1354 `${this.logPrefix()} Not saving unchanged charging station configuration file ${
1355 this.configurationFile
1360 FileUtils
.handleFileException(
1362 FileType
.ChargingStationConfiguration
,
1363 this.configurationFile
,
1364 error
as NodeJS
.ErrnoException
1369 `${this.logPrefix()} Trying to save charging station configuration to undefined configuration file`
1374 private getOcppConfigurationFromTemplate(): ChargingStationOcppConfiguration
| null {
1375 return this.getTemplateFromFile()?.Configuration
?? null;
1378 private getOcppConfigurationFromFile(): ChargingStationOcppConfiguration
| null {
1379 let configuration
: ChargingStationConfiguration
= null;
1380 if (this.getOcppPersistentConfiguration()) {
1381 const configurationFromFile
= this.getConfigurationFromFile();
1382 configuration
= configurationFromFile
?.configurationKey
&& configurationFromFile
;
1384 configuration
&& delete configuration
.stationInfo
;
1385 return configuration
;
1388 private getOcppConfiguration(): ChargingStationOcppConfiguration
| null {
1389 let ocppConfiguration
: ChargingStationOcppConfiguration
= this.getOcppConfigurationFromFile();
1390 if (!ocppConfiguration
) {
1391 ocppConfiguration
= this.getOcppConfigurationFromTemplate();
1393 return ocppConfiguration
;
1396 private async onOpen(): Promise
<void> {
1397 if (this.isWebSocketConnectionOpened()) {
1399 `${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.toString()} succeeded`
1401 if (!this.isRegistered()) {
1402 // Send BootNotification
1403 let registrationRetryCount
= 0;
1405 this.bootNotificationResponse
= await this.ocppRequestService
.requestHandler
<
1406 BootNotificationRequest
,
1407 BootNotificationResponse
1410 RequestCommand
.BOOT_NOTIFICATION
,
1412 chargePointModel
: this.bootNotificationRequest
.chargePointModel
,
1413 chargePointVendor
: this.bootNotificationRequest
.chargePointVendor
,
1414 chargeBoxSerialNumber
: this.bootNotificationRequest
.chargeBoxSerialNumber
,
1415 firmwareVersion
: this.bootNotificationRequest
.firmwareVersion
,
1416 chargePointSerialNumber
: this.bootNotificationRequest
.chargePointSerialNumber
,
1417 iccid
: this.bootNotificationRequest
.iccid
,
1418 imsi
: this.bootNotificationRequest
.imsi
,
1419 meterSerialNumber
: this.bootNotificationRequest
.meterSerialNumber
,
1420 meterType
: this.bootNotificationRequest
.meterType
,
1422 { skipBufferingOnError
: true }
1424 if (!this.isRegistered()) {
1425 this.getRegistrationMaxRetries() !== -1 && registrationRetryCount
++;
1427 this.bootNotificationResponse
?.interval
1428 ? this.bootNotificationResponse
.interval
* 1000
1429 : Constants
.OCPP_DEFAULT_BOOT_NOTIFICATION_INTERVAL
1433 !this.isRegistered() &&
1434 (registrationRetryCount
<= this.getRegistrationMaxRetries() ||
1435 this.getRegistrationMaxRetries() === -1)
1438 if (this.isRegistered()) {
1439 if (this.isInAcceptedState()) {
1440 await this.startMessageSequence();
1441 this.wsConnectionRestarted
&& this.flushMessageBuffer();
1445 `${this.logPrefix()} Registration failure: max retries reached (${this.getRegistrationMaxRetries()}) or retry disabled (${this.getRegistrationMaxRetries()})`
1448 this.started
=== false && (this.started
= true);
1449 this.autoReconnectRetryCount
= 0;
1450 this.wsConnectionRestarted
= false;
1451 parentPort
.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
1454 `${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.toString()} failed`
1459 private async onClose(code
: number, reason
: string): Promise
<void> {
1462 case WebSocketCloseEventStatusCode
.CLOSE_NORMAL
:
1463 case WebSocketCloseEventStatusCode
.CLOSE_NO_STATUS
:
1465 `${this.logPrefix()} WebSocket normally closed with status '${Utils.getWebSocketCloseEventStatusString(
1467 )}' and reason '${reason}'`
1469 this.autoReconnectRetryCount
= 0;
1470 await this.stopMessageSequence(StopTransactionReason
.OTHER
);
1475 `${this.logPrefix()} WebSocket abnormally closed with status '${Utils.getWebSocketCloseEventStatusString(
1477 )}' and reason '${reason}'`
1479 await this.reconnect(code
);
1482 parentPort
.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
1485 private async onMessage(data
: Data
): Promise
<void> {
1486 let messageType
: number;
1487 let messageId
: string;
1488 let commandName
: IncomingRequestCommand
;
1489 let commandPayload
: JsonType
;
1490 let errorType
: ErrorType
;
1491 let errorMessage
: string;
1492 let errorDetails
: JsonType
;
1493 let responseCallback
: (payload
: JsonType
, requestPayload
: JsonType
) => void;
1494 let errorCallback
: (error
: OCPPError
, requestStatistic
?: boolean) => void;
1495 let requestCommandName
: RequestCommand
| IncomingRequestCommand
;
1496 let requestPayload
: JsonType
;
1497 let cachedRequest
: CachedRequest
;
1500 const request
= JSON
.parse(data
.toString()) as IncomingRequest
| Response
| ErrorResponse
;
1501 if (Array.isArray(request
) === true) {
1502 [messageType
, messageId
] = request
;
1503 // Check the type of message
1504 switch (messageType
) {
1506 case MessageType
.CALL_MESSAGE
:
1507 [, , commandName
, commandPayload
] = request
as IncomingRequest
;
1508 if (this.getEnableStatistics()) {
1509 this.performanceStatistics
.addRequestStatistic(commandName
, messageType
);
1512 `${this.logPrefix()} << Command '${commandName}' received request payload: ${JSON.stringify(
1516 // Process the message
1517 await this.ocppIncomingRequestService
.incomingRequestHandler(
1525 case MessageType
.CALL_RESULT_MESSAGE
:
1526 [, , commandPayload
] = request
as Response
;
1527 if (!this.requests
.has(messageId
)) {
1529 throw new OCPPError(
1530 ErrorType
.INTERNAL_ERROR
,
1531 `Response for unknown message id ${messageId}`,
1537 cachedRequest
= this.requests
.get(messageId
);
1538 if (Array.isArray(cachedRequest
) === true) {
1539 [responseCallback
, , requestCommandName
, requestPayload
] = cachedRequest
;
1541 throw new OCPPError(
1542 ErrorType
.PROTOCOL_ERROR
,
1543 `Cached request for message id ${messageId} response is not an array`,
1545 cachedRequest
as unknown
as JsonType
1549 `${this.logPrefix()} << Command '${
1550 requestCommandName ?? 'unknown'
1551 }' received response payload: ${JSON.stringify(request)}`
1553 responseCallback(commandPayload
, requestPayload
);
1556 case MessageType
.CALL_ERROR_MESSAGE
:
1557 [, , errorType
, errorMessage
, errorDetails
] = request
as ErrorResponse
;
1558 if (!this.requests
.has(messageId
)) {
1560 throw new OCPPError(
1561 ErrorType
.INTERNAL_ERROR
,
1562 `Error response for unknown message id ${messageId}`,
1564 { errorType
, errorMessage
, errorDetails
}
1567 cachedRequest
= this.requests
.get(messageId
);
1568 if (Array.isArray(cachedRequest
) === true) {
1569 [, errorCallback
, requestCommandName
] = cachedRequest
;
1571 throw new OCPPError(
1572 ErrorType
.PROTOCOL_ERROR
,
1573 `Cached request for message id ${messageId} error response is not an array`,
1575 cachedRequest
as unknown
as JsonType
1579 `${this.logPrefix()} << Command '${
1580 requestCommandName ?? 'unknown'
1581 }' received error payload: ${JSON.stringify(request)}`
1583 errorCallback(new OCPPError(errorType
, errorMessage
, requestCommandName
, errorDetails
));
1587 // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1588 errMsg
= `Wrong message type ${messageType}`;
1589 logger
.error(`${this.logPrefix()} ${errMsg}`);
1590 throw new OCPPError(ErrorType
.PROTOCOL_ERROR
, errMsg
);
1592 parentPort
.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
1594 throw new OCPPError(ErrorType
.PROTOCOL_ERROR
, 'Incoming message is not an array', null, {
1601 `${this.logPrefix()} Incoming OCPP command '${
1602 commandName ?? requestCommandName ?? null
1603 }' message '${data.toString()}' matching cached request '${JSON.stringify(
1604 this.requests.get(messageId)
1605 )}' processing error:`,
1608 if (!(error
instanceof OCPPError
)) {
1610 `${this.logPrefix()} Error thrown at incoming OCPP command '${
1611 commandName ?? requestCommandName ?? null
1612 }' message '${data.toString()}' handling is not an OCPPError:`,
1617 messageType
=== MessageType
.CALL_MESSAGE
&&
1618 (await this.ocppRequestService
.sendError(
1622 commandName
?? requestCommandName
?? null
1627 private onPing(): void {
1628 logger
.debug(this.logPrefix() + ' Received a WS ping (rfc6455) from the server');
1631 private onPong(): void {
1632 logger
.debug(this.logPrefix() + ' Received a WS pong (rfc6455) from the server');
1635 private onError(error
: WSError
): void {
1636 this.closeWSConnection();
1637 logger
.error(this.logPrefix() + ' WebSocket error:', error
);
1640 private getEnergyActiveImportRegister(
1641 connectorStatus
: ConnectorStatus
,
1644 if (this.getMeteringPerTransaction()) {
1647 ? Math.round(connectorStatus
?.transactionEnergyActiveImportRegisterValue
)
1648 : connectorStatus
?.transactionEnergyActiveImportRegisterValue
) ?? 0
1653 ? Math.round(connectorStatus
?.energyActiveImportRegisterValue
)
1654 : connectorStatus
?.energyActiveImportRegisterValue
) ?? 0
1658 private getUseConnectorId0(stationInfo
?: ChargingStationInfo
): boolean | undefined {
1659 const localStationInfo
= stationInfo
?? this.stationInfo
;
1660 return !Utils
.isUndefined(localStationInfo
.useConnectorId0
)
1661 ? localStationInfo
.useConnectorId0
1666 private getConnectionTimeout(): number | undefined {
1668 ChargingStationConfigurationUtils
.getConfigurationKey(
1670 StandardParametersKey
.ConnectionTimeOut
1675 ChargingStationConfigurationUtils
.getConfigurationKey(
1677 StandardParametersKey
.ConnectionTimeOut
1679 ) ?? Constants
.DEFAULT_CONNECTION_TIMEOUT
1682 return Constants
.DEFAULT_CONNECTION_TIMEOUT
;
1685 // -1 for unlimited, 0 for disabling
1686 private getAutoReconnectMaxRetries(): number | undefined {
1687 if (!Utils
.isUndefined(this.stationInfo
.autoReconnectMaxRetries
)) {
1688 return this.stationInfo
.autoReconnectMaxRetries
;
1690 if (!Utils
.isUndefined(Configuration
.getAutoReconnectMaxRetries())) {
1691 return Configuration
.getAutoReconnectMaxRetries();
1697 private getRegistrationMaxRetries(): number | undefined {
1698 if (!Utils
.isUndefined(this.stationInfo
.registrationMaxRetries
)) {
1699 return this.stationInfo
.registrationMaxRetries
;
1704 private getPowerDivider(): number {
1705 let powerDivider
= this.getNumberOfConnectors();
1706 if (this.stationInfo
?.powerSharedByConnectors
) {
1707 powerDivider
= this.getNumberOfRunningTransactions();
1709 return powerDivider
;
1712 private getMaximumPower(stationInfo
?: ChargingStationInfo
): number {
1713 const localStationInfo
= stationInfo
?? this.stationInfo
;
1714 return (localStationInfo
['maxPower'] as number) ?? localStationInfo
.maximumPower
;
1717 private getMaximumAmperage(stationInfo
: ChargingStationInfo
): number | undefined {
1718 const maximumPower
= this.getMaximumPower(stationInfo
);
1719 switch (this.getCurrentOutType(stationInfo
)) {
1720 case CurrentType
.AC
:
1721 return ACElectricUtils
.amperagePerPhaseFromPower(
1722 this.getNumberOfPhases(stationInfo
),
1723 maximumPower
/ this.getNumberOfConnectors(),
1724 this.getVoltageOut(stationInfo
)
1726 case CurrentType
.DC
:
1727 return DCElectricUtils
.amperage(maximumPower
, this.getVoltageOut(stationInfo
));
1731 private getAmperageLimitation(): number | undefined {
1733 this.stationInfo
.amperageLimitationOcppKey
&&
1734 ChargingStationConfigurationUtils
.getConfigurationKey(
1736 this.stationInfo
.amperageLimitationOcppKey
1741 ChargingStationConfigurationUtils
.getConfigurationKey(
1743 this.stationInfo
.amperageLimitationOcppKey
1745 ) / ChargingStationUtils
.getAmperageLimitationUnitDivider(this.stationInfo
)
1750 private async startMessageSequence(): Promise
<void> {
1751 if (this.stationInfo
?.autoRegister
) {
1752 await this.ocppRequestService
.requestHandler
<
1753 BootNotificationRequest
,
1754 BootNotificationResponse
1757 RequestCommand
.BOOT_NOTIFICATION
,
1759 chargePointModel
: this.bootNotificationRequest
.chargePointModel
,
1760 chargePointVendor
: this.bootNotificationRequest
.chargePointVendor
,
1761 chargeBoxSerialNumber
: this.bootNotificationRequest
.chargeBoxSerialNumber
,
1762 firmwareVersion
: this.bootNotificationRequest
.firmwareVersion
,
1763 chargePointSerialNumber
: this.bootNotificationRequest
.chargePointSerialNumber
,
1764 iccid
: this.bootNotificationRequest
.iccid
,
1765 imsi
: this.bootNotificationRequest
.imsi
,
1766 meterSerialNumber
: this.bootNotificationRequest
.meterSerialNumber
,
1767 meterType
: this.bootNotificationRequest
.meterType
,
1769 { skipBufferingOnError
: true }
1772 // Start WebSocket ping
1773 this.startWebSocketPing();
1775 this.startHeartbeat();
1776 // Initialize connectors status
1777 for (const connectorId
of this.connectors
.keys()) {
1778 if (connectorId
=== 0) {
1781 this.started
=== true &&
1782 !this.getConnectorStatus(connectorId
)?.status &&
1783 this.getConnectorStatus(connectorId
)?.bootStatus
1785 // Send status in template at startup
1786 await this.ocppRequestService
.requestHandler
<
1787 StatusNotificationRequest
,
1788 StatusNotificationResponse
1789 >(this, RequestCommand
.STATUS_NOTIFICATION
, {
1791 status: this.getConnectorStatus(connectorId
).bootStatus
,
1792 errorCode
: ChargePointErrorCode
.NO_ERROR
,
1794 this.getConnectorStatus(connectorId
).status =
1795 this.getConnectorStatus(connectorId
).bootStatus
;
1797 this.started
=== false &&
1798 this.getConnectorStatus(connectorId
)?.status &&
1799 this.getConnectorStatus(connectorId
)?.bootStatus
1801 // Send status in template after reset
1802 await this.ocppRequestService
.requestHandler
<
1803 StatusNotificationRequest
,
1804 StatusNotificationResponse
1805 >(this, RequestCommand
.STATUS_NOTIFICATION
, {
1807 status: this.getConnectorStatus(connectorId
).bootStatus
,
1808 errorCode
: ChargePointErrorCode
.NO_ERROR
,
1810 this.getConnectorStatus(connectorId
).status =
1811 this.getConnectorStatus(connectorId
).bootStatus
;
1812 } else if (this.started
=== true && this.getConnectorStatus(connectorId
)?.status) {
1813 // Send previous status at template reload
1814 await this.ocppRequestService
.requestHandler
<
1815 StatusNotificationRequest
,
1816 StatusNotificationResponse
1817 >(this, RequestCommand
.STATUS_NOTIFICATION
, {
1819 status: this.getConnectorStatus(connectorId
).status,
1820 errorCode
: ChargePointErrorCode
.NO_ERROR
,
1823 // Send default status
1824 await this.ocppRequestService
.requestHandler
<
1825 StatusNotificationRequest
,
1826 StatusNotificationResponse
1827 >(this, RequestCommand
.STATUS_NOTIFICATION
, {
1829 status: ChargePointStatus
.AVAILABLE
,
1830 errorCode
: ChargePointErrorCode
.NO_ERROR
,
1832 this.getConnectorStatus(connectorId
).status = ChargePointStatus
.AVAILABLE
;
1836 if (this.getAutomaticTransactionGeneratorConfigurationFromTemplate()?.enable
) {
1837 this.startAutomaticTransactionGenerator();
1841 private async stopMessageSequence(
1842 reason
: StopTransactionReason
= StopTransactionReason
.NONE
1844 // Stop WebSocket ping
1845 this.stopWebSocketPing();
1847 this.stopHeartbeat();
1848 // Stop ongoing transactions
1849 if (this.getNumberOfRunningTransactions() > 0) {
1850 if (this.automaticTransactionGenerator
?.started
) {
1851 this.stopAutomaticTransactionGenerator();
1853 await this.stopRunningTransactions(reason
);
1858 private startWebSocketPing(): void {
1859 const webSocketPingInterval
: number = ChargingStationConfigurationUtils
.getConfigurationKey(
1861 StandardParametersKey
.WebSocketPingInterval
1863 ? Utils
.convertToInt(
1864 ChargingStationConfigurationUtils
.getConfigurationKey(
1866 StandardParametersKey
.WebSocketPingInterval
1870 if (webSocketPingInterval
> 0 && !this.webSocketPingSetInterval
) {
1871 this.webSocketPingSetInterval
= setInterval(() => {
1872 if (this.isWebSocketConnectionOpened()) {
1873 this.wsConnection
.ping((): void => {
1874 /* This is intentional */
1877 }, webSocketPingInterval
* 1000);
1880 ' WebSocket ping started every ' +
1881 Utils
.formatDurationSeconds(webSocketPingInterval
)
1883 } else if (this.webSocketPingSetInterval
) {
1886 ' WebSocket ping every ' +
1887 Utils
.formatDurationSeconds(webSocketPingInterval
) +
1892 `${this.logPrefix()} WebSocket ping interval set to ${
1893 webSocketPingInterval
1894 ? Utils.formatDurationSeconds(webSocketPingInterval)
1895 : webSocketPingInterval
1896 }, not starting the WebSocket ping`
1901 private stopWebSocketPing(): void {
1902 if (this.webSocketPingSetInterval
) {
1903 clearInterval(this.webSocketPingSetInterval
);
1907 private getConfiguredSupervisionUrl(): URL
{
1908 const supervisionUrls
= Utils
.cloneObject
<string | string[]>(
1909 this.stationInfo
.supervisionUrls
?? Configuration
.getSupervisionUrls()
1911 if (!Utils
.isEmptyArray(supervisionUrls
)) {
1913 switch (Configuration
.getSupervisionUrlDistribution()) {
1914 case SupervisionUrlDistribution
.ROUND_ROBIN
:
1915 urlIndex
= (this.index
- 1) % supervisionUrls
.length
;
1917 case SupervisionUrlDistribution
.RANDOM
:
1919 urlIndex
= Math.floor(Utils
.secureRandom() * supervisionUrls
.length
);
1921 case SupervisionUrlDistribution
.SEQUENTIAL
:
1922 if (this.index
<= supervisionUrls
.length
) {
1923 urlIndex
= this.index
- 1;
1926 `${this.logPrefix()} No more configured supervision urls available, using the first one`
1932 `${this.logPrefix()} Unknown supervision url distribution '${Configuration.getSupervisionUrlDistribution()}' from values '${SupervisionUrlDistribution.toString()}', defaulting to ${
1933 SupervisionUrlDistribution.ROUND_ROBIN
1936 urlIndex
= (this.index
- 1) % supervisionUrls
.length
;
1939 return new URL(supervisionUrls
[urlIndex
]);
1941 return new URL(supervisionUrls
as string);
1944 private getHeartbeatInterval(): number | undefined {
1945 const HeartbeatInterval
= ChargingStationConfigurationUtils
.getConfigurationKey(
1947 StandardParametersKey
.HeartbeatInterval
1949 if (HeartbeatInterval
) {
1950 return Utils
.convertToInt(HeartbeatInterval
.value
) * 1000;
1952 const HeartBeatInterval
= ChargingStationConfigurationUtils
.getConfigurationKey(
1954 StandardParametersKey
.HeartBeatInterval
1956 if (HeartBeatInterval
) {
1957 return Utils
.convertToInt(HeartBeatInterval
.value
) * 1000;
1959 !this.stationInfo
?.autoRegister
&&
1961 `${this.logPrefix()} Heartbeat interval configuration key not set, using default value: ${
1962 Constants.DEFAULT_HEARTBEAT_INTERVAL
1965 return Constants
.DEFAULT_HEARTBEAT_INTERVAL
;
1968 private stopHeartbeat(): void {
1969 if (this.heartbeatSetInterval
) {
1970 clearInterval(this.heartbeatSetInterval
);
1974 private terminateWSConnection(): void {
1975 if (this.isWebSocketConnectionOpened()) {
1976 this.wsConnection
.terminate();
1977 this.wsConnection
= null;
1981 private stopMeterValues(connectorId
: number) {
1982 if (this.getConnectorStatus(connectorId
)?.transactionSetInterval
) {
1983 clearInterval(this.getConnectorStatus(connectorId
).transactionSetInterval
);
1987 private getReconnectExponentialDelay(): boolean | undefined {
1988 return !Utils
.isUndefined(this.stationInfo
.reconnectExponentialDelay
)
1989 ? this.stationInfo
.reconnectExponentialDelay
1993 private async reconnect(code
: number): Promise
<void> {
1994 // Stop WebSocket ping
1995 this.stopWebSocketPing();
1997 this.stopHeartbeat();
1998 // Stop the ATG if needed
1999 if (this.automaticTransactionGenerator
?.configuration
?.stopOnConnectionFailure
) {
2000 this.stopAutomaticTransactionGenerator();
2003 this.autoReconnectRetryCount
< this.getAutoReconnectMaxRetries() ||
2004 this.getAutoReconnectMaxRetries() === -1
2006 this.autoReconnectRetryCount
++;
2007 const reconnectDelay
= this.getReconnectExponentialDelay()
2008 ? Utils
.exponentialDelay(this.autoReconnectRetryCount
)
2009 : this.getConnectionTimeout() * 1000;
2010 const reconnectDelayWithdraw
= 1000;
2011 const reconnectTimeout
=
2012 reconnectDelay
&& reconnectDelay
- reconnectDelayWithdraw
> 0
2013 ? reconnectDelay
- reconnectDelayWithdraw
2016 `${this.logPrefix()} WebSocket: connection retry in ${Utils.roundTo(
2019 )}ms, timeout ${reconnectTimeout}ms`
2021 await Utils
.sleep(reconnectDelay
);
2024 ' WebSocket: reconnecting try #' +
2025 this.autoReconnectRetryCount
.toString()
2027 this.openWSConnection(
2028 { ...(this.stationInfo
?.wsOptions
?? {}), handshakeTimeout
: reconnectTimeout
},
2029 { closeOpened
: true }
2031 this.wsConnectionRestarted
= true;
2032 } else if (this.getAutoReconnectMaxRetries() !== -1) {
2034 `${this.logPrefix()} WebSocket reconnect failure: maximum retries reached (${
2035 this.autoReconnectRetryCount
2036 }) or retry disabled (${this.getAutoReconnectMaxRetries()})`
2041 private getAutomaticTransactionGeneratorConfigurationFromTemplate(): AutomaticTransactionGeneratorConfiguration
| null {
2042 return this.getTemplateFromFile()?.AutomaticTransactionGenerator
?? null;
2045 private initializeConnectorStatus(connectorId
: number): void {
2046 this.getConnectorStatus(connectorId
).idTagLocalAuthorized
= false;
2047 this.getConnectorStatus(connectorId
).idTagAuthorized
= false;
2048 this.getConnectorStatus(connectorId
).transactionRemoteStarted
= false;
2049 this.getConnectorStatus(connectorId
).transactionStarted
= false;
2050 this.getConnectorStatus(connectorId
).energyActiveImportRegisterValue
= 0;
2051 this.getConnectorStatus(connectorId
).transactionEnergyActiveImportRegisterValue
= 0;