From a9ed42b2eaac1fb26700d6d86952d0d2cee4d857 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 5 Sep 2022 00:44:53 +0200 Subject: [PATCH] UI Services: add status notification command MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- README.md | 20 +++++++++++- .../ChargingStationWorkerBroadcastChannel.ts | 31 +++++++++++++++++-- .../ui-server/ui-services/UIService001.ts | 12 +++++++ src/types/UIProtocol.ts | 1 + src/types/WorkerBroadcastChannel.ts | 4 ++- src/types/ocpp/1.6/Requests.ts | 2 +- 6 files changed, 64 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d8053802..f03560df 100644 --- a/README.md +++ b/README.md @@ -459,7 +459,8 @@ Set the Websocket header _Sec-Websocket-Protocol_ to `ui0.0.1`. `PDU`: { `status`: 'success' | 'failure', `hashIdsSucceeded`: charging station unique identifier strings array, - `hashIdsFailed`: charging station unique identifier strings array (optional) + `hashIdsFailed`: charging station unique identifier strings array (optional), + `responsesFailed`: failed responses payload array (optional) } ###### Stop Transaction @@ -570,6 +571,23 @@ Set the Websocket header _Sec-Websocket-Protocol_ to `ui0.0.1`. `hashIdsFailed`: charging station unique identifier strings array (optional) } +###### Stop Automatic Transaction Generator + +- Request: + `ProcedureName`: 'StatusNotification' + `PDU`: { + `hashIds`: charging station unique identifier strings array (optional, default: all charging stations), + `connectorId`: connector id integer + } + +- Response: + `PDU`: { + `status`: 'success' | 'failure', + `hashIdsSucceeded`: charging station unique identifier strings array, + `hashIdsFailed`: charging station unique identifier strings array (optional) + `responsesFailed`: failed responses payload array (optional) + } + ## Support, Feedback, Contributing This project is open to feature requests/suggestions, bug reports etc. via [GitHub issues](https://github.com/SAP/e-mobility-charging-stations-simulator/issues). Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our [Contribution Guidelines](CONTRIBUTING.md). diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index a31d9779..ebc10099 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -1,5 +1,7 @@ import BaseError from '../exception/BaseError'; -import { RequestCommand } from '../types/ocpp/Requests'; +import type OCPPError from '../exception/OCPPError'; +import { RequestCommand, type StatusNotificationRequest } from '../types/ocpp/Requests'; +import type { StatusNotificationResponse } from '../types/ocpp/Responses'; import { AuthorizationStatus, StartTransactionRequest, @@ -16,12 +18,16 @@ import { } from '../types/WorkerBroadcastChannel'; import { ResponseStatus } from '../ui/web/src/types/UIProtocol'; import logger from '../utils/Logger'; +import Utils from '../utils/Utils'; import type ChargingStation from './ChargingStation'; import WorkerBroadcastChannel from './WorkerBroadcastChannel'; const moduleName = 'ChargingStationWorkerBroadcastChannel'; -type CommandResponse = StartTransactionResponse | StopTransactionResponse; +type CommandResponse = + | StartTransactionResponse + | StopTransactionResponse + | StatusNotificationResponse; export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadcastChannel { private readonly chargingStation: ChargingStation; @@ -88,6 +94,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca commandResponse, errorMessage: (error as Error).message, errorStack: (error as Error).stack, + errorDetails: (error as OCPPError).details, }; } this.sendResponse([uuid, responsePayload]); @@ -144,6 +151,21 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca case BroadcastChannelProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR: this.chargingStation.stopAutomaticTransactionGenerator(requestPayload.connectorIds); break; + case BroadcastChannelProcedureName.STATUS_NOTIFICATION: + return this.chargingStation.ocppRequestService.requestHandler< + StatusNotificationRequest, + StatusNotificationResponse + >(this.chargingStation, RequestCommand.STATUS_NOTIFICATION, { + connectorId: requestPayload.connectorId, + errorCode: requestPayload.errorCode, + status: requestPayload.status, + ...(requestPayload.info && { info: requestPayload.info }), + ...(requestPayload.timestamp && { timestamp: requestPayload.timestamp }), + ...(requestPayload.vendorId && { vendorId: requestPayload.vendorId }), + ...(requestPayload.vendorErrorCode && { + vendorErrorCode: requestPayload.vendorErrorCode, + }), + }); default: // eslint-disable-next-line @typescript-eslint/restrict-template-expressions throw new BaseError(`Unknown worker broadcast channel command: ${command}`); @@ -151,7 +173,10 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca } private commandResponseToResponseStatus(commandResponse: CommandResponse): ResponseStatus { - if (commandResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) { + if ( + Utils.isEmptyObject(commandResponse) || + commandResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED + ) { return ResponseStatus.SUCCESS; } return ResponseStatus.FAILURE; diff --git a/src/charging-station/ui-server/ui-services/UIService001.ts b/src/charging-station/ui-server/ui-services/UIService001.ts index 4740b7d7..74403cea 100644 --- a/src/charging-station/ui-server/ui-services/UIService001.ts +++ b/src/charging-station/ui-server/ui-services/UIService001.ts @@ -43,6 +43,10 @@ export default class UIService001 extends AbstractUIService { ProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR, this.handleStopAutomaticTransactionGenerator.bind(this) as ProtocolRequestHandler ); + this.requestHandlers.set( + ProcedureName.STATUS_NOTIFICATION, + this.handleStatusNotification.bind(this) as ProtocolRequestHandler + ); } private handleStartChargingStation(uuid: string, payload: RequestPayload): void { @@ -96,4 +100,12 @@ export default class UIService001 extends AbstractUIService { payload ); } + + private handleStatusNotification(uuid: string, payload: RequestPayload): void { + this.sendBroadcastChannelRequest( + uuid, + BroadcastChannelProcedureName.STATUS_NOTIFICATION, + payload + ); + } } diff --git a/src/types/UIProtocol.ts b/src/types/UIProtocol.ts index 0e4fb77a..d995e096 100644 --- a/src/types/UIProtocol.ts +++ b/src/types/UIProtocol.ts @@ -38,6 +38,7 @@ export enum ProcedureName { STOP_TRANSACTION = 'stopTransaction', START_AUTOMATIC_TRANSACTION_GENERATOR = 'startAutomaticTransactionGenerator', STOP_AUTOMATIC_TRANSACTION_GENERATOR = 'stopAutomaticTransactionGenerator', + STATUS_NOTIFICATION = 'statusNotification', } export interface RequestPayload extends JsonObject { diff --git a/src/types/WorkerBroadcastChannel.ts b/src/types/WorkerBroadcastChannel.ts index ca3d4270..f235200c 100644 --- a/src/types/WorkerBroadcastChannel.ts +++ b/src/types/WorkerBroadcastChannel.ts @@ -16,6 +16,7 @@ export enum BroadcastChannelProcedureName { STOP_TRANSACTION = 'stopTransaction', START_AUTOMATIC_TRANSACTION_GENERATOR = 'startAutomaticTransactionGenerator', STOP_AUTOMATIC_TRANSACTION_GENERATOR = 'stopAutomaticTransactionGenerator', + STATUS_NOTIFICATION = 'statusNotification', } export interface BroadcastChannelRequestPayload extends RequestPayload { @@ -24,7 +25,8 @@ export interface BroadcastChannelRequestPayload extends RequestPayload { idTag?: string; } -export interface BroadcastChannelResponsePayload extends ResponsePayload { +export interface BroadcastChannelResponsePayload + extends Omit { hashId: string; } diff --git a/src/types/ocpp/1.6/Requests.ts b/src/types/ocpp/1.6/Requests.ts index db0c7edd..263947c2 100644 --- a/src/types/ocpp/1.6/Requests.ts +++ b/src/types/ocpp/1.6/Requests.ts @@ -34,8 +34,8 @@ export interface OCPP16BootNotificationRequest extends JsonObject { export interface OCPP16StatusNotificationRequest extends JsonObject { connectorId: number; errorCode: OCPP16ChargePointErrorCode; - info?: string; status: OCPP16ChargePointStatus; + info?: string; timestamp?: string; vendorId?: string; vendorErrorCode?: string; -- 2.34.1