From 90293abb1042312652c22f8b8c468d99ec080c71 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 11 Jan 2023 20:57:12 +0100 Subject: [PATCH] Fix firmware update OCPP command handling and simulation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index b80a8f4b..6f089a70 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -945,7 +945,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer ) === false ) { logger.warn( - `${chargingStation.logPrefix()} Cannot simulate firmware update: feature profile not supported` + `${chargingStation.logPrefix()} ${moduleName}.handleRequestUpdateFirmware: Cannot simulate firmware update: feature profile not supported` ); return OCPPConstants.OCPP_RESPONSE_EMPTY; } @@ -954,7 +954,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer chargingStation.stationInfo.firmwareStatus !== OCPP16FirmwareStatus.Installed ) { logger.warn( - `${chargingStation.logPrefix()} Cannot simulate firmware update: firmware update is already in progress` + `${chargingStation.logPrefix()} ${moduleName}.handleRequestUpdateFirmware: Cannot simulate firmware update: firmware update is already in progress` ); return OCPPConstants.OCPP_RESPONSE_EMPTY; } @@ -984,8 +984,8 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer private async updateFirmware( chargingStation: ChargingStation, - minDelay = 15, - maxDelay = 30 + maxDelay = 30, + minDelay = 15 ): Promise { chargingStation.stopAutomaticTransactionGenerator(); for (const connectorId of chargingStation.connectors.keys()) { @@ -1024,7 +1024,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer status: OCPP16FirmwareStatus.Downloading, }); chargingStation.stationInfo.firmwareStatus = OCPP16FirmwareStatus.Downloading; - await Utils.sleep(Utils.getRandomInteger(minDelay, maxDelay) * 1000); + await Utils.sleep(Utils.getRandomInteger(maxDelay, minDelay) * 1000); await chargingStation.ocppRequestService.requestHandler< OCPP16FirmwareStatusNotificationRequest, OCPP16FirmwareStatusNotificationResponse @@ -1032,7 +1032,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer status: OCPP16FirmwareStatus.Downloaded, }); chargingStation.stationInfo.firmwareStatus = OCPP16FirmwareStatus.Downloaded; - await Utils.sleep(Utils.getRandomInteger(minDelay, maxDelay) * 1000); + await Utils.sleep(Utils.getRandomInteger(maxDelay, minDelay) * 1000); await chargingStation.ocppRequestService.requestHandler< OCPP16FirmwareStatusNotificationRequest, OCPP16FirmwareStatusNotificationResponse @@ -1041,7 +1041,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer }); chargingStation.stationInfo.firmwareStatus = OCPP16FirmwareStatus.Installing; if (chargingStation.getFirmwareUpgrade().reset === true) { - await Utils.sleep(Utils.getRandomInteger(minDelay, maxDelay) * 1000); + await Utils.sleep(Utils.getRandomInteger(maxDelay, minDelay) * 1000); await chargingStation.reset(OCPP16StopTransactionReason.REBOOT); } } @@ -1057,6 +1057,9 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer OCPP16IncomingRequestCommand.GET_DIAGNOSTICS ) === false ) { + logger.warn( + `${chargingStation.logPrefix()} ${moduleName}.handleRequestGetDiagnostics: Cannot get diagnostics: feature profile not supported` + ); return OCPPConstants.OCPP_RESPONSE_EMPTY; } const uri = new URL(commandPayload.location); -- 2.34.1