From: Jérôme Benoit Date: Mon, 9 Jan 2023 12:42:49 +0000 (+0100) Subject: Bump patch level is firmware version at reboot at firmware update X-Git-Tag: v1.1.89~4 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3637ca2c3a39b1185de71fae3577679a7e43891d;p=e-mobility-charging-stations-simulator.git Bump patch level is firmware version at reboot at firmware update Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 8d7907ba..84aa81ca 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -825,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); @@ -862,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; @@ -1000,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 { @@ -1846,8 +1855,8 @@ export default class ChargingStation { status: FirmwareStatus.Installed, }); this.stationInfo.firmwareStatus = FirmwareStatus.Installed; - // TODO: bump firmware version } + // Start the ATG if (this.getAutomaticTransactionGeneratorConfigurationFromTemplate()?.enable === true) { this.startAutomaticTransactionGenerator(); diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index e0ba24d4..0df0954f 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -1082,6 +1082,8 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer status: OCPP16ChargePointStatus.UNAVAILABLE, errorCode: OCPP16ChargePointErrorCode.NO_ERROR, }); + chargingStation.getConnectorStatus(connectorId).status = + OCPP16ChargePointStatus.UNAVAILABLE; } } await chargingStation.ocppRequestService.requestHandler< diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index fb9e2004..c7e767eb 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -10,8 +10,8 @@ export default class Constants { static readonly CHARGING_STATION_ATG_DEFAULT_STOP_AFTER_HOURS = 0.25; // Hours // See https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string - static readonly SEMVER_REGEXP = - /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/; + static readonly SEMVER_PATTERN = + '^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$'; static readonly DEFAULT_CIRCULAR_BUFFER_CAPACITY = Number.MAX_SAFE_INTEGER;