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';
19 OCPP16IncomingRequestService
,
21 OCPP16ResponseService
,
23 OCPP20IncomingRequestService
,
25 OCPP20ResponseService
,
26 type OCPPIncomingRequestService
,
27 type OCPPRequestService
,
30 import { SharedLRUCache
} from
'./SharedLRUCache';
31 import { BaseError
, OCPPError
} from
'../exception';
32 import { PerformanceStatistics
} from
'../performance';
34 type AutomaticTransactionGeneratorConfiguration
,
36 type BootNotificationRequest
,
37 type BootNotificationResponse
,
39 type ChargingStationConfiguration
,
40 type ChargingStationInfo
,
41 type ChargingStationOcppConfiguration
,
42 type ChargingStationTemplate
,
43 ConnectorPhaseRotation
,
52 type FirmwareStatusNotificationRequest
,
53 type FirmwareStatusNotificationResponse
,
55 type HeartbeatRequest
,
56 type HeartbeatResponse
,
58 type IncomingRequestCommand
,
63 type MeterValuesRequest
,
64 type MeterValuesResponse
,
68 RegistrationStatusEnumType
,
71 type ResponseCallback
,
72 StandardParametersKey
,
73 type StatusNotificationRequest
,
74 type StatusNotificationResponse
,
75 StopTransactionReason
,
76 type StopTransactionRequest
,
77 type StopTransactionResponse
,
78 SupervisionUrlDistribution
,
79 SupportedFeatureProfiles
,
80 VendorDefaultParametersKey
,
82 WebSocketCloseEventStatusCode
,
85 import { Configuration
} from
'../utils/Configuration';
86 import { Constants
} from
'../utils/Constants';
87 import { ACElectricUtils
, DCElectricUtils
} from
'../utils/ElectricUtils';
88 import { FileUtils
} from
'../utils/FileUtils';
89 import { logger
} from
'../utils/Logger';
90 import { Utils
} from
'../utils/Utils';
92 export class ChargingStation
{
93 public readonly index
: number;
94 public readonly templateFile
: string;
95 public stationInfo
!: ChargingStationInfo
;
96 public started
: boolean;
97 public starting
: boolean;
98 public authorizedTagsCache
: AuthorizedTagsCache
;
99 public automaticTransactionGenerator
!: AutomaticTransactionGenerator
| undefined;
100 public ocppConfiguration
!: ChargingStationOcppConfiguration
| undefined;
101 public wsConnection
!: WebSocket
| null;
102 public readonly connectors
: Map
<number, ConnectorStatus
>;
103 public readonly requests
: Map
<string, CachedRequest
>;
104 public performanceStatistics
!: PerformanceStatistics
| undefined;
105 public heartbeatSetInterval
!: NodeJS
.Timeout
;
106 public ocppRequestService
!: OCPPRequestService
;
107 public bootNotificationRequest
!: BootNotificationRequest
;
108 public bootNotificationResponse
!: BootNotificationResponse
| undefined;
109 public powerDivider
!: number;
110 private stopping
: boolean;
111 private configurationFile
!: string;
112 private configurationFileHash
!: string;
113 private connectorsConfigurationHash
!: string;
114 private ocppIncomingRequestService
!: OCPPIncomingRequestService
;
115 private readonly messageBuffer
: Set
<string>;
116 private configuredSupervisionUrl
!: URL
;
117 private configuredSupervisionUrlIndex
!: number;
118 private wsConnectionRestarted
: boolean;
119 private autoReconnectRetryCount
: number;
120 private templateFileWatcher
!: fs
.FSWatcher
| undefined;
121 private readonly sharedLRUCache
: SharedLRUCache
;
122 private webSocketPingSetInterval
!: NodeJS
.Timeout
;
123 private readonly chargingStationWorkerBroadcastChannel
: ChargingStationWorkerBroadcastChannel
;
125 constructor(index
: number, templateFile
: string) {
126 this.started
= false;
127 this.starting
= false;
128 this.stopping
= false;
129 this.wsConnectionRestarted
= false;
130 this.autoReconnectRetryCount
= 0;
132 this.templateFile
= templateFile
;
133 this.connectors
= new Map
<number, ConnectorStatus
>();
134 this.requests
= new Map
<string, CachedRequest
>();
135 this.messageBuffer
= new Set
<string>();
136 this.sharedLRUCache
= SharedLRUCache
.getInstance();
137 this.authorizedTagsCache
= AuthorizedTagsCache
.getInstance();
138 this.chargingStationWorkerBroadcastChannel
= new ChargingStationWorkerBroadcastChannel(this);
143 private get
wsConnectionUrl(): URL
{
146 this.getSupervisionUrlOcppConfiguration()
147 ? ChargingStationConfigurationUtils.getConfigurationKey(
149 this.getSupervisionUrlOcppKey()
151 : this.configuredSupervisionUrl.href
152 }/${this.stationInfo.chargingStationId}`
156 public logPrefix
= (): string => {
157 return Utils
.logPrefix(
159 (Utils.isNotEmptyString(this?.stationInfo?.chargingStationId) &&
160 this?.stationInfo?.chargingStationId) ??
161 ChargingStationUtils.getChargingStationId(this.index, this.getTemplateFromFile()) ??
167 public hasAuthorizedTags(): boolean {
168 return Utils
.isNotEmptyArray(
169 this.authorizedTagsCache
.getAuthorizedTags(
170 ChargingStationUtils
.getAuthorizationFile(this.stationInfo
)
175 public getEnableStatistics(): boolean {
176 return this.stationInfo
.enableStatistics
?? false;
179 public getMustAuthorizeAtRemoteStart(): boolean {
180 return this.stationInfo
.mustAuthorizeAtRemoteStart
?? true;
183 public getPayloadSchemaValidation(): boolean {
184 return this.stationInfo
.payloadSchemaValidation
?? true;
187 public getNumberOfPhases(stationInfo
?: ChargingStationInfo
): number | undefined {
188 const localStationInfo
: ChargingStationInfo
= stationInfo
?? this.stationInfo
;
189 switch (this.getCurrentOutType(stationInfo
)) {
191 return !Utils
.isUndefined(localStationInfo
.numberOfPhases
)
192 ? localStationInfo
.numberOfPhases
199 public isWebSocketConnectionOpened(): boolean {
200 return this?.wsConnection
?.readyState
=== WebSocket
.OPEN
;
203 public getRegistrationStatus(): RegistrationStatusEnumType
| undefined {
204 return this?.bootNotificationResponse
?.status;
207 public isInUnknownState(): boolean {
208 return Utils
.isNullOrUndefined(this?.bootNotificationResponse
?.status);
211 public isInPendingState(): boolean {
212 return this?.bootNotificationResponse
?.status === RegistrationStatusEnumType
.PENDING
;
215 public isInAcceptedState(): boolean {
216 return this?.bootNotificationResponse
?.status === RegistrationStatusEnumType
.ACCEPTED
;
219 public isInRejectedState(): boolean {
220 return this?.bootNotificationResponse
?.status === RegistrationStatusEnumType
.REJECTED
;
223 public isRegistered(): boolean {
225 this.isInUnknownState() === false &&
226 (this.isInAcceptedState() === true || this.isInPendingState() === true)
230 public isChargingStationAvailable(): boolean {
231 return this.getConnectorStatus(0)?.availability
=== AvailabilityType
.OPERATIVE
;
234 public isConnectorAvailable(id
: number): boolean {
235 return id
> 0 && this.getConnectorStatus(id
)?.availability
=== AvailabilityType
.OPERATIVE
;
238 public getNumberOfConnectors(): number {
239 return this.connectors
.get(0) ? this.connectors
.size
- 1 : this.connectors
.size
;
242 public getConnectorStatus(id
: number): ConnectorStatus
| undefined {
243 return this.connectors
.get(id
);
246 public getCurrentOutType(stationInfo
?: ChargingStationInfo
): CurrentType
{
247 return (stationInfo
?? this.stationInfo
)?.currentOutType
?? CurrentType
.AC
;
250 public getOcppStrictCompliance(): boolean {
251 return this.stationInfo
?.ocppStrictCompliance
?? false;
254 public getVoltageOut(stationInfo
?: ChargingStationInfo
): number | undefined {
255 const defaultVoltageOut
= ChargingStationUtils
.getDefaultVoltageOut(
256 this.getCurrentOutType(stationInfo
),
260 const localStationInfo
: ChargingStationInfo
= stationInfo
?? this.stationInfo
;
261 return !Utils
.isUndefined(localStationInfo
.voltageOut
)
262 ? localStationInfo
.voltageOut
266 public getMaximumPower(stationInfo
?: ChargingStationInfo
): number {
267 const localStationInfo
= stationInfo
?? this.stationInfo
;
268 return (localStationInfo
['maxPower'] as number) ?? localStationInfo
.maximumPower
;
271 public getConnectorMaximumAvailablePower(connectorId
: number): number {
272 let connectorAmperageLimitationPowerLimit
: number;
274 !Utils
.isNullOrUndefined(this.getAmperageLimitation()) &&
275 this.getAmperageLimitation() < this.stationInfo
?.maximumAmperage
277 connectorAmperageLimitationPowerLimit
=
278 (this.getCurrentOutType() === CurrentType
.AC
279 ? ACElectricUtils
.powerTotal(
280 this.getNumberOfPhases(),
281 this.getVoltageOut(),
282 this.getAmperageLimitation() * this.getNumberOfConnectors()
284 : DCElectricUtils
.power(this.getVoltageOut(), this.getAmperageLimitation())) /
287 const connectorMaximumPower
= this.getMaximumPower() / this.powerDivider
;
288 const connectorChargingProfilesPowerLimit
=
289 ChargingStationUtils
.getChargingStationConnectorChargingProfilesPowerLimit(this, connectorId
);
291 isNaN(connectorMaximumPower
) ? Infinity : connectorMaximumPower
,
292 isNaN(connectorAmperageLimitationPowerLimit
)
294 : connectorAmperageLimitationPowerLimit
,
295 isNaN(connectorChargingProfilesPowerLimit
) ? Infinity : connectorChargingProfilesPowerLimit
299 public getTransactionIdTag(transactionId
: number): string | undefined {
300 for (const connectorId
of this.connectors
.keys()) {
303 this.getConnectorStatus(connectorId
)?.transactionId
=== transactionId
305 return this.getConnectorStatus(connectorId
)?.transactionIdTag
;
310 public getOutOfOrderEndMeterValues(): boolean {
311 return this.stationInfo
?.outOfOrderEndMeterValues
?? false;
314 public getBeginEndMeterValues(): boolean {
315 return this.stationInfo
?.beginEndMeterValues
?? false;
318 public getMeteringPerTransaction(): boolean {
319 return this.stationInfo
?.meteringPerTransaction
?? true;
322 public getTransactionDataMeterValues(): boolean {
323 return this.stationInfo
?.transactionDataMeterValues
?? false;
326 public getMainVoltageMeterValues(): boolean {
327 return this.stationInfo
?.mainVoltageMeterValues
?? true;
330 public getPhaseLineToLineVoltageMeterValues(): boolean {
331 return this.stationInfo
?.phaseLineToLineVoltageMeterValues
?? false;
334 public getCustomValueLimitationMeterValues(): boolean {
335 return this.stationInfo
?.customValueLimitationMeterValues
?? true;
338 public getConnectorIdByTransactionId(transactionId
: number): number | undefined {
339 for (const connectorId
of this.connectors
.keys()) {
342 this.getConnectorStatus(connectorId
)?.transactionId
=== transactionId
349 public getEnergyActiveImportRegisterByTransactionId(
350 transactionId
: number,
353 return this.getEnergyActiveImportRegister(
354 this.getConnectorStatus(this.getConnectorIdByTransactionId(transactionId
)),
359 public getEnergyActiveImportRegisterByConnectorId(connectorId
: number, rounded
= false): number {
360 return this.getEnergyActiveImportRegister(this.getConnectorStatus(connectorId
), rounded
);
363 public getAuthorizeRemoteTxRequests(): boolean {
364 const authorizeRemoteTxRequests
= ChargingStationConfigurationUtils
.getConfigurationKey(
366 StandardParametersKey
.AuthorizeRemoteTxRequests
368 return authorizeRemoteTxRequests
369 ? Utils
.convertToBoolean(authorizeRemoteTxRequests
.value
)
373 public getLocalAuthListEnabled(): boolean {
374 const localAuthListEnabled
= ChargingStationConfigurationUtils
.getConfigurationKey(
376 StandardParametersKey
.LocalAuthListEnabled
378 return localAuthListEnabled
? Utils
.convertToBoolean(localAuthListEnabled
.value
) : false;
381 public startHeartbeat(): void {
383 this.getHeartbeatInterval() &&
384 this.getHeartbeatInterval() > 0 &&
385 !this.heartbeatSetInterval
387 this.heartbeatSetInterval
= setInterval(() => {
388 this.ocppRequestService
389 .requestHandler
<HeartbeatRequest
, HeartbeatResponse
>(this, RequestCommand
.HEARTBEAT
)
392 `${this.logPrefix()} Error while sending '${RequestCommand.HEARTBEAT}':`,
396 }, this.getHeartbeatInterval());
398 `${this.logPrefix()} Heartbeat started every ${Utils.formatDurationMilliSeconds(
399 this.getHeartbeatInterval()
402 } else if (this.heartbeatSetInterval
) {
404 `${this.logPrefix()} Heartbeat already started every ${Utils.formatDurationMilliSeconds(
405 this.getHeartbeatInterval()
410 `${this.logPrefix()} Heartbeat interval set to ${
411 this.getHeartbeatInterval()
412 ? Utils.formatDurationMilliSeconds(this.getHeartbeatInterval())
413 : this.getHeartbeatInterval()
414 }, not starting the heartbeat`
419 public restartHeartbeat(): void {
421 this.stopHeartbeat();
423 this.startHeartbeat();
426 public restartWebSocketPing(): void {
427 // Stop WebSocket ping
428 this.stopWebSocketPing();
429 // Start WebSocket ping
430 this.startWebSocketPing();
433 public startMeterValues(connectorId
: number, interval
: number): void {
434 if (connectorId
=== 0) {
436 `${this.logPrefix()} Trying to start MeterValues on connector Id ${connectorId.toString()}`
440 if (!this.getConnectorStatus(connectorId
)) {
442 `${this.logPrefix()} Trying to start MeterValues on non existing connector Id ${connectorId.toString()}`
446 if (this.getConnectorStatus(connectorId
)?.transactionStarted
=== false) {
448 `${this.logPrefix()} Trying to start MeterValues on connector Id ${connectorId} with no transaction started`
452 this.getConnectorStatus(connectorId
)?.transactionStarted
=== true &&
453 Utils
.isNullOrUndefined(this.getConnectorStatus(connectorId
)?.transactionId
)
456 `${this.logPrefix()} Trying to start MeterValues on connector Id ${connectorId} with no transaction id`
461 this.getConnectorStatus(connectorId
).transactionSetInterval
= setInterval(() => {
462 // FIXME: Implement OCPP version agnostic helpers
463 const meterValue
: MeterValue
= OCPP16ServiceUtils
.buildMeterValue(
466 this.getConnectorStatus(connectorId
).transactionId
,
469 this.ocppRequestService
470 .requestHandler
<MeterValuesRequest
, MeterValuesResponse
>(
472 RequestCommand
.METER_VALUES
,
475 transactionId
: this.getConnectorStatus(connectorId
)?.transactionId
,
476 meterValue
: [meterValue
],
481 `${this.logPrefix()} Error while sending '${RequestCommand.METER_VALUES}':`,
488 `${this.logPrefix()} Charging station ${
489 StandardParametersKey.MeterValueSampleInterval
490 } configuration set to ${
491 interval ? Utils.formatDurationMilliSeconds(interval) : interval
492 }, not sending MeterValues`
497 public start(): void {
498 if (this.started
=== false) {
499 if (this.starting
=== false) {
500 this.starting
= true;
501 if (this.getEnableStatistics() === true) {
502 this.performanceStatistics
?.start();
504 this.openWSConnection();
505 // Monitor charging station template file
506 this.templateFileWatcher
= FileUtils
.watchJsonFile(
508 FileType
.ChargingStationTemplate
,
511 (event
, filename
): void => {
512 if (Utils
.isNotEmptyString(filename
) && event
=== 'change') {
515 `${this.logPrefix()} ${FileType.ChargingStationTemplate} ${
517 } file have changed, reload`
519 this.sharedLRUCache
.deleteChargingStationTemplate(this.stationInfo
?.templateHash
);
523 this.stopAutomaticTransactionGenerator();
525 this.getAutomaticTransactionGeneratorConfigurationFromTemplate()?.enable
=== true
527 this.startAutomaticTransactionGenerator();
529 if (this.getEnableStatistics() === true) {
530 this.performanceStatistics
?.restart();
532 this.performanceStatistics
?.stop();
534 // FIXME?: restart heartbeat and WebSocket ping when their interval values have changed
537 `${this.logPrefix()} ${FileType.ChargingStationTemplate} file monitoring error:`,
545 parentPort
?.postMessage(MessageChannelUtils
.buildStartedMessage(this));
546 this.starting
= false;
548 logger
.warn(`${this.logPrefix()} Charging station is already starting...`);
551 logger
.warn(`${this.logPrefix()} Charging station is already started...`);
555 public async stop(reason
?: StopTransactionReason
): Promise
<void> {
556 if (this.started
=== true) {
557 if (this.stopping
=== false) {
558 this.stopping
= true;
559 await this.stopMessageSequence(reason
);
560 this.closeWSConnection();
561 if (this.getEnableStatistics() === true) {
562 this.performanceStatistics
?.stop();
564 this.sharedLRUCache
.deleteChargingStationConfiguration(this.configurationFileHash
);
565 this.templateFileWatcher
?.close();
566 this.sharedLRUCache
.deleteChargingStationTemplate(this.stationInfo
?.templateHash
);
567 this.bootNotificationResponse
= undefined;
568 this.started
= false;
569 parentPort
?.postMessage(MessageChannelUtils
.buildStoppedMessage(this));
570 this.stopping
= false;
572 logger
.warn(`${this.logPrefix()} Charging station is already stopping...`);
575 logger
.warn(`${this.logPrefix()} Charging station is already stopped...`);
579 public async reset(reason
?: StopTransactionReason
): Promise
<void> {
580 await this.stop(reason
);
581 await Utils
.sleep(this.stationInfo
.resetTime
);
586 public saveOcppConfiguration(): void {
587 if (this.getOcppPersistentConfiguration()) {
588 this.saveConfiguration();
592 public resetConnectorStatus(connectorId
: number): void {
593 this.getConnectorStatus(connectorId
).idTagLocalAuthorized
= false;
594 this.getConnectorStatus(connectorId
).idTagAuthorized
= false;
595 this.getConnectorStatus(connectorId
).transactionRemoteStarted
= false;
596 this.getConnectorStatus(connectorId
).transactionStarted
= false;
597 delete this.getConnectorStatus(connectorId
)?.localAuthorizeIdTag
;
598 delete this.getConnectorStatus(connectorId
)?.authorizeIdTag
;
599 delete this.getConnectorStatus(connectorId
)?.transactionId
;
600 delete this.getConnectorStatus(connectorId
)?.transactionIdTag
;
601 this.getConnectorStatus(connectorId
).transactionEnergyActiveImportRegisterValue
= 0;
602 delete this.getConnectorStatus(connectorId
)?.transactionBeginMeterValue
;
603 this.stopMeterValues(connectorId
);
604 parentPort
?.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
607 public hasFeatureProfile(featureProfile
: SupportedFeatureProfiles
): boolean | undefined {
608 return ChargingStationConfigurationUtils
.getConfigurationKey(
610 StandardParametersKey
.SupportedFeatureProfiles
611 )?.value
?.includes(featureProfile
);
614 public bufferMessage(message
: string): void {
615 this.messageBuffer
.add(message
);
618 public openWSConnection(
619 options
: WsOptions
= this.stationInfo
?.wsOptions
?? {},
620 params
: { closeOpened
?: boolean; terminateOpened
?: boolean } = {
622 terminateOpened
: false,
625 options
.handshakeTimeout
= options
?.handshakeTimeout
?? this.getConnectionTimeout() * 1000;
626 params
.closeOpened
= params
?.closeOpened
?? false;
627 params
.terminateOpened
= params
?.terminateOpened
?? false;
628 if (this.started
=== false && this.starting
=== false) {
630 `${this.logPrefix()} Cannot open OCPP connection to URL ${this.wsConnectionUrl.toString()} on stopped charging station`
635 !Utils
.isNullOrUndefined(this.stationInfo
.supervisionUser
) &&
636 !Utils
.isNullOrUndefined(this.stationInfo
.supervisionPassword
)
638 options
.auth
= `${this.stationInfo.supervisionUser}:${this.stationInfo.supervisionPassword}`;
640 if (params
?.closeOpened
) {
641 this.closeWSConnection();
643 if (params
?.terminateOpened
) {
644 this.terminateWSConnection();
646 const ocppVersion
= this.stationInfo
.ocppVersion
?? OCPPVersion
.VERSION_16
;
647 let protocol
: string;
648 switch (ocppVersion
) {
649 case OCPPVersion
.VERSION_16
:
650 case OCPPVersion
.VERSION_20
:
651 case OCPPVersion
.VERSION_201
:
652 protocol
= `ocpp${ocppVersion}`;
655 this.handleUnsupportedVersion(ocppVersion
);
659 if (this.isWebSocketConnectionOpened() === true) {
661 `${this.logPrefix()} OCPP connection to URL ${this.wsConnectionUrl.toString()} is already opened`
667 `${this.logPrefix()} Open OCPP connection to URL ${this.wsConnectionUrl.toString()}`
670 this.wsConnection
= new WebSocket(this.wsConnectionUrl
, protocol
, options
);
672 // Handle WebSocket message
673 this.wsConnection
.on(
675 this.onMessage
.bind(this) as (this: WebSocket
, data
: RawData
, isBinary
: boolean) => void
677 // Handle WebSocket error
678 this.wsConnection
.on(
680 this.onError
.bind(this) as (this: WebSocket
, error
: Error) => void
682 // Handle WebSocket close
683 this.wsConnection
.on(
685 this.onClose
.bind(this) as (this: WebSocket
, code
: number, reason
: Buffer
) => void
687 // Handle WebSocket open
688 this.wsConnection
.on('open', this.onOpen
.bind(this) as (this: WebSocket
) => void);
689 // Handle WebSocket ping
690 this.wsConnection
.on('ping', this.onPing
.bind(this) as (this: WebSocket
, data
: Buffer
) => void);
691 // Handle WebSocket pong
692 this.wsConnection
.on('pong', this.onPong
.bind(this) as (this: WebSocket
, data
: Buffer
) => void);
695 public closeWSConnection(): void {
696 if (this.isWebSocketConnectionOpened() === true) {
697 this.wsConnection
?.close();
698 this.wsConnection
= null;
702 public startAutomaticTransactionGenerator(
703 connectorIds
?: number[],
704 automaticTransactionGeneratorConfiguration
?: AutomaticTransactionGeneratorConfiguration
706 this.automaticTransactionGenerator
= AutomaticTransactionGenerator
.getInstance(
707 automaticTransactionGeneratorConfiguration
??
708 this.getAutomaticTransactionGeneratorConfigurationFromTemplate(),
711 if (Utils
.isNotEmptyArray(connectorIds
)) {
712 for (const connectorId
of connectorIds
) {
713 this.automaticTransactionGenerator
?.startConnector(connectorId
);
716 this.automaticTransactionGenerator
?.start();
718 parentPort
?.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
721 public stopAutomaticTransactionGenerator(connectorIds
?: number[]): void {
722 if (Utils
.isNotEmptyArray(connectorIds
)) {
723 for (const connectorId
of connectorIds
) {
724 this.automaticTransactionGenerator
?.stopConnector(connectorId
);
727 this.automaticTransactionGenerator
?.stop();
729 parentPort
?.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
732 public async stopTransactionOnConnector(
734 reason
= StopTransactionReason
.NONE
735 ): Promise
<StopTransactionResponse
> {
736 const transactionId
= this.getConnectorStatus(connectorId
)?.transactionId
;
738 this.getBeginEndMeterValues() === true &&
739 this.getOcppStrictCompliance() === true &&
740 this.getOutOfOrderEndMeterValues() === false
742 // FIXME: Implement OCPP version agnostic helpers
743 const transactionEndMeterValue
= OCPP16ServiceUtils
.buildTransactionEndMeterValue(
746 this.getEnergyActiveImportRegisterByTransactionId(transactionId
)
748 await this.ocppRequestService
.requestHandler
<MeterValuesRequest
, MeterValuesResponse
>(
750 RequestCommand
.METER_VALUES
,
754 meterValue
: [transactionEndMeterValue
],
758 return this.ocppRequestService
.requestHandler
<StopTransactionRequest
, StopTransactionResponse
>(
760 RequestCommand
.STOP_TRANSACTION
,
763 meterStop
: this.getEnergyActiveImportRegisterByTransactionId(transactionId
, true),
769 private flushMessageBuffer(): void {
770 if (this.messageBuffer
.size
> 0) {
771 this.messageBuffer
.forEach((message
) => {
773 let commandName
: RequestCommand
;
774 const [messageType
] = JSON
.parse(message
) as OutgoingRequest
| Response
| ErrorResponse
;
775 const isRequest
= messageType
=== MessageType
.CALL_MESSAGE
;
777 [, , commandName
] = JSON
.parse(message
) as OutgoingRequest
;
778 beginId
= PerformanceStatistics
.beginMeasure(commandName
);
780 this.wsConnection
?.send(message
);
781 isRequest
&& PerformanceStatistics
.endMeasure(commandName
, beginId
);
783 `${this.logPrefix()} >> Buffered ${OCPPServiceUtils.getMessageTypeString(
785 )} payload sent: ${message}`
787 this.messageBuffer
.delete(message
);
792 private getSupervisionUrlOcppConfiguration(): boolean {
793 return this.stationInfo
.supervisionUrlOcppConfiguration
?? false;
796 private getSupervisionUrlOcppKey(): string {
797 return this.stationInfo
.supervisionUrlOcppKey
?? VendorDefaultParametersKey
.ConnectionUrl
;
800 private getTemplateFromFile(): ChargingStationTemplate
| undefined {
801 let template
: ChargingStationTemplate
;
803 if (this.sharedLRUCache
.hasChargingStationTemplate(this.stationInfo
?.templateHash
)) {
804 template
= this.sharedLRUCache
.getChargingStationTemplate(this.stationInfo
.templateHash
);
806 const measureId
= `${FileType.ChargingStationTemplate} read`;
807 const beginId
= PerformanceStatistics
.beginMeasure(measureId
);
808 template
= JSON
.parse(
809 fs
.readFileSync(this.templateFile
, 'utf8')
810 ) as ChargingStationTemplate
;
811 PerformanceStatistics
.endMeasure(measureId
, beginId
);
812 template
.templateHash
= crypto
813 .createHash(Constants
.DEFAULT_HASH_ALGORITHM
)
814 .update(JSON
.stringify(template
))
816 this.sharedLRUCache
.setChargingStationTemplate(template
);
819 FileUtils
.handleFileException(
821 FileType
.ChargingStationTemplate
,
822 error
as NodeJS
.ErrnoException
,
829 private getStationInfoFromTemplate(): ChargingStationInfo
{
830 const stationTemplate
: ChargingStationTemplate
| undefined = this.getTemplateFromFile();
831 if (Utils
.isNullOrUndefined(stationTemplate
)) {
832 const errorMsg
= `Failed to read charging station template file ${this.templateFile}`;
833 logger
.error(`${this.logPrefix()} ${errorMsg}`);
834 throw new BaseError(errorMsg
);
836 if (Utils
.isEmptyObject(stationTemplate
)) {
837 const errorMsg
= `Empty charging station information from template file ${this.templateFile}`;
838 logger
.error(`${this.logPrefix()} ${errorMsg}`);
839 throw new BaseError(errorMsg
);
841 // Deprecation template keys section
842 ChargingStationUtils
.warnDeprecatedTemplateKey(
847 "Use 'supervisionUrls' instead"
849 ChargingStationUtils
.convertDeprecatedTemplateKey(
854 const stationInfo
: ChargingStationInfo
=
855 ChargingStationUtils
.stationTemplateToStationInfo(stationTemplate
);
856 stationInfo
.hashId
= ChargingStationUtils
.getHashId(this.index
, stationTemplate
);
857 stationInfo
.chargingStationId
= ChargingStationUtils
.getChargingStationId(
861 stationInfo
.ocppVersion
= stationTemplate
?.ocppVersion
?? OCPPVersion
.VERSION_16
;
862 ChargingStationUtils
.createSerialNumber(stationTemplate
, stationInfo
);
863 if (Utils
.isNotEmptyArray(stationTemplate
?.power
)) {
864 stationTemplate
.power
= stationTemplate
.power
as number[];
865 const powerArrayRandomIndex
= Math.floor(Utils
.secureRandom() * stationTemplate
.power
.length
);
866 stationInfo
.maximumPower
=
867 stationTemplate
?.powerUnit
=== PowerUnits
.KILO_WATT
868 ? stationTemplate
.power
[powerArrayRandomIndex
] * 1000
869 : stationTemplate
.power
[powerArrayRandomIndex
];
871 stationTemplate
.power
= stationTemplate
?.power
as number;
872 stationInfo
.maximumPower
=
873 stationTemplate
?.powerUnit
=== PowerUnits
.KILO_WATT
874 ? stationTemplate
.power
* 1000
875 : stationTemplate
.power
;
877 stationInfo
.firmwareVersionPattern
=
878 stationTemplate
?.firmwareVersionPattern
?? Constants
.SEMVER_PATTERN
;
880 Utils
.isNotEmptyString(stationInfo
.firmwareVersion
) &&
881 new RegExp(stationInfo
.firmwareVersionPattern
).test(stationInfo
.firmwareVersion
) === false
884 `${this.logPrefix()} Firmware version '${stationInfo.firmwareVersion}' in template file ${
886 } does not match firmware version pattern '${stationInfo.firmwareVersionPattern}'`
889 stationInfo
.firmwareUpgrade
= merge
<FirmwareUpgrade
>(
896 stationTemplate
?.firmwareUpgrade
?? {}
898 stationInfo
.resetTime
= !Utils
.isNullOrUndefined(stationTemplate
?.resetTime
)
899 ? stationTemplate
.resetTime
* 1000
900 : Constants
.CHARGING_STATION_DEFAULT_RESET_TIME
;
901 const configuredMaxConnectors
=
902 ChargingStationUtils
.getConfiguredNumberOfConnectors(stationTemplate
);
903 ChargingStationUtils
.checkConfiguredMaxConnectors(
904 configuredMaxConnectors
,
908 const templateMaxConnectors
=
909 ChargingStationUtils
.getTemplateMaxNumberOfConnectors(stationTemplate
);
910 ChargingStationUtils
.checkTemplateMaxConnectors(
911 templateMaxConnectors
,
916 configuredMaxConnectors
>
917 (stationTemplate
?.Connectors
[0] ? templateMaxConnectors
- 1 : templateMaxConnectors
) &&
918 !stationTemplate
?.randomConnectors
921 `${this.logPrefix()} Number of connectors exceeds the number of connector configurations in template ${
923 }, forcing random connector configurations affectation`
925 stationInfo
.randomConnectors
= true;
927 // Build connectors if needed (FIXME: should be factored out)
928 this.initializeConnectors(stationInfo
, configuredMaxConnectors
, templateMaxConnectors
);
929 stationInfo
.maximumAmperage
= this.getMaximumAmperage(stationInfo
);
930 ChargingStationUtils
.createStationInfoHash(stationInfo
);
934 private getStationInfoFromFile(): ChargingStationInfo
| undefined {
935 let stationInfo
: ChargingStationInfo
| undefined;
936 this.getStationInfoPersistentConfiguration() &&
937 (stationInfo
= this.getConfigurationFromFile()?.stationInfo
);
938 stationInfo
&& ChargingStationUtils
.createStationInfoHash(stationInfo
);
942 private getStationInfo(): ChargingStationInfo
{
943 const stationInfoFromTemplate
: ChargingStationInfo
= this.getStationInfoFromTemplate();
944 const stationInfoFromFile
: ChargingStationInfo
| undefined = this.getStationInfoFromFile();
945 // Priority: charging station info from template > charging station info from configuration file > charging station info attribute
946 if (stationInfoFromFile
?.templateHash
=== stationInfoFromTemplate
.templateHash
) {
947 if (this.stationInfo
?.infoHash
=== stationInfoFromFile
?.infoHash
) {
948 return this.stationInfo
;
950 return stationInfoFromFile
;
952 stationInfoFromFile
&&
953 ChargingStationUtils
.propagateSerialNumber(
954 this.getTemplateFromFile(),
956 stationInfoFromTemplate
958 return stationInfoFromTemplate
;
961 private saveStationInfo(): void {
962 if (this.getStationInfoPersistentConfiguration()) {
963 this.saveConfiguration();
967 private getOcppPersistentConfiguration(): boolean {
968 return this.stationInfo
?.ocppPersistentConfiguration
?? true;
971 private getStationInfoPersistentConfiguration(): boolean {
972 return this.stationInfo
?.stationInfoPersistentConfiguration
?? true;
975 private handleUnsupportedVersion(version
: OCPPVersion
) {
976 const errMsg
= `Unsupported protocol version '${version}' configured in template file ${this.templateFile}`;
977 logger
.error(`${this.logPrefix()} ${errMsg}`);
978 throw new BaseError(errMsg
);
981 private initialize(): void {
982 this.configurationFile
= path
.join(
983 path
.dirname(this.templateFile
.replace('station-templates', 'configurations')),
984 `${ChargingStationUtils.getHashId(this.index, this.getTemplateFromFile())}.json`
986 this.stationInfo
= this.getStationInfo();
987 this.saveStationInfo();
988 // Avoid duplication of connectors related information in RAM
989 this.stationInfo
?.Connectors
&& delete this.stationInfo
.Connectors
;
990 this.configuredSupervisionUrl
= this.getConfiguredSupervisionUrl();
991 if (this.getEnableStatistics() === true) {
992 this.performanceStatistics
= PerformanceStatistics
.getInstance(
993 this.stationInfo
.hashId
,
994 this.stationInfo
.chargingStationId
,
995 this.configuredSupervisionUrl
998 this.bootNotificationRequest
= ChargingStationUtils
.createBootNotificationRequest(
1001 this.powerDivider
= this.getPowerDivider();
1002 // OCPP configuration
1003 this.ocppConfiguration
= this.getOcppConfiguration();
1004 this.initializeOcppConfiguration();
1005 const ocppVersion
= this.stationInfo
.ocppVersion
?? OCPPVersion
.VERSION_16
;
1006 switch (ocppVersion
) {
1007 case OCPPVersion
.VERSION_16
:
1008 this.ocppIncomingRequestService
=
1009 OCPP16IncomingRequestService
.getInstance
<OCPP16IncomingRequestService
>();
1010 this.ocppRequestService
= OCPP16RequestService
.getInstance
<OCPP16RequestService
>(
1011 OCPP16ResponseService
.getInstance
<OCPP16ResponseService
>()
1014 case OCPPVersion
.VERSION_20
:
1015 case OCPPVersion
.VERSION_201
:
1016 this.ocppIncomingRequestService
=
1017 OCPP20IncomingRequestService
.getInstance
<OCPP20IncomingRequestService
>();
1018 this.ocppRequestService
= OCPP20RequestService
.getInstance
<OCPP20RequestService
>(
1019 OCPP20ResponseService
.getInstance
<OCPP20ResponseService
>()
1023 this.handleUnsupportedVersion(ocppVersion
);
1026 if (this.stationInfo
?.autoRegister
=== true) {
1027 this.bootNotificationResponse
= {
1028 currentTime
: new Date(),
1029 interval
: this.getHeartbeatInterval() / 1000,
1030 status: RegistrationStatusEnumType
.ACCEPTED
,
1034 this.stationInfo
.firmwareStatus
=== FirmwareStatus
.Installing
&&
1035 Utils
.isNotEmptyString(this.stationInfo
.firmwareVersion
) &&
1036 Utils
.isNotEmptyString(this.stationInfo
.firmwareVersionPattern
)
1038 const patternGroup
: number | undefined =
1039 this.stationInfo
.firmwareUpgrade
?.versionUpgrade
?.patternGroup
??
1040 this.stationInfo
.firmwareVersion
?.split('.').length
;
1041 const match
= this.stationInfo
?.firmwareVersion
1042 ?.match(new RegExp(this.stationInfo
.firmwareVersionPattern
))
1043 ?.slice(1, patternGroup
+ 1);
1044 const patchLevelIndex
= match
.length
- 1;
1045 match
[patchLevelIndex
] = (
1046 Utils
.convertToInt(match
[patchLevelIndex
]) +
1047 this.stationInfo
.firmwareUpgrade
?.versionUpgrade
?.step
1049 this.stationInfo
.firmwareVersion
= match
?.join('.');
1053 private initializeOcppConfiguration(): void {
1055 !ChargingStationConfigurationUtils
.getConfigurationKey(
1057 StandardParametersKey
.HeartbeatInterval
1060 ChargingStationConfigurationUtils
.addConfigurationKey(
1062 StandardParametersKey
.HeartbeatInterval
,
1067 !ChargingStationConfigurationUtils
.getConfigurationKey(
1069 StandardParametersKey
.HeartBeatInterval
1072 ChargingStationConfigurationUtils
.addConfigurationKey(
1074 StandardParametersKey
.HeartBeatInterval
,
1080 this.getSupervisionUrlOcppConfiguration() &&
1081 !ChargingStationConfigurationUtils
.getConfigurationKey(this, this.getSupervisionUrlOcppKey())
1083 ChargingStationConfigurationUtils
.addConfigurationKey(
1085 this.getSupervisionUrlOcppKey(),
1086 this.configuredSupervisionUrl
.href
,
1090 !this.getSupervisionUrlOcppConfiguration() &&
1091 ChargingStationConfigurationUtils
.getConfigurationKey(this, this.getSupervisionUrlOcppKey())
1093 ChargingStationConfigurationUtils
.deleteConfigurationKey(
1095 this.getSupervisionUrlOcppKey(),
1100 Utils
.isNotEmptyString(this.stationInfo
?.amperageLimitationOcppKey
) &&
1101 !ChargingStationConfigurationUtils
.getConfigurationKey(
1103 this.stationInfo
.amperageLimitationOcppKey
1106 ChargingStationConfigurationUtils
.addConfigurationKey(
1108 this.stationInfo
.amperageLimitationOcppKey
,
1110 this.stationInfo
.maximumAmperage
*
1111 ChargingStationUtils
.getAmperageLimitationUnitDivider(this.stationInfo
)
1116 !ChargingStationConfigurationUtils
.getConfigurationKey(
1118 StandardParametersKey
.SupportedFeatureProfiles
1121 ChargingStationConfigurationUtils
.addConfigurationKey(
1123 StandardParametersKey
.SupportedFeatureProfiles
,
1124 `${SupportedFeatureProfiles.Core},${SupportedFeatureProfiles.FirmwareManagement},${SupportedFeatureProfiles.LocalAuthListManagement},${SupportedFeatureProfiles.SmartCharging},${SupportedFeatureProfiles.RemoteTrigger}`
1127 ChargingStationConfigurationUtils
.addConfigurationKey(
1129 StandardParametersKey
.NumberOfConnectors
,
1130 this.getNumberOfConnectors().toString(),
1135 !ChargingStationConfigurationUtils
.getConfigurationKey(
1137 StandardParametersKey
.MeterValuesSampledData
1140 ChargingStationConfigurationUtils
.addConfigurationKey(
1142 StandardParametersKey
.MeterValuesSampledData
,
1143 MeterValueMeasurand
.ENERGY_ACTIVE_IMPORT_REGISTER
1147 !ChargingStationConfigurationUtils
.getConfigurationKey(
1149 StandardParametersKey
.ConnectorPhaseRotation
1152 const connectorPhaseRotation
= [];
1153 for (const connectorId
of this.connectors
.keys()) {
1155 if (connectorId
=== 0 && this.getNumberOfPhases() === 0) {
1156 connectorPhaseRotation
.push(`${connectorId}.${ConnectorPhaseRotation.RST}`);
1157 } else if (connectorId
> 0 && this.getNumberOfPhases() === 0) {
1158 connectorPhaseRotation
.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`);
1160 } else if (connectorId
> 0 && this.getNumberOfPhases() === 1) {
1161 connectorPhaseRotation
.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`);
1162 } else if (connectorId
> 0 && this.getNumberOfPhases() === 3) {
1163 connectorPhaseRotation
.push(`${connectorId}.${ConnectorPhaseRotation.RST}`);
1166 ChargingStationConfigurationUtils
.addConfigurationKey(
1168 StandardParametersKey
.ConnectorPhaseRotation
,
1169 connectorPhaseRotation
.toString()
1173 !ChargingStationConfigurationUtils
.getConfigurationKey(
1175 StandardParametersKey
.AuthorizeRemoteTxRequests
1178 ChargingStationConfigurationUtils
.addConfigurationKey(
1180 StandardParametersKey
.AuthorizeRemoteTxRequests
,
1185 !ChargingStationConfigurationUtils
.getConfigurationKey(
1187 StandardParametersKey
.LocalAuthListEnabled
1189 ChargingStationConfigurationUtils
.getConfigurationKey(
1191 StandardParametersKey
.SupportedFeatureProfiles
1192 )?.value
?.includes(SupportedFeatureProfiles
.LocalAuthListManagement
)
1194 ChargingStationConfigurationUtils
.addConfigurationKey(
1196 StandardParametersKey
.LocalAuthListEnabled
,
1201 !ChargingStationConfigurationUtils
.getConfigurationKey(
1203 StandardParametersKey
.ConnectionTimeOut
1206 ChargingStationConfigurationUtils
.addConfigurationKey(
1208 StandardParametersKey
.ConnectionTimeOut
,
1209 Constants
.DEFAULT_CONNECTION_TIMEOUT
.toString()
1212 this.saveOcppConfiguration();
1215 private initializeConnectors(
1216 stationInfo
: ChargingStationInfo
,
1217 configuredMaxConnectors
: number,
1218 templateMaxConnectors
: number
1220 if (!stationInfo
?.Connectors
&& this.connectors
.size
=== 0) {
1221 const logMsg
= `No already defined connectors and charging station information from template ${this.templateFile} with no connectors configuration defined`;
1222 logger
.error(`${this.logPrefix()} ${logMsg}`);
1223 throw new BaseError(logMsg
);
1225 if (!stationInfo
?.Connectors
[0]) {
1227 `${this.logPrefix()} Charging station information from template ${
1229 } with no connector Id 0 configuration`
1232 if (stationInfo
?.Connectors
) {
1233 const connectorsConfigHash
= crypto
1234 .createHash(Constants
.DEFAULT_HASH_ALGORITHM
)
1235 .update(`${JSON.stringify(stationInfo?.Connectors)}${configuredMaxConnectors.toString()}`)
1237 const connectorsConfigChanged
=
1238 this.connectors
?.size
!== 0 && this.connectorsConfigurationHash
!== connectorsConfigHash
;
1239 if (this.connectors
?.size
=== 0 || connectorsConfigChanged
) {
1240 connectorsConfigChanged
&& this.connectors
.clear();
1241 this.connectorsConfigurationHash
= connectorsConfigHash
;
1242 // Add connector Id 0
1243 let lastConnector
= '0';
1244 for (lastConnector
in stationInfo
?.Connectors
) {
1245 const connectorStatus
= stationInfo
?.Connectors
[lastConnector
];
1246 const lastConnectorId
= Utils
.convertToInt(lastConnector
);
1248 lastConnectorId
=== 0 &&
1249 this.getUseConnectorId0(stationInfo
) === true &&
1252 this.checkStationInfoConnectorStatus(lastConnectorId
, connectorStatus
);
1253 this.connectors
.set(
1255 Utils
.cloneObject
<ConnectorStatus
>(connectorStatus
)
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 const connectorStatus
= stationInfo
?.Connectors
[randConnectorId
.toString()];
1270 this.checkStationInfoConnectorStatus(randConnectorId
, connectorStatus
);
1271 this.connectors
.set(index
, Utils
.cloneObject
<ConnectorStatus
>(connectorStatus
));
1272 this.getConnectorStatus(index
).availability
= AvailabilityType
.OPERATIVE
;
1273 if (Utils
.isUndefined(this.getConnectorStatus(index
)?.chargingProfiles
)) {
1274 this.getConnectorStatus(index
).chargingProfiles
= [];
1281 `${this.logPrefix()} Charging station information from template ${
1283 } with no connectors configuration defined, using already defined connectors`
1286 // Initialize transaction attributes on connectors
1287 for (const connectorId
of this.connectors
.keys()) {
1288 if (connectorId
> 0 && this.getConnectorStatus(connectorId
)?.transactionStarted
=== true) {
1290 `${this.logPrefix()} Connector ${connectorId} at initialization has a transaction started: ${
1291 this.getConnectorStatus(connectorId)?.transactionId
1297 (this.getConnectorStatus(connectorId
)?.transactionStarted
=== undefined ||
1298 this.getConnectorStatus(connectorId
)?.transactionStarted
=== null)
1300 this.initializeConnectorStatus(connectorId
);
1305 private checkStationInfoConnectorStatus(
1306 connectorId
: number,
1307 connectorStatus
: ConnectorStatus
1309 if (!Utils
.isNullOrUndefined(connectorStatus
?.status)) {
1311 `${this.logPrefix()} Charging station information from template ${
1313 } with connector ${connectorId} status configuration defined, undefine it`
1315 connectorStatus
.status = undefined;
1319 private getConfigurationFromFile(): ChargingStationConfiguration
| undefined {
1320 let configuration
: ChargingStationConfiguration
| undefined;
1321 if (this.configurationFile
&& fs
.existsSync(this.configurationFile
)) {
1323 if (this.sharedLRUCache
.hasChargingStationConfiguration(this.configurationFileHash
)) {
1324 configuration
= this.sharedLRUCache
.getChargingStationConfiguration(
1325 this.configurationFileHash
1328 const measureId
= `${FileType.ChargingStationConfiguration} read`;
1329 const beginId
= PerformanceStatistics
.beginMeasure(measureId
);
1330 configuration
= JSON
.parse(
1331 fs
.readFileSync(this.configurationFile
, 'utf8')
1332 ) as ChargingStationConfiguration
;
1333 PerformanceStatistics
.endMeasure(measureId
, beginId
);
1334 this.configurationFileHash
= configuration
.configurationHash
;
1335 this.sharedLRUCache
.setChargingStationConfiguration(configuration
);
1338 FileUtils
.handleFileException(
1339 this.configurationFile
,
1340 FileType
.ChargingStationConfiguration
,
1341 error
as NodeJS
.ErrnoException
,
1346 return configuration
;
1349 private saveConfiguration(): void {
1350 if (this.configurationFile
) {
1352 if (!fs
.existsSync(path
.dirname(this.configurationFile
))) {
1353 fs
.mkdirSync(path
.dirname(this.configurationFile
), { recursive
: true });
1355 const configurationData
: ChargingStationConfiguration
=
1356 this.getConfigurationFromFile() ?? {};
1357 this.ocppConfiguration
?.configurationKey
&&
1358 (configurationData
.configurationKey
= this.ocppConfiguration
.configurationKey
);
1359 this.stationInfo
&& (configurationData
.stationInfo
= this.stationInfo
);
1360 delete configurationData
.configurationHash
;
1361 const configurationHash
= crypto
1362 .createHash(Constants
.DEFAULT_HASH_ALGORITHM
)
1363 .update(JSON
.stringify(configurationData
))
1365 if (this.configurationFileHash
!== configurationHash
) {
1366 configurationData
.configurationHash
= configurationHash
;
1367 const measureId
= `${FileType.ChargingStationConfiguration} write`;
1368 const beginId
= PerformanceStatistics
.beginMeasure(measureId
);
1369 const fileDescriptor
= fs
.openSync(this.configurationFile
, 'w');
1370 fs
.writeFileSync(fileDescriptor
, JSON
.stringify(configurationData
, null, 2), 'utf8');
1371 fs
.closeSync(fileDescriptor
);
1372 PerformanceStatistics
.endMeasure(measureId
, beginId
);
1373 this.sharedLRUCache
.deleteChargingStationConfiguration(this.configurationFileHash
);
1374 this.configurationFileHash
= configurationHash
;
1375 this.sharedLRUCache
.setChargingStationConfiguration(configurationData
);
1378 `${this.logPrefix()} Not saving unchanged charging station configuration file ${
1379 this.configurationFile
1384 FileUtils
.handleFileException(
1385 this.configurationFile
,
1386 FileType
.ChargingStationConfiguration
,
1387 error
as NodeJS
.ErrnoException
,
1393 `${this.logPrefix()} Trying to save charging station configuration to undefined configuration file`
1398 private getOcppConfigurationFromTemplate(): ChargingStationOcppConfiguration
| undefined {
1399 return this.getTemplateFromFile()?.Configuration
;
1402 private getOcppConfigurationFromFile(): ChargingStationOcppConfiguration
| undefined {
1403 let configuration
: ChargingStationConfiguration
| undefined;
1404 if (this.getOcppPersistentConfiguration() === true) {
1405 const configurationFromFile
= this.getConfigurationFromFile();
1406 configuration
= configurationFromFile
?.configurationKey
&& configurationFromFile
;
1408 configuration
&& delete configuration
.stationInfo
;
1409 return configuration
;
1412 private getOcppConfiguration(): ChargingStationOcppConfiguration
| undefined {
1413 let ocppConfiguration
: ChargingStationOcppConfiguration
| undefined =
1414 this.getOcppConfigurationFromFile();
1415 if (!ocppConfiguration
) {
1416 ocppConfiguration
= this.getOcppConfigurationFromTemplate();
1418 return ocppConfiguration
;
1421 private async onOpen(): Promise
<void> {
1422 if (this.isWebSocketConnectionOpened() === true) {
1424 `${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.toString()} succeeded`
1426 if (this.isRegistered() === false) {
1427 // Send BootNotification
1428 let registrationRetryCount
= 0;
1430 this.bootNotificationResponse
= await this.ocppRequestService
.requestHandler
<
1431 BootNotificationRequest
,
1432 BootNotificationResponse
1433 >(this, RequestCommand
.BOOT_NOTIFICATION
, this.bootNotificationRequest
, {
1434 skipBufferingOnError
: true,
1436 if (this.isRegistered() === false) {
1437 this.getRegistrationMaxRetries() !== -1 && registrationRetryCount
++;
1439 this?.bootNotificationResponse
?.interval
1440 ? this.bootNotificationResponse
.interval
* 1000
1441 : Constants
.OCPP_DEFAULT_BOOT_NOTIFICATION_INTERVAL
1445 this.isRegistered() === false &&
1446 (registrationRetryCount
<= this.getRegistrationMaxRetries() ||
1447 this.getRegistrationMaxRetries() === -1)
1450 if (this.isRegistered() === true) {
1451 if (this.isInAcceptedState() === true) {
1452 await this.startMessageSequence();
1456 `${this.logPrefix()} Registration failure: max retries reached (${this.getRegistrationMaxRetries()}) or retry disabled (${this.getRegistrationMaxRetries()})`
1459 this.wsConnectionRestarted
= false;
1460 this.autoReconnectRetryCount
= 0;
1461 parentPort
?.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
1464 `${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.toString()} failed`
1469 private async onClose(code
: number, reason
: Buffer
): Promise
<void> {
1472 case WebSocketCloseEventStatusCode
.CLOSE_NORMAL
:
1473 case WebSocketCloseEventStatusCode
.CLOSE_NO_STATUS
:
1475 `${this.logPrefix()} WebSocket normally closed with status '${Utils.getWebSocketCloseEventStatusString(
1477 )}' and reason '${reason.toString()}'`
1479 this.autoReconnectRetryCount
= 0;
1484 `${this.logPrefix()} WebSocket abnormally closed with status '${Utils.getWebSocketCloseEventStatusString(
1486 )}' and reason '${reason.toString()}'`
1488 this.started
=== true && (await this.reconnect());
1491 parentPort
?.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
1494 private async onMessage(data
: RawData
): Promise
<void> {
1495 let messageType
: number;
1496 let messageId
: string;
1497 let commandName
: IncomingRequestCommand
;
1498 let commandPayload
: JsonType
;
1499 let errorType
: ErrorType
;
1500 let errorMessage
: string;
1501 let errorDetails
: JsonType
;
1502 let responseCallback
: ResponseCallback
;
1503 let errorCallback
: ErrorCallback
;
1504 let requestCommandName
: RequestCommand
| IncomingRequestCommand
;
1505 let requestPayload
: JsonType
;
1506 let cachedRequest
: CachedRequest
;
1509 const request
= JSON
.parse(data
.toString()) as IncomingRequest
| Response
| ErrorResponse
;
1510 if (Array.isArray(request
) === true) {
1511 [messageType
, messageId
] = request
;
1512 // Check the type of message
1513 switch (messageType
) {
1515 case MessageType
.CALL_MESSAGE
:
1516 [, , commandName
, commandPayload
] = request
as IncomingRequest
;
1517 if (this.getEnableStatistics() === true) {
1518 this.performanceStatistics
?.addRequestStatistic(commandName
, messageType
);
1521 `${this.logPrefix()} << Command '${commandName}' received request payload: ${JSON.stringify(
1525 // Process the message
1526 await this.ocppIncomingRequestService
.incomingRequestHandler(
1534 case MessageType
.CALL_RESULT_MESSAGE
:
1535 [, , commandPayload
] = request
as Response
;
1536 if (this.requests
.has(messageId
) === false) {
1538 throw new OCPPError(
1539 ErrorType
.INTERNAL_ERROR
,
1540 `Response for unknown message id ${messageId}`,
1546 cachedRequest
= this.requests
.get(messageId
);
1547 if (Array.isArray(cachedRequest
) === true) {
1548 [responseCallback
, errorCallback
, requestCommandName
, requestPayload
] = cachedRequest
;
1550 throw new OCPPError(
1551 ErrorType
.PROTOCOL_ERROR
,
1552 `Cached request for message id ${messageId} response is not an array`,
1554 cachedRequest
as unknown
as JsonType
1558 `${this.logPrefix()} << Command '${
1559 requestCommandName ?? Constants.UNKNOWN_COMMAND
1560 }' received response payload: ${JSON.stringify(request)}`
1562 responseCallback(commandPayload
, requestPayload
);
1565 case MessageType
.CALL_ERROR_MESSAGE
:
1566 [, , errorType
, errorMessage
, errorDetails
] = request
as ErrorResponse
;
1567 if (this.requests
.has(messageId
) === false) {
1569 throw new OCPPError(
1570 ErrorType
.INTERNAL_ERROR
,
1571 `Error response for unknown message id ${messageId}`,
1573 { errorType
, errorMessage
, errorDetails
}
1576 cachedRequest
= this.requests
.get(messageId
);
1577 if (Array.isArray(cachedRequest
) === true) {
1578 [, errorCallback
, requestCommandName
] = cachedRequest
;
1580 throw new OCPPError(
1581 ErrorType
.PROTOCOL_ERROR
,
1582 `Cached request for message id ${messageId} error response is not an array`,
1584 cachedRequest
as unknown
as JsonType
1588 `${this.logPrefix()} << Command '${
1589 requestCommandName ?? Constants.UNKNOWN_COMMAND
1590 }' received error response payload: ${JSON.stringify(request)}`
1592 errorCallback(new OCPPError(errorType
, errorMessage
, requestCommandName
, errorDetails
));
1596 // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
1597 errMsg
= `Wrong message type ${messageType}`;
1598 logger
.error(`${this.logPrefix()} ${errMsg}`);
1599 throw new OCPPError(ErrorType
.PROTOCOL_ERROR
, errMsg
);
1601 parentPort
?.postMessage(MessageChannelUtils
.buildUpdatedMessage(this));
1603 throw new OCPPError(ErrorType
.PROTOCOL_ERROR
, 'Incoming message is not an array', null, {
1610 `${this.logPrefix()} Incoming OCPP command '${
1611 commandName ?? requestCommandName ?? Constants.UNKNOWN_COMMAND
1612 }' message '${data.toString()}'${
1613 messageType !== MessageType.CALL_MESSAGE
1614 ? ` matching cached request
'${JSON.stringify(this.requests.get(messageId))}'`
1616 } processing error:`,
1619 if (error
instanceof OCPPError
=== false) {
1621 `${this.logPrefix()} Error thrown at incoming OCPP command '${
1622 commandName ?? requestCommandName ?? Constants.UNKNOWN_COMMAND
1623 }' message '${data.toString()}' handling is not an OCPPError:`,
1627 switch (messageType
) {
1628 case MessageType
.CALL_MESSAGE
:
1630 await this.ocppRequestService
.sendError(
1634 commandName
?? requestCommandName
?? null
1637 case MessageType
.CALL_RESULT_MESSAGE
:
1638 case MessageType
.CALL_ERROR_MESSAGE
:
1639 if (errorCallback
) {
1640 // Reject the deferred promise in case of error at response handling (rejecting an already fulfilled promise is a no-op)
1641 errorCallback(error
as OCPPError
, false);
1643 // Remove the request from the cache in case of error at response handling
1644 this.requests
.delete(messageId
);
1651 private onPing(): void {
1652 logger
.debug(`${this.logPrefix()} Received a WS ping (rfc6455) from the server`);
1655 private onPong(): void {
1656 logger
.debug(`${this.logPrefix()} Received a WS pong (rfc6455) from the server`);
1659 private onError(error
: WSError
): void {
1660 this.closeWSConnection();
1661 logger
.error(`${this.logPrefix()} WebSocket error:`, error
);
1664 private getEnergyActiveImportRegister(connectorStatus
: ConnectorStatus
, rounded
= false): number {
1665 if (this.getMeteringPerTransaction() === true) {
1668 ? Math.round(connectorStatus
?.transactionEnergyActiveImportRegisterValue
)
1669 : connectorStatus
?.transactionEnergyActiveImportRegisterValue
) ?? 0
1674 ? Math.round(connectorStatus
?.energyActiveImportRegisterValue
)
1675 : connectorStatus
?.energyActiveImportRegisterValue
) ?? 0
1679 private getUseConnectorId0(stationInfo
?: ChargingStationInfo
): boolean {
1680 const localStationInfo
= stationInfo
?? this.stationInfo
;
1681 return localStationInfo
?.useConnectorId0
?? true;
1684 private getNumberOfRunningTransactions(): number {
1686 for (const connectorId
of this.connectors
.keys()) {
1687 if (connectorId
> 0 && this.getConnectorStatus(connectorId
)?.transactionStarted
=== true) {
1694 private async stopRunningTransactions(reason
= StopTransactionReason
.NONE
): Promise
<void> {
1695 for (const connectorId
of this.connectors
.keys()) {
1696 if (connectorId
> 0 && this.getConnectorStatus(connectorId
)?.transactionStarted
=== true) {
1697 await this.stopTransactionOnConnector(connectorId
, reason
);
1703 private getConnectionTimeout(): number {
1705 ChargingStationConfigurationUtils
.getConfigurationKey(
1707 StandardParametersKey
.ConnectionTimeOut
1712 ChargingStationConfigurationUtils
.getConfigurationKey(
1714 StandardParametersKey
.ConnectionTimeOut
1716 ) ?? Constants
.DEFAULT_CONNECTION_TIMEOUT
1719 return Constants
.DEFAULT_CONNECTION_TIMEOUT
;
1722 // -1 for unlimited, 0 for disabling
1723 private getAutoReconnectMaxRetries(): number | undefined {
1724 if (!Utils
.isUndefined(this.stationInfo
.autoReconnectMaxRetries
)) {
1725 return this.stationInfo
.autoReconnectMaxRetries
;
1727 if (!Utils
.isUndefined(Configuration
.getAutoReconnectMaxRetries())) {
1728 return Configuration
.getAutoReconnectMaxRetries();
1734 private getRegistrationMaxRetries(): number | undefined {
1735 if (!Utils
.isUndefined(this.stationInfo
.registrationMaxRetries
)) {
1736 return this.stationInfo
.registrationMaxRetries
;
1741 private getPowerDivider(): number {
1742 let powerDivider
= this.getNumberOfConnectors();
1743 if (this.stationInfo
?.powerSharedByConnectors
) {
1744 powerDivider
= this.getNumberOfRunningTransactions();
1746 return powerDivider
;
1749 private getMaximumAmperage(stationInfo
: ChargingStationInfo
): number | undefined {
1750 const maximumPower
= this.getMaximumPower(stationInfo
);
1751 switch (this.getCurrentOutType(stationInfo
)) {
1752 case CurrentType
.AC
:
1753 return ACElectricUtils
.amperagePerPhaseFromPower(
1754 this.getNumberOfPhases(stationInfo
),
1755 maximumPower
/ this.getNumberOfConnectors(),
1756 this.getVoltageOut(stationInfo
)
1758 case CurrentType
.DC
:
1759 return DCElectricUtils
.amperage(maximumPower
, this.getVoltageOut(stationInfo
));
1763 private getAmperageLimitation(): number | undefined {
1765 Utils
.isNotEmptyString(this.stationInfo
?.amperageLimitationOcppKey
) &&
1766 ChargingStationConfigurationUtils
.getConfigurationKey(
1768 this.stationInfo
.amperageLimitationOcppKey
1773 ChargingStationConfigurationUtils
.getConfigurationKey(
1775 this.stationInfo
.amperageLimitationOcppKey
1777 ) / ChargingStationUtils
.getAmperageLimitationUnitDivider(this.stationInfo
)
1782 private async startMessageSequence(): Promise
<void> {
1783 if (this.stationInfo
?.autoRegister
=== true) {
1784 await this.ocppRequestService
.requestHandler
<
1785 BootNotificationRequest
,
1786 BootNotificationResponse
1787 >(this, RequestCommand
.BOOT_NOTIFICATION
, this.bootNotificationRequest
, {
1788 skipBufferingOnError
: true,
1791 // Start WebSocket ping
1792 this.startWebSocketPing();
1794 this.startHeartbeat();
1795 // Initialize connectors status
1796 for (const connectorId
of this.connectors
.keys()) {
1797 let connectorStatus
: ConnectorStatusEnum
| undefined;
1798 if (connectorId
=== 0) {
1801 !this.getConnectorStatus(connectorId
)?.status &&
1802 (this.isChargingStationAvailable() === false ||
1803 this.isConnectorAvailable(connectorId
) === false)
1805 connectorStatus
= ConnectorStatusEnum
.UNAVAILABLE
;
1807 !this.getConnectorStatus(connectorId
)?.status &&
1808 this.getConnectorStatus(connectorId
)?.bootStatus
1810 // Set boot status in template at startup
1811 connectorStatus
= this.getConnectorStatus(connectorId
)?.bootStatus
;
1812 } else if (this.getConnectorStatus(connectorId
)?.status) {
1813 // Set previous status at startup
1814 connectorStatus
= this.getConnectorStatus(connectorId
)?.status;
1816 // Set default status
1817 connectorStatus
= ConnectorStatusEnum
.AVAILABLE
;
1819 await this.ocppRequestService
.requestHandler
<
1820 StatusNotificationRequest
,
1821 StatusNotificationResponse
1824 RequestCommand
.STATUS_NOTIFICATION
,
1825 OCPPServiceUtils
.buildStatusNotificationRequest(this, connectorId
, connectorStatus
)
1827 this.getConnectorStatus(connectorId
).status = connectorStatus
;
1829 if (this.stationInfo
?.firmwareStatus
=== FirmwareStatus
.Installing
) {
1830 await this.ocppRequestService
.requestHandler
<
1831 FirmwareStatusNotificationRequest
,
1832 FirmwareStatusNotificationResponse
1833 >(this, RequestCommand
.FIRMWARE_STATUS_NOTIFICATION
, {
1834 status: FirmwareStatus
.Installed
,
1836 this.stationInfo
.firmwareStatus
= FirmwareStatus
.Installed
;
1840 if (this.getAutomaticTransactionGeneratorConfigurationFromTemplate()?.enable
=== true) {
1841 this.startAutomaticTransactionGenerator();
1843 this.wsConnectionRestarted
=== true && this.flushMessageBuffer();
1846 private async stopMessageSequence(
1847 reason
: StopTransactionReason
= StopTransactionReason
.NONE
1849 // Stop WebSocket ping
1850 this.stopWebSocketPing();
1852 this.stopHeartbeat();
1853 // Stop ongoing transactions
1854 if (this.automaticTransactionGenerator
?.started
=== true) {
1855 this.stopAutomaticTransactionGenerator();
1857 await this.stopRunningTransactions(reason
);
1859 for (const connectorId
of this.connectors
.keys()) {
1860 if (connectorId
> 0) {
1861 await this.ocppRequestService
.requestHandler
<
1862 StatusNotificationRequest
,
1863 StatusNotificationResponse
1866 RequestCommand
.STATUS_NOTIFICATION
,
1867 OCPPServiceUtils
.buildStatusNotificationRequest(
1870 ConnectorStatusEnum
.UNAVAILABLE
1873 this.getConnectorStatus(connectorId
).status = undefined;
1878 private startWebSocketPing(): void {
1879 const webSocketPingInterval
: number = ChargingStationConfigurationUtils
.getConfigurationKey(
1881 StandardParametersKey
.WebSocketPingInterval
1883 ? Utils
.convertToInt(
1884 ChargingStationConfigurationUtils
.getConfigurationKey(
1886 StandardParametersKey
.WebSocketPingInterval
1890 if (webSocketPingInterval
> 0 && !this.webSocketPingSetInterval
) {
1891 this.webSocketPingSetInterval
= setInterval(() => {
1892 if (this.isWebSocketConnectionOpened() === true) {
1893 this.wsConnection
?.ping();
1895 }, webSocketPingInterval
* 1000);
1897 `${this.logPrefix()} WebSocket ping started every ${Utils.formatDurationSeconds(
1898 webSocketPingInterval
1901 } else if (this.webSocketPingSetInterval
) {
1903 `${this.logPrefix()} WebSocket ping already started every ${Utils.formatDurationSeconds(
1904 webSocketPingInterval
1909 `${this.logPrefix()} WebSocket ping interval set to ${
1910 webSocketPingInterval
1911 ? Utils.formatDurationSeconds(webSocketPingInterval)
1912 : webSocketPingInterval
1913 }, not starting the WebSocket ping`
1918 private stopWebSocketPing(): void {
1919 if (this.webSocketPingSetInterval
) {
1920 clearInterval(this.webSocketPingSetInterval
);
1924 private getConfiguredSupervisionUrl(): URL
{
1925 const supervisionUrls
= this.stationInfo
?.supervisionUrls
?? Configuration
.getSupervisionUrls();
1926 if (Utils
.isNotEmptyArray(supervisionUrls
)) {
1927 switch (Configuration
.getSupervisionUrlDistribution()) {
1928 case SupervisionUrlDistribution
.ROUND_ROBIN
:
1930 this.configuredSupervisionUrlIndex
= (this.index
- 1) % supervisionUrls
.length
;
1932 case SupervisionUrlDistribution
.RANDOM
:
1933 this.configuredSupervisionUrlIndex
= Math.floor(
1934 Utils
.secureRandom() * supervisionUrls
.length
1937 case SupervisionUrlDistribution
.CHARGING_STATION_AFFINITY
:
1938 this.configuredSupervisionUrlIndex
= (this.index
- 1) % supervisionUrls
.length
;
1942 `${this.logPrefix()} Unknown supervision url distribution '${Configuration.getSupervisionUrlDistribution()}' from values '${SupervisionUrlDistribution.toString()}', defaulting to ${
1943 SupervisionUrlDistribution.CHARGING_STATION_AFFINITY
1946 this.configuredSupervisionUrlIndex
= (this.index
- 1) % supervisionUrls
.length
;
1949 return new URL(supervisionUrls
[this.configuredSupervisionUrlIndex
]);
1951 return new URL(supervisionUrls
as string);
1954 private getHeartbeatInterval(): number {
1955 const HeartbeatInterval
= ChargingStationConfigurationUtils
.getConfigurationKey(
1957 StandardParametersKey
.HeartbeatInterval
1959 if (HeartbeatInterval
) {
1960 return Utils
.convertToInt(HeartbeatInterval
.value
) * 1000;
1962 const HeartBeatInterval
= ChargingStationConfigurationUtils
.getConfigurationKey(
1964 StandardParametersKey
.HeartBeatInterval
1966 if (HeartBeatInterval
) {
1967 return Utils
.convertToInt(HeartBeatInterval
.value
) * 1000;
1969 this.stationInfo
?.autoRegister
=== false &&
1971 `${this.logPrefix()} Heartbeat interval configuration key not set, using default value: ${
1972 Constants.DEFAULT_HEARTBEAT_INTERVAL
1975 return Constants
.DEFAULT_HEARTBEAT_INTERVAL
;
1978 private stopHeartbeat(): void {
1979 if (this.heartbeatSetInterval
) {
1980 clearInterval(this.heartbeatSetInterval
);
1984 private terminateWSConnection(): void {
1985 if (this.isWebSocketConnectionOpened() === true) {
1986 this.wsConnection
?.terminate();
1987 this.wsConnection
= null;
1991 private stopMeterValues(connectorId
: number) {
1992 if (this.getConnectorStatus(connectorId
)?.transactionSetInterval
) {
1993 clearInterval(this.getConnectorStatus(connectorId
)?.transactionSetInterval
);
1997 private getReconnectExponentialDelay(): boolean {
1998 return this.stationInfo
?.reconnectExponentialDelay
?? false;
2001 private async reconnect(): Promise
<void> {
2002 // Stop WebSocket ping
2003 this.stopWebSocketPing();
2005 this.stopHeartbeat();
2006 // Stop the ATG if needed
2007 if (this.automaticTransactionGenerator
?.configuration
?.stopOnConnectionFailure
=== true) {
2008 this.stopAutomaticTransactionGenerator();
2011 this.autoReconnectRetryCount
< this.getAutoReconnectMaxRetries() ||
2012 this.getAutoReconnectMaxRetries() === -1
2014 this.autoReconnectRetryCount
++;
2015 const reconnectDelay
= this.getReconnectExponentialDelay()
2016 ? Utils
.exponentialDelay(this.autoReconnectRetryCount
)
2017 : this.getConnectionTimeout() * 1000;
2018 const reconnectDelayWithdraw
= 1000;
2019 const reconnectTimeout
=
2020 reconnectDelay
&& reconnectDelay
- reconnectDelayWithdraw
> 0
2021 ? reconnectDelay
- reconnectDelayWithdraw
2024 `${this.logPrefix()} WebSocket connection retry in ${Utils.roundTo(
2027 )}ms, timeout ${reconnectTimeout}ms`
2029 await Utils
.sleep(reconnectDelay
);
2031 `${this.logPrefix()} WebSocket connection retry #${this.autoReconnectRetryCount.toString()}`
2033 this.openWSConnection(
2034 { ...(this.stationInfo
?.wsOptions
?? {}), handshakeTimeout
: reconnectTimeout
},
2035 { closeOpened
: true }
2037 this.wsConnectionRestarted
= true;
2038 } else if (this.getAutoReconnectMaxRetries() !== -1) {
2040 `${this.logPrefix()} WebSocket connection retries failure: maximum retries reached (${
2041 this.autoReconnectRetryCount
2042 }) or retries disabled (${this.getAutoReconnectMaxRetries()})`
2047 private getAutomaticTransactionGeneratorConfigurationFromTemplate():
2048 | AutomaticTransactionGeneratorConfiguration
2050 return this.getTemplateFromFile()?.AutomaticTransactionGenerator
;
2053 private initializeConnectorStatus(connectorId
: number): void {
2054 this.getConnectorStatus(connectorId
).idTagLocalAuthorized
= false;
2055 this.getConnectorStatus(connectorId
).idTagAuthorized
= false;
2056 this.getConnectorStatus(connectorId
).transactionRemoteStarted
= false;
2057 this.getConnectorStatus(connectorId
).transactionStarted
= false;
2058 this.getConnectorStatus(connectorId
).energyActiveImportRegisterValue
= 0;
2059 this.getConnectorStatus(connectorId
).transactionEnergyActiveImportRegisterValue
= 0;