From bad85ee42a1c6a12be50560e535331dadff453b4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 8 Mar 2022 12:37:53 +0100 Subject: [PATCH] Convert sendDiagnosticsStatusNotification to OCPP message sending handler 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 | 28 +++++++++++++------ .../ocpp/1.6/OCPP16RequestService.ts | 15 +--------- .../ocpp/OCPPRequestService.ts | 5 ---- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index a86e995e..bd998504 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -829,8 +829,11 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer info.bytes / 1024 } bytes transferred from diagnostics archive ${info.name}` ); - await this.chargingStation.ocppRequestService.sendDiagnosticsStatusNotification( - OCPP16DiagnosticsStatus.Uploading + await this.chargingStation.ocppRequestService.sendMessageHandler( + OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, + { + status: OCPP16DiagnosticsStatus.Uploading, + } ); }); uploadResponse = await ftpClient.uploadFrom( @@ -838,8 +841,11 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer uri.pathname + diagnosticsArchive ); if (uploadResponse.code === 226) { - await this.chargingStation.ocppRequestService.sendDiagnosticsStatusNotification( - OCPP16DiagnosticsStatus.Uploaded + await this.chargingStation.ocppRequestService.sendMessageHandler( + OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, + { + status: OCPP16DiagnosticsStatus.Uploaded, + } ); if (ftpClient) { ftpClient.close(); @@ -862,8 +868,11 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer OCPP16IncomingRequestCommand.GET_DIAGNOSTICS ); } catch (error) { - await this.chargingStation.ocppRequestService.sendDiagnosticsStatusNotification( - OCPP16DiagnosticsStatus.UploadFailed + await this.chargingStation.ocppRequestService.sendMessageHandler( + OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, + { + status: OCPP16DiagnosticsStatus.UploadFailed, + } ); if (ftpClient) { ftpClient.close(); @@ -880,8 +889,11 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer uri.protocol } to transfer the diagnostic logs archive` ); - await this.chargingStation.ocppRequestService.sendDiagnosticsStatusNotification( - OCPP16DiagnosticsStatus.UploadFailed + await this.chargingStation.ocppRequestService.sendMessageHandler( + OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, + { + status: OCPP16DiagnosticsStatus.UploadFailed, + } ); return Constants.OCPP_RESPONSE_EMPTY; } diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index 8ba3c086..f184c7ab 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -12,13 +12,13 @@ import { OCPP16RequestCommand, StatusNotificationRequest, } from '../../../types/ocpp/1.6/Requests'; -import { MeterValuesRequest, OCPP16MeterValue } from '../../../types/ocpp/1.6/MeterValues'; import { ResponseType, SendParams } from '../../../types/ocpp/Requests'; import type ChargingStation from '../../ChargingStation'; import Constants from '../../../utils/Constants'; import { ErrorType } from '../../../types/ocpp/ErrorType'; import { JsonType } from '../../../types/JsonType'; +import { MeterValuesRequest } from '../../../types/ocpp/1.6/MeterValues'; import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus'; import { OCPP16ServiceUtils } from './OCPP16ServiceUtils'; import OCPPError from '../../../exception/OCPPError'; @@ -57,19 +57,6 @@ export default class OCPP16RequestService extends OCPPRequestService { ); } - public async sendDiagnosticsStatusNotification( - diagnosticsStatus: OCPP16DiagnosticsStatus - ): Promise { - const payload: DiagnosticsStatusNotificationRequest = { - status: diagnosticsStatus, - }; - await this.sendMessage( - Utils.generateUUID(), - payload, - OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION - ); - } - private buildCommandPayload( commandName: OCPP16RequestCommand, commandParams?: JsonType diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 1430de07..e5047d33 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -13,7 +13,6 @@ import { ErrorType } from '../../types/ocpp/ErrorType'; import { HandleErrorParams } from '../../types/Error'; import { JsonType } from '../../types/JsonType'; import { MessageType } from '../../types/ocpp/MessageType'; -import { MeterValue } from '../../types/ocpp/MeterValues'; import OCPPError from '../../exception/OCPPError'; import type OCPPResponseService from './OCPPResponseService'; import PerformanceStatistics from '../../performance/PerformanceStatistics'; @@ -323,8 +322,4 @@ export default abstract class OCPPRequestService { commandParams?: JsonType, params?: SendParams ): Promise; - - public abstract sendDiagnosticsStatusNotification( - diagnosticsStatus: DiagnosticsStatus - ): Promise; } -- 2.34.1