From 77b95a89411dcee5df14a283f05f6d6020db08ef Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 16 Nov 2022 21:52:43 +0100 Subject: [PATCH] Add DataTransfer support for incoming request MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Ref #36 Signed-off-by: Jérôme Benoit --- .../ocpp/1.6/OCPP16IncomingRequestService.ts | 42 ++++++++++++++++++- src/types/ocpp/1.6/Requests.ts | 3 ++ src/utils/Constants.ts | 5 +++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index dd1018a0..ebec27d2 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -31,6 +31,8 @@ import { OCPP16AvailabilityType, OCPP16BootNotificationRequest, OCPP16ClearCacheRequest, + OCPP16DataTransferRequest, + OCPP16DataTransferVendorId, OCPP16HeartbeatRequest, OCPP16IncomingRequestCommand, OCPP16MessageTrigger, @@ -43,7 +45,7 @@ import { SetChargingProfileRequest, UnlockConnectorRequest, } from '../../../types/ocpp/1.6/Requests'; -import type { +import { ChangeAvailabilityResponse, ChangeConfigurationResponse, ClearChargingProfileResponse, @@ -51,6 +53,8 @@ import type { GetConfigurationResponse, GetDiagnosticsResponse, OCPP16BootNotificationResponse, + OCPP16DataTransferResponse, + OCPP16DataTransferStatus, OCPP16HeartbeatResponse, OCPP16StatusNotificationResponse, OCPP16TriggerMessageResponse, @@ -123,6 +127,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer ], [OCPP16IncomingRequestCommand.GET_DIAGNOSTICS, this.handleRequestGetDiagnostics.bind(this)], [OCPP16IncomingRequestCommand.TRIGGER_MESSAGE, this.handleRequestTriggerMessage.bind(this)], + [OCPP16IncomingRequestCommand.DATA_TRANSFER, this.handleRequestDataTransfer.bind(this)], ]); this.jsonSchemas = new Map>([ [ @@ -269,6 +274,18 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer ) ) as JSONSchemaType, ], + [ + OCPP16IncomingRequestCommand.DATA_TRANSFER, + JSON.parse( + fs.readFileSync( + path.resolve( + path.dirname(fileURLToPath(import.meta.url)), + '../../../assets/json-schemas/ocpp/1.6/DataTransfer.json' + ), + 'utf8' + ) + ) as JSONSchemaType, + ], ]); this.validatePayload.bind(this); } @@ -1226,4 +1243,27 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer ); } } + + private handleRequestDataTransfer( + chargingStation: ChargingStation, + commandPayload: OCPP16DataTransferRequest + ): OCPP16DataTransferResponse { + try { + if (Object.values(OCPP16DataTransferVendorId).includes(commandPayload.vendorId)) { + return { + status: OCPP16DataTransferStatus.ACCEPTED, + }; + } + return { + status: OCPP16DataTransferStatus.UNKNOWN_VENDOR_ID, + }; + } catch (error) { + return this.handleIncomingRequestError( + chargingStation, + OCPP16IncomingRequestCommand.DATA_TRANSFER, + error as Error, + { errorResponse: Constants.OCPP_DATA_TRANSFER_RESPONSE_REJECTED } + ); + } + } } diff --git a/src/types/ocpp/1.6/Requests.ts b/src/types/ocpp/1.6/Requests.ts index cf810704..4a90569d 100644 --- a/src/types/ocpp/1.6/Requests.ts +++ b/src/types/ocpp/1.6/Requests.ts @@ -55,6 +55,7 @@ export enum OCPP16IncomingRequestCommand { REMOTE_STOP_TRANSACTION = 'RemoteStopTransaction', GET_DIAGNOSTICS = 'GetDiagnostics', TRIGGER_MESSAGE = 'TriggerMessage', + DATA_TRANSFER = 'DataTransfer', } export type OCPP16ClearCacheRequest = EmptyObject; @@ -139,6 +140,8 @@ export interface OCPP16TriggerMessageRequest extends JsonObject { connectorId?: number; } +export enum OCPP16DataTransferVendorId {} + export interface OCPP16DataTransferRequest extends JsonObject { vendorId: string; messageId?: string; diff --git a/src/utils/Constants.ts b/src/utils/Constants.ts index bfb4fbf3..74b88834 100644 --- a/src/utils/Constants.ts +++ b/src/utils/Constants.ts @@ -4,6 +4,7 @@ import { ChargingProfileStatus, ClearChargingProfileStatus, ConfigurationStatus, + DataTransferStatus, DefaultStatus, TriggerMessageStatus, UnlockStatus, @@ -82,6 +83,10 @@ export default class Constants { status: TriggerMessageStatus.NOT_IMPLEMENTED, }); + static readonly OCPP_DATA_TRANSFER_RESPONSE_REJECTED = Object.freeze({ + status: DataTransferStatus.REJECTED, + }); + static readonly OCPP_DEFAULT_BOOT_NOTIFICATION_INTERVAL = 60000; // Ms static readonly OCPP_WEBSOCKET_TIMEOUT = 60000; // Ms static readonly OCPP_TRIGGER_MESSAGE_DELAY = 500; // Ms -- 2.34.1