X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStation.ts;h=84aa81ca649336eda64779744c87600ac5d9a098;hb=81533a206ec56709897f27edf1298e7c86d74c31;hp=587ca02ff143d391c222b07ca11a9f81fdf7cb70;hpb=4598878063d62259a6046a870dfa455b9d0027ca;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 587ca02f..84aa81ca 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -43,6 +43,8 @@ import { type BootNotificationRequest, type CachedRequest, type ErrorCallback, + FirmwareStatus, + type FirmwareStatusNotificationRequest, type HeartbeatRequest, type IncomingRequest, IncomingRequestCommand, @@ -54,6 +56,7 @@ import { import { type BootNotificationResponse, type ErrorResponse, + type FirmwareStatusNotificationResponse, type HeartbeatResponse, type MeterValuesResponse, RegistrationStatusEnumType, @@ -170,17 +173,15 @@ export default class ChargingStation { ); } - public getEnableStatistics(): boolean | undefined { - return !Utils.isUndefined(this.stationInfo.enableStatistics) - ? this.stationInfo.enableStatistics - : true; + public getEnableStatistics(): boolean { + return this.stationInfo.enableStatistics ?? false; } - public getMustAuthorizeAtRemoteStart(): boolean | undefined { + public getMustAuthorizeAtRemoteStart(): boolean { return this.stationInfo.mustAuthorizeAtRemoteStart ?? true; } - public getPayloadSchemaValidation(): boolean | undefined { + public getPayloadSchemaValidation(): boolean { return this.stationInfo.payloadSchemaValidation ?? true; } @@ -484,7 +485,7 @@ export default class ChargingStation { if (this.started === false) { if (this.starting === false) { this.starting = true; - if (this.getEnableStatistics()) { + if (this.getEnableStatistics() === true) { this.performanceStatistics.start(); } this.openWSConnection(); @@ -512,7 +513,7 @@ export default class ChargingStation { ) { this.startAutomaticTransactionGenerator(); } - if (this.getEnableStatistics()) { + if (this.getEnableStatistics() === true) { this.performanceStatistics.restart(); } else { this.performanceStatistics.stop(); @@ -544,7 +545,7 @@ export default class ChargingStation { this.stopping = true; await this.stopMessageSequence(reason); this.closeWSConnection(); - if (this.getEnableStatistics()) { + if (this.getEnableStatistics() === true) { this.performanceStatistics.stop(); } this.sharedLRUCache.deleteChargingStationConfiguration(this.configurationFileHash); @@ -824,21 +825,6 @@ export default class ChargingStation { 'supervisionUrl', 'supervisionUrls' ); - const firmwareVersionRegExp = stationTemplate.firmwareVersionPattern - ? new RegExp(stationTemplate.firmwareVersionPattern) - : Constants.SEMVER_REGEXP; - if ( - stationTemplate.firmwareVersion && - firmwareVersionRegExp.test(stationTemplate.firmwareVersion) === false - ) { - logger.warn( - `${this.logPrefix()} Firmware version '${ - stationTemplate.firmwareVersion - }' in template file ${ - this.templateFile - } does not match regular expression '${firmwareVersionRegExp.toString()}'` - ); - } const stationInfo: ChargingStationInfo = ChargingStationUtils.stationTemplateToStationInfo(stationTemplate); stationInfo.hashId = ChargingStationUtils.getHashId(this.index, stationTemplate); @@ -861,6 +847,18 @@ export default class ChargingStation { ? stationTemplate.power * 1000 : stationTemplate.power; } + stationInfo.firmwareVersionPattern = + stationTemplate.firmwareVersionPattern ?? Constants.SEMVER_PATTERN; + if ( + stationInfo.firmwareVersion && + new RegExp(stationInfo.firmwareVersionPattern).test(stationInfo.firmwareVersion) === false + ) { + logger.warn( + `${this.logPrefix()} Firmware version '${stationInfo.firmwareVersion}' in template file ${ + this.templateFile + } does not match firmware version pattern '${stationInfo.firmwareVersionPattern}'` + ); + } stationInfo.resetTime = stationTemplate.resetTime ? stationTemplate.resetTime * 1000 : Constants.CHARGING_STATION_DEFAULT_RESET_TIME; @@ -958,7 +956,7 @@ export default class ChargingStation { // Avoid duplication of connectors related information in RAM this.stationInfo?.Connectors && delete this.stationInfo.Connectors; this.configuredSupervisionUrl = this.getConfiguredSupervisionUrl(); - if (this.getEnableStatistics()) { + if (this.getEnableStatistics() === true) { this.performanceStatistics = PerformanceStatistics.getInstance( this.stationInfo.hashId, this.stationInfo.chargingStationId, @@ -999,6 +997,18 @@ export default class ChargingStation { status: RegistrationStatusEnumType.ACCEPTED, }; } + if ( + this.stationInfo.firmwareStatus === FirmwareStatus.Installing && + this.stationInfo.firmwareVersion && + this.stationInfo.firmwareVersionPattern + ) { + const match = this.stationInfo.firmwareVersion + .match(new RegExp(this.stationInfo.firmwareVersionPattern)) + .slice(1, this.stationInfo.firmwareVersion.split('.').length + 1); + const patchLevelIndex = match.length - 1; + match[patchLevelIndex] = (Utils.convertToInt(match[patchLevelIndex]) + 1).toString(); + this.stationInfo.firmwareVersion = match.join('.'); + } } private initializeOcppConfiguration(): void { @@ -1837,6 +1847,16 @@ export default class ChargingStation { }); this.getConnectorStatus(connectorId).status = chargePointStatus; } + if (this.stationInfo?.firmwareStatus === FirmwareStatus.Installing) { + await this.ocppRequestService.requestHandler< + FirmwareStatusNotificationRequest, + FirmwareStatusNotificationResponse + >(this, RequestCommand.FIRMWARE_STATUS_NOTIFICATION, { + status: FirmwareStatus.Installed, + }); + this.stationInfo.firmwareStatus = FirmwareStatus.Installed; + } + // Start the ATG if (this.getAutomaticTransactionGeneratorConfigurationFromTemplate()?.enable === true) { this.startAutomaticTransactionGenerator();