From: Jérôme Benoit Date: Wed, 11 Jan 2023 18:57:39 +0000 (+0100) Subject: Implement firmwareUpgrade CS template section support X-Git-Tag: v1.1.90~24 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=5d280aae12d6ad7367136421c8e2414a676d2c1a;p=e-mobility-charging-stations-simulator.git Implement firmwareUpgrade CS template section support Signed-off-by: Jérôme Benoit --- diff --git a/src/assets/station-templates/chargex.station-template.json b/src/assets/station-templates/chargex.station-template.json index 7c20df31..3f4a6be1 100644 --- a/src/assets/station-templates/chargex.station-template.json +++ b/src/assets/station-templates/chargex.station-template.json @@ -11,6 +11,11 @@ "voltageOut": 230, "beginEndMeterValues": true, "outOfOrderEndMeterValues": true, + "firmwareUpgrade": { + "versionUpgrade": { + "patternGroup": 3 + } + }, "commandsSupport": { "incomingCommands": { "Reset": true, diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 7e324b25..a7a41ddd 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -6,6 +6,7 @@ import path from 'path'; import { URL } from 'url'; import { parentPort } from 'worker_threads'; +import merge from 'just-merge'; import WebSocket, { type RawData } from 'ws'; import BaseError from '../exception/BaseError'; @@ -18,6 +19,7 @@ import type { ChargingStationOcppConfiguration } from '../types/ChargingStationO import { type ChargingStationTemplate, CurrentType, + type FirmwareUpgrade, PowerUnits, type WsOptions, } from '../types/ChargingStationTemplate'; @@ -563,6 +565,15 @@ export default class ChargingStation { } } + public getFirmwareUpgrade(): FirmwareUpgrade { + return merge( + { + reset: true, + }, + this.stationInfo.firmwareUpgrade + ); + } + public async reset(reason?: StopTransactionReason): Promise { await this.stop(reason); await Utils.sleep(this.stationInfo.resetTime); @@ -1002,11 +1013,17 @@ export default class ChargingStation { this.stationInfo.firmwareVersion && this.stationInfo.firmwareVersionPattern ) { + const versionStep = this.getFirmwareUpgrade()?.versionUpgrade?.step ?? 1; + const patternGroup: number = + this.getFirmwareUpgrade()?.versionUpgrade?.patternGroup ?? + this.stationInfo.firmwareVersion.split('.').length; const match = this.stationInfo.firmwareVersion .match(new RegExp(this.stationInfo.firmwareVersionPattern)) - .slice(1, this.stationInfo.firmwareVersion.split('.').length + 1); + .slice(1, patternGroup + 1); const patchLevelIndex = match.length - 1; - match[patchLevelIndex] = (Utils.convertToInt(match[patchLevelIndex]) + 1).toString(); + match[patchLevelIndex] = ( + Utils.convertToInt(match[patchLevelIndex]) + versionStep + ).toString(); this.stationInfo.firmwareVersion = match.join('.'); } } diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 3f1b2cfe..b80a8f4b 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -944,6 +944,18 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer OCPP16IncomingRequestCommand.UPDATE_FIRMWARE ) === false ) { + logger.warn( + `${chargingStation.logPrefix()} Cannot simulate firmware update: feature profile not supported` + ); + return OCPPConstants.OCPP_RESPONSE_EMPTY; + } + if ( + !Utils.isNullOrUndefined(chargingStation.stationInfo.firmwareStatus) && + chargingStation.stationInfo.firmwareStatus !== OCPP16FirmwareStatus.Installed + ) { + logger.warn( + `${chargingStation.logPrefix()} Cannot simulate firmware update: firmware update is already in progress` + ); return OCPPConstants.OCPP_RESPONSE_EMPTY; } const retrieveDate = Utils.convertToDate(commandPayload.retrieveDate); @@ -993,6 +1005,18 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer OCPP16ChargePointStatus.UNAVAILABLE; } } + if ( + chargingStation.getFirmwareUpgrade()?.failureStatus && + !Utils.isEmptyString(chargingStation.getFirmwareUpgrade().failureStatus) + ) { + await chargingStation.ocppRequestService.requestHandler< + OCPP16FirmwareStatusNotificationRequest, + OCPP16FirmwareStatusNotificationResponse + >(chargingStation, OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION, { + status: chargingStation.getFirmwareUpgrade().failureStatus, + }); + return; + } await chargingStation.ocppRequestService.requestHandler< OCPP16FirmwareStatusNotificationRequest, OCPP16FirmwareStatusNotificationResponse @@ -1016,8 +1040,10 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer status: OCPP16FirmwareStatus.Installing, }); chargingStation.stationInfo.firmwareStatus = OCPP16FirmwareStatus.Installing; - await Utils.sleep(Utils.getRandomInteger(minDelay, maxDelay) * 1000); - await chargingStation.reset(OCPP16StopTransactionReason.REBOOT); + if (chargingStation.getFirmwareUpgrade().reset === true) { + await Utils.sleep(Utils.getRandomInteger(minDelay, maxDelay) * 1000); + await chargingStation.reset(OCPP16StopTransactionReason.REBOOT); + } } private async handleRequestGetDiagnostics( diff --git a/src/types/ChargingStationTemplate.ts b/src/types/ChargingStationTemplate.ts index c6640771..99b43765 100644 --- a/src/types/ChargingStationTemplate.ts +++ b/src/types/ChargingStationTemplate.ts @@ -40,14 +40,13 @@ export enum Voltage { export type WsOptions = ClientOptions & ClientRequestArgs; -type FirmwareUpgrade = { +export type FirmwareUpgrade = { versionUpgrade: { - patternGroup?: number | number[]; + patternGroup?: number; step?: number; }; reset?: boolean; - resetDelay?: number; - failureMessage?: FirmwareStatus; + failureStatus?: FirmwareStatus; }; type CommandsSupport = {