X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStation.ts;h=fc6a409adfc006c7200bc600441f83c8ebeb1490;hb=178956d8c51c6a2b4ecc55b592dfb9ee339b8105;hp=3c049c068e10ed1f21b2c3be95d12d5fa0532eeb;hpb=ea5d5eef0981ce1a29c2cb6ce5ee0e8408250952;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 3c049c06..fc6a409a 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -26,7 +26,6 @@ import { type OCPPRequestService, OCPPServiceUtils, } from './ocpp'; -import { OCPPConstants } from './ocpp/OCPPConstants'; import { SharedLRUCache } from './SharedLRUCache'; import { BaseError, OCPPError } from '../exception'; import { PerformanceStatistics } from '../performance'; @@ -63,18 +62,17 @@ import { MeterValueMeasurand, type MeterValuesRequest, type MeterValuesResponse, - OCPP16AuthorizationStatus, - type OCPP16AuthorizeRequest, - type OCPP16AuthorizeResponse, - OCPP16RequestCommand, - OCPP16SupportedFeatureProfiles, OCPPVersion, type OutgoingRequest, PowerUnits, RegistrationStatusEnumType, RequestCommand, + type Reservation, + ReservationFilterKey, + ReservationTerminationReason, type Response, StandardParametersKey, + type Status, type StatusNotificationRequest, type StatusNotificationResponse, StopTransactionReason, @@ -87,8 +85,6 @@ import { WebSocketCloseEventStatusCode, type WsOptions, } from '../types'; -import { ReservationTerminationReason } from '../types/ocpp/1.6/Reservation'; -import type { Reservation } from '../types/ocpp/Reservation'; import { ACElectricUtils, AsyncLock, @@ -96,14 +92,16 @@ import { Configuration, Constants, DCElectricUtils, - ErrorUtils, - FileUtils, - MessageChannelUtils, Utils, buildChargingStationAutomaticTransactionGeneratorConfiguration, buildConnectorsStatus, buildEvsesStatus, + buildStartedMessage, + buildStoppedMessage, + buildUpdatedMessage, + handleFileException, logger, + watchJsonFile, } from '../utils'; export class ChargingStation { @@ -140,8 +138,7 @@ export class ChargingStation { private readonly sharedLRUCache: SharedLRUCache; private webSocketPingSetInterval!: NodeJS.Timeout; private readonly chargingStationWorkerBroadcastChannel: ChargingStationWorkerBroadcastChannel; - private reservations?: Reservation[]; - private reservationExpiryDateSetInterval?: NodeJS.Timeout; + private reservationExpirationSetInterval?: NodeJS.Timeout; constructor(index: number, templateFile: string) { this.started = false; @@ -558,7 +555,8 @@ export class ChargingStation { ); } else { logger.error( - `${this.logPrefix()} Heartbeat interval set to ${this.getHeartbeatInterval()}, not starting the heartbeat` + `${this.logPrefix()} Heartbeat interval set to ${this.getHeartbeatInterval()}, + not starting the heartbeat` ); } } @@ -586,13 +584,15 @@ export class ChargingStation { } if (!this.getConnectorStatus(connectorId)) { logger.error( - `${this.logPrefix()} Trying to start MeterValues on non existing connector id ${connectorId.toString()}` + `${this.logPrefix()} Trying to start MeterValues on non existing connector id + ${connectorId.toString()}` ); return; } if (this.getConnectorStatus(connectorId)?.transactionStarted === false) { logger.error( - `${this.logPrefix()} Trying to start MeterValues on connector id ${connectorId} with no transaction started` + `${this.logPrefix()} Trying to start MeterValues on connector id ${connectorId} + with no transaction started` ); return; } else if ( @@ -600,7 +600,8 @@ export class ChargingStation { Utils.isNullOrUndefined(this.getConnectorStatus(connectorId)?.transactionId) ) { logger.error( - `${this.logPrefix()} Trying to start MeterValues on connector id ${connectorId} with no transaction id` + `${this.logPrefix()} Trying to start MeterValues on connector id ${connectorId} + with no transaction id` ); return; } @@ -652,12 +653,12 @@ export class ChargingStation { if (this.getEnableStatistics() === true) { this.performanceStatistics?.start(); } - if (this.supportsReservations()) { - this.startReservationExpiryDateSetInterval(); + if (this.hasFeatureProfile(SupportedFeatureProfiles.Reservation)) { + this.startReservationExpirationSetInterval(); } this.openWSConnection(); // Monitor charging station template file - this.templateFileWatcher = FileUtils.watchJsonFile( + this.templateFileWatcher = watchJsonFile( this.templateFile, FileType.ChargingStationTemplate, this.logPrefix(), @@ -694,7 +695,7 @@ export class ChargingStation { } ); this.started = true; - parentPort?.postMessage(MessageChannelUtils.buildStartedMessage(this)); + parentPort?.postMessage(buildStartedMessage(this)); this.starting = false; } else { logger.warn(`${this.logPrefix()} Charging station is already starting...`); @@ -719,7 +720,7 @@ export class ChargingStation { delete this.bootNotificationResponse; this.started = false; this.saveConfiguration(); - parentPort?.postMessage(MessageChannelUtils.buildStoppedMessage(this)); + parentPort?.postMessage(buildStoppedMessage(this)); this.stopping = false; } else { logger.warn(`${this.logPrefix()} Charging station is already stopping...`); @@ -760,11 +761,12 @@ export class ChargingStation { terminateOpened: false, } ): void { - options.handshakeTimeout = options?.handshakeTimeout ?? this.getConnectionTimeout() * 1000; + options = { handshakeTimeout: this.getConnectionTimeout() * 1000, ...options }; params = { ...{ closeOpened: false, terminateOpened: false }, ...params }; if (this.started === false && this.starting === false) { logger.warn( - `${this.logPrefix()} Cannot open OCPP connection to URL ${this.wsConnectionUrl.toString()} on stopped charging station` + `${this.logPrefix()} Cannot open OCPP connection to URL ${this.wsConnectionUrl.toString()} + on stopped charging station` ); return; } @@ -783,7 +785,8 @@ export class ChargingStation { if (this.isWebSocketConnectionOpened() === true) { logger.warn( - `${this.logPrefix()} OCPP connection to URL ${this.wsConnectionUrl.toString()} is already opened` + `${this.logPrefix()} OCPP connection to URL ${this.wsConnectionUrl.toString()} + is already opened` ); return; } @@ -831,12 +834,29 @@ export class ChargingStation { public getAutomaticTransactionGeneratorConfiguration(): | AutomaticTransactionGeneratorConfiguration | undefined { + let automaticTransactionGeneratorConfiguration: + | AutomaticTransactionGeneratorConfiguration + | undefined; const automaticTransactionGeneratorConfigurationFromFile = this.getConfigurationFromFile()?.automaticTransactionGenerator; - if (automaticTransactionGeneratorConfigurationFromFile) { - return automaticTransactionGeneratorConfigurationFromFile; + if ( + this.getAutomaticTransactionGeneratorPersistentConfiguration() && + automaticTransactionGeneratorConfigurationFromFile + ) { + automaticTransactionGeneratorConfiguration = + automaticTransactionGeneratorConfigurationFromFile; + } else { + automaticTransactionGeneratorConfiguration = + this.getTemplateFromFile()?.AutomaticTransactionGenerator; } - return this.getTemplateFromFile()?.AutomaticTransactionGenerator; + return { + ...Constants.DEFAULT_ATG_CONFIGURATION, + ...automaticTransactionGeneratorConfiguration, + }; + } + + public getAutomaticTransactionGeneratorStatuses(): Status[] | undefined { + return this.getConfigurationFromFile()?.automaticTransactionGeneratorStatuses; } public startAutomaticTransactionGenerator(connectorIds?: number[]): void { @@ -848,8 +868,8 @@ export class ChargingStation { } else { this.automaticTransactionGenerator?.start(); } - this.saveChargingStationAutomaticTransactionGeneratorConfiguration(); - parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(this)); + this.saveAutomaticTransactionGeneratorConfiguration(); + parentPort?.postMessage(buildUpdatedMessage(this)); } public stopAutomaticTransactionGenerator(connectorIds?: number[]): void { @@ -860,8 +880,8 @@ export class ChargingStation { } else { this.automaticTransactionGenerator?.stop(); } - this.saveChargingStationAutomaticTransactionGeneratorConfiguration(); - parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(this)); + this.saveAutomaticTransactionGeneratorConfiguration(); + parentPort?.postMessage(buildUpdatedMessage(this)); } public async stopTransactionOnConnector( @@ -901,40 +921,26 @@ export class ChargingStation { ); } - public supportsReservations(): boolean { - logger.info(`${this.logPrefix()} Check for reservation support in charging station`); - return ChargingStationConfigurationUtils.getConfigurationKey( - this, - StandardParametersKey.SupportedFeatureProfiles - ).value.includes(OCPP16SupportedFeatureProfiles.Reservation); - } - - public supportsReservationsOnConnectorId0(): boolean { - logger.info( - ` ${this.logPrefix()} Check for reservation support on connector 0 in charging station (CS)` - ); - return ( - this.supportsReservations() && + public getReservationOnConnectorId0Enabled(): boolean { + return Utils.convertToBoolean( ChargingStationConfigurationUtils.getConfigurationKey( this, - OCPPConstants.OCPP_RESERVE_CONNECTOR_ZERO_SUPPORTED - ).value === 'true' + StandardParametersKey.ReserveConnectorZeroSupported + ).value ); } public async addReservation(reservation: Reservation): Promise { - if (Utils.isNullOrUndefined(this.reservations)) { - this.reservations = []; - } const [exists, reservationFound] = this.doesReservationExists(reservation); if (exists) { await this.removeReservation(reservationFound); } - this.reservations.push(reservation); + const connectorStatus = this.getConnectorStatus(reservation.connectorId); + connectorStatus.reservation = reservation; + connectorStatus.status = ConnectorStatusEnum.Reserved; if (reservation.connectorId === 0) { return; } - this.getConnectorStatus(reservation.connectorId).status = ConnectorStatusEnum.Reserved; await this.ocppRequestService.requestHandler< StatusNotificationRequest, StatusNotificationResponse @@ -953,18 +959,23 @@ export class ChargingStation { reservation: Reservation, reason?: ReservationTerminationReason ): Promise { - const sameReservation = (r: Reservation) => r.id === reservation.id; - const index = this.reservations?.findIndex(sameReservation); - this.reservations.splice(index, 1); + const connector = this.getConnectorStatus(reservation.connectorId); switch (reason) { - case ReservationTerminationReason.TRANSACTION_STARTED: - // No action needed + case ReservationTerminationReason.TRANSACTION_STARTED: { + delete connector.reservation; + if (reservation.connectorId === 0) { + connector.status = ConnectorStatusEnum.Available; + } break; - case ReservationTerminationReason.CONNECTOR_STATE_CHANGED: - // No action needed + } + case ReservationTerminationReason.CONNECTOR_STATE_CHANGED: { + delete connector.reservation; break; - default: // ReservationTerminationReason.EXPIRED, ReservationTerminationReason.CANCELED - this.getConnectorStatus(reservation.connectorId).status = ConnectorStatusEnum.Available; + } + default: { + // ReservationTerminationReason.EXPIRED, ReservationTerminationReason.CANCELED + connector.status = ConnectorStatusEnum.Available; + delete connector.reservation; await this.ocppRequestService.requestHandler< StatusNotificationRequest, StatusNotificationResponse @@ -978,85 +989,57 @@ export class ChargingStation { ) ); break; + } } } - public getReservationById(id: number): Reservation { - return this.reservations?.find((reservation) => reservation.id === id); - } - - public getReservationByIdTag(id: string): Reservation { - return this.reservations?.find((reservation) => reservation.idTag === id); - } - - public getReservationByConnectorId(id: number): Reservation { - return this.reservations?.find((reservation) => reservation.connectorId === id); + public getReservationBy(filterKey: ReservationFilterKey, value: number | string): Reservation { + if (this.hasEvses) { + for (const evse of this.evses.values()) { + for (const connector of evse.connectors.values()) { + if (connector?.reservation?.[filterKey] === value) { + return connector.reservation; + } + } + } + } else { + for (const connector of this.connectors.values()) { + if (connector?.reservation?.[filterKey] === value) { + return connector.reservation; + } + } + } } public doesReservationExists(reservation: Partial): [boolean, Reservation] { - const sameReservation = (r: Reservation) => r.id === reservation.id; - const foundReservation = this.reservations?.find(sameReservation); + const foundReservation = this.getReservationBy( + ReservationFilterKey.RESERVATION_ID, + reservation?.id + ); return Utils.isUndefined(foundReservation) ? [false, null] : [true, foundReservation]; } - public async isAuthorized( - connectorId: number, - idTag: string, - parentIdTag?: string - ): Promise { - let authorized = false; - const connectorStatus = this.getConnectorStatus(connectorId); - if ( - this.getLocalAuthListEnabled() === true && - this.hasIdTags() === true && - Utils.isNotEmptyString( - this.idTagsCache - .getIdTags(ChargingStationUtils.getIdTagsFile(this.stationInfo)) - ?.find((tag) => tag === idTag) - ) - ) { - connectorStatus.localAuthorizeIdTag = idTag; - connectorStatus.idTagLocalAuthorized = true; - authorized = true; - } else if (this.getMustAuthorizeAtRemoteStart() === true) { - connectorStatus.authorizeIdTag = idTag; - const authorizeResponse: OCPP16AuthorizeResponse = - await this.ocppRequestService.requestHandler< - OCPP16AuthorizeRequest, - OCPP16AuthorizeResponse - >(this, OCPP16RequestCommand.AUTHORIZE, { - idTag: idTag, - }); - if (authorizeResponse?.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) { - authorized = true; - } - } else { - logger.warn( - `${this.logPrefix()} The charging station configuration expects authorize at - remote start transaction but local authorization or authorize isn't enabled` - ); - } - return authorized; - } - - public startReservationExpiryDateSetInterval(customInterval?: number): void { + public startReservationExpirationSetInterval(customInterval?: number): void { const interval = customInterval ?? Constants.DEFAULT_RESERVATION_EXPIRATION_OBSERVATION_INTERVAL; logger.info( `${this.logPrefix()} Reservation expiration date interval is set to ${interval} - and starts on CS now` + and starts on charging station now` ); // eslint-disable-next-line @typescript-eslint/no-misused-promises - this.reservationExpiryDateSetInterval = setInterval(async (): Promise => { - if (!Utils.isNullOrUndefined(this.reservations) && !Utils.isEmptyArray(this.reservations)) { - for (const reservation of this.reservations) { - if (reservation.expiryDate.toString() < new Date().toISOString()) { - await this.removeReservation(reservation); - logger.info( - `${this.logPrefix()} Reservation with ID ${ - reservation.id - } reached expiration date and was removed from CS` - ); + this.reservationExpirationSetInterval = setInterval(async (): Promise => { + if (this.hasEvses) { + for (const evse of this.evses.values()) { + for (const connector of evse.connectors.values()) { + if (connector?.reservation?.expiryDate.toString() < new Date().toISOString()) { + await this.removeReservation(connector.reservation); + } + } + } + } else { + for (const connector of this.connectors.values()) { + if (connector?.reservation?.expiryDate.toString() < new Date().toISOString()) { + await this.removeReservation(connector.reservation); } } } @@ -1064,25 +1047,29 @@ export class ChargingStation { } public restartReservationExpiryDateSetInterval(): void { - this.stopReservationExpiryDateSetInterval(); - this.startReservationExpiryDateSetInterval(); + this.stopReservationExpirationSetInterval(); + this.startReservationExpirationSetInterval(); } public validateIncomingRequestWithReservation(connectorId: number, idTag: string): boolean { - const reservation = this.getReservationByConnectorId(connectorId); - return Utils.isUndefined(reservation) || reservation.idTag !== idTag; + const reservation = this.getReservationBy(ReservationFilterKey.CONNECTOR_ID, connectorId); + return !Utils.isUndefined(reservation) && reservation.idTag === idTag; } public isConnectorReservable( reservationId: number, - connectorId?: number, - idTag?: string + idTag?: string, + connectorId?: number ): boolean { const [alreadyExists] = this.doesReservationExists({ id: reservationId }); if (alreadyExists) { return alreadyExists; } - const userReservedAlready = Utils.isUndefined(this.getReservationByIdTag(idTag)) ? false : true; + const userReservedAlready = Utils.isUndefined( + this.getReservationBy(ReservationFilterKey.ID_TAG, idTag) + ) + ? false + : true; const notConnectorZero = Utils.isUndefined(connectorId) ? true : connectorId > 0; const freeConnectorsAvailable = this.getNumberOfReservableConnectors() > 0; return !alreadyExists && !userReservedAlready && notConnectorZero && freeConnectorsAvailable; @@ -1090,20 +1077,41 @@ export class ChargingStation { private getNumberOfReservableConnectors(): number { let reservableConnectors = 0; - this.connectors.forEach((connector, id) => { - if (id === 0) { - return; + if (this.hasEvses) { + for (const evse of this.evses.values()) { + reservableConnectors = this.countReservableConnectors(evse.connectors); + } + } else { + reservableConnectors = this.countReservableConnectors(this.connectors); + } + return reservableConnectors - this.getNumberOfReservationsOnConnectorZero(); + } + + private countReservableConnectors(connectors: Map) { + let reservableConnectors = 0; + for (const [connectorId, connector] of connectors) { + if (connectorId === 0) { + continue; } if (connector.status === ConnectorStatusEnum.Available) { - reservableConnectors++; + ++reservableConnectors; } - }); - return reservableConnectors - this.getNumberOfReservationsOnConnectorZero(); + } + return reservableConnectors; } private getNumberOfReservationsOnConnectorZero(): number { - const reservations = this.reservations?.filter((reservation) => reservation.connectorId === 0); - return Utils.isNullOrUndefined(reservations) ? 0 : reservations.length; + let numberOfReservations = 0; + if (this.hasEvses) { + for (const evse of this.evses.values()) { + if (evse.connectors.get(0)?.reservation) { + ++numberOfReservations; + } + } + } else if (this.connectors.get(0)?.reservation) { + ++numberOfReservations; + } + return numberOfReservations; } private flushMessageBuffer(): void { @@ -1133,9 +1141,9 @@ export class ChargingStation { return this.stationInfo.supervisionUrlOcppConfiguration ?? false; } - private stopReservationExpiryDateSetInterval(): void { - if (this.reservationExpiryDateSetInterval) { - clearInterval(this.reservationExpiryDateSetInterval); + private stopReservationExpirationSetInterval(): void { + if (this.reservationExpirationSetInterval) { + clearInterval(this.reservationExpirationSetInterval); } } @@ -1163,7 +1171,7 @@ export class ChargingStation { this.templateFileHash = template.templateHash; } } catch (error) { - ErrorUtils.handleFileException( + handleFileException( this.templateFile, FileType.ChargingStationTemplate, error as NodeJS.ErrnoException, @@ -1282,8 +1290,13 @@ export class ChargingStation { return this.stationInfo?.stationInfoPersistentConfiguration ?? true; } + private getAutomaticTransactionGeneratorPersistentConfiguration(): boolean { + return this.stationInfo?.automaticTransactionGeneratorPersistentConfiguration ?? true; + } + private handleUnsupportedVersion(version: OCPPVersion) { - const errorMsg = `Unsupported protocol version '${version}' configured in template file ${this.templateFile}`; + const errorMsg = `Unsupported protocol version '${version}' configured + in template file ${this.templateFile}`; logger.error(`${this.logPrefix()} ${errorMsg}`); throw new BaseError(errorMsg); } @@ -1296,9 +1309,8 @@ export class ChargingStation { `${ChargingStationUtils.getHashId(this.index, stationTemplate)}.json` ); const chargingStationConfiguration = this.getConfigurationFromFile(); - const featureFlag = false; if ( - featureFlag && + chargingStationConfiguration?.stationInfo?.templateHash === stationTemplate?.templateHash && (chargingStationConfiguration?.connectorsStatus || chargingStationConfiguration?.evsesStatus) ) { this.initializeConnectorsOrEvsesFromFile(chargingStationConfiguration); @@ -1681,7 +1693,7 @@ export class ChargingStation { if (stationTemplate?.Evses) { const evsesConfigHash = crypto .createHash(Constants.DEFAULT_HASH_ALGORITHM) - .update(`${JSON.stringify(stationTemplate?.Evses)}`) + .update(JSON.stringify(stationTemplate?.Evses)) .digest('hex'); const evsesConfigChanged = this.evses?.size !== 0 && this.evsesConfigurationHash !== evsesConfigHash; @@ -1742,7 +1754,7 @@ export class ChargingStation { this.configurationFileHash = configuration.configurationHash; } } catch (error) { - ErrorUtils.handleFileException( + handleFileException( this.configurationFile, FileType.ChargingStationConfiguration, error as NodeJS.ErrnoException, @@ -1753,8 +1765,10 @@ export class ChargingStation { return configuration; } - private saveChargingStationAutomaticTransactionGeneratorConfiguration(): void { - this.saveConfiguration(); + private saveAutomaticTransactionGeneratorConfiguration(): void { + if (this.getAutomaticTransactionGeneratorPersistentConfiguration()) { + this.saveConfiguration(); + } } private saveConnectorsStatus() { @@ -1775,24 +1789,44 @@ export class ChargingStation { Utils.cloneObject(this.getConfigurationFromFile()) ?? {}; if (this.getStationInfoPersistentConfiguration() && this.stationInfo) { configurationData.stationInfo = this.stationInfo; + } else { + delete configurationData.stationInfo; } if (this.getOcppPersistentConfiguration() && this.ocppConfiguration?.configurationKey) { configurationData.configurationKey = this.ocppConfiguration.configurationKey; + } else { + delete configurationData.configurationKey; } configurationData = merge( configurationData, buildChargingStationAutomaticTransactionGeneratorConfiguration(this) ); + if ( + !this.getAutomaticTransactionGeneratorPersistentConfiguration() || + !this.getAutomaticTransactionGeneratorConfiguration() + ) { + delete configurationData.automaticTransactionGenerator; + } if (this.connectors.size > 0) { configurationData.connectorsStatus = buildConnectorsStatus(this); + } else { + delete configurationData.connectorsStatus; } if (this.evses.size > 0) { configurationData.evsesStatus = buildEvsesStatus(this); + } else { + delete configurationData.evsesStatus; } delete configurationData.configurationHash; const configurationHash = crypto .createHash(Constants.DEFAULT_HASH_ALGORITHM) - .update(JSON.stringify(configurationData)) + .update( + JSON.stringify({ + stationInfo: configurationData.stationInfo, + configurationKey: configurationData.configurationKey, + automaticTransactionGenerator: configurationData.automaticTransactionGenerator, + } as ChargingStationConfiguration) + ) .digest('hex'); if (this.configurationFileHash !== configurationHash) { AsyncLock.acquire(AsyncLockType.configuration) @@ -1809,7 +1843,7 @@ export class ChargingStation { this.configurationFileHash = configurationHash; }) .catch((error) => { - ErrorUtils.handleFileException( + handleFileException( this.configurationFile, FileType.ChargingStationConfiguration, error as NodeJS.ErrnoException, @@ -1827,7 +1861,7 @@ export class ChargingStation { ); } } catch (error) { - ErrorUtils.handleFileException( + handleFileException( this.configurationFile, FileType.ChargingStationConfiguration, error as NodeJS.ErrnoException, @@ -1878,7 +1912,7 @@ export class ChargingStation { skipBufferingOnError: true, }); if (this.isRegistered() === false) { - this.getRegistrationMaxRetries() !== -1 && registrationRetryCount++; + this.getRegistrationMaxRetries() !== -1 && ++registrationRetryCount; await Utils.sleep( this?.bootNotificationResponse?.interval ? this.bootNotificationResponse.interval * 1000 @@ -1902,7 +1936,7 @@ export class ChargingStation { } this.wsConnectionRestarted = false; this.autoReconnectRetryCount = 0; - parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(this)); + parentPort?.postMessage(buildUpdatedMessage(this)); } else { logger.warn( `${this.logPrefix()} Connection to OCPP server through ${this.wsConnectionUrl.toString()} failed` @@ -1932,7 +1966,7 @@ export class ChargingStation { this.started === true && (await this.reconnect()); break; } - parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(this)); + parentPort?.postMessage(buildUpdatedMessage(this)); } private getCachedRequest(messageType: MessageType, messageId: string): CachedRequest | undefined { @@ -2042,7 +2076,7 @@ export class ChargingStation { logger.error(`${this.logPrefix()} ${errorMsg}`); throw new OCPPError(ErrorType.PROTOCOL_ERROR, errorMsg); } - parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(this)); + parentPort?.postMessage(buildUpdatedMessage(this)); } else { throw new OCPPError(ErrorType.PROTOCOL_ERROR, 'Incoming message is not an array', null, { request, @@ -2440,7 +2474,7 @@ export class ChargingStation { this.autoReconnectRetryCount < this.getAutoReconnectMaxRetries() || this.getAutoReconnectMaxRetries() === -1 ) { - this.autoReconnectRetryCount++; + ++this.autoReconnectRetryCount; const reconnectDelay = this.getReconnectExponentialDelay() ? Utils.exponentialDelay(this.autoReconnectRetryCount) : this.getConnectionTimeout() * 1000;