From: Jérôme Benoit Date: Mon, 7 Mar 2022 21:58:20 +0000 (+0100) Subject: Convert sendStatusNotification to OCPP message sending handler X-Git-Tag: v1.1.52~12 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=93b4a429b3cd9c37b5698b601361039c51e295d2;p=e-mobility-charging-stations-simulator.git Convert sendStatusNotification to OCPP message sending handler Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 9297b3e8..539ab309 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -28,6 +28,7 @@ import { WSError, WebSocketCloseEventStatusCode } from '../types/WebSocket'; import WebSocket, { ClientOptions, Data, OPEN, RawData } from 'ws'; import AutomaticTransactionGenerator from './AutomaticTransactionGenerator'; +import { ChargePointErrorCode } from '../types/ocpp/ChargePointErrorCode'; import { ChargePointStatus } from '../types/ocpp/ChargePointStatus'; import { ChargingProfile } from '../types/ocpp/ChargingProfile'; import ChargingStationInfo from '../types/ChargingStationInfo'; @@ -513,10 +514,11 @@ export default class ChargingStation { await this.stopMessageSequence(reason); for (const connectorId of this.connectors.keys()) { if (connectorId > 0) { - await this.ocppRequestService.sendStatusNotification( + await this.ocppRequestService.sendMessageHandler(RequestCommand.STATUS_NOTIFICATION, { connectorId, - ChargePointStatus.UNAVAILABLE - ); + status: ChargePointStatus.UNAVAILABLE, + errorCode: ChargePointErrorCode.NO_ERROR, + }); this.getConnectorStatus(connectorId).status = ChargePointStatus.UNAVAILABLE; } } @@ -1266,10 +1268,11 @@ export default class ChargingStation { this.getConnectorStatus(connectorId)?.bootStatus ) { // Send status in template at startup - await this.ocppRequestService.sendStatusNotification( + await this.ocppRequestService.sendMessageHandler(RequestCommand.STATUS_NOTIFICATION, { connectorId, - this.getConnectorStatus(connectorId).bootStatus - ); + status: this.getConnectorStatus(connectorId).bootStatus, + errorCode: ChargePointErrorCode.NO_ERROR, + }); this.getConnectorStatus(connectorId).status = this.getConnectorStatus(connectorId).bootStatus; } else if ( @@ -1278,24 +1281,27 @@ export default class ChargingStation { this.getConnectorStatus(connectorId)?.bootStatus ) { // Send status in template after reset - await this.ocppRequestService.sendStatusNotification( + await this.ocppRequestService.sendMessageHandler(RequestCommand.STATUS_NOTIFICATION, { connectorId, - this.getConnectorStatus(connectorId).bootStatus - ); + status: this.getConnectorStatus(connectorId).bootStatus, + errorCode: ChargePointErrorCode.NO_ERROR, + }); this.getConnectorStatus(connectorId).status = this.getConnectorStatus(connectorId).bootStatus; } else if (!this.stopped && this.getConnectorStatus(connectorId)?.status) { // Send previous status at template reload - await this.ocppRequestService.sendStatusNotification( + await this.ocppRequestService.sendMessageHandler(RequestCommand.STATUS_NOTIFICATION, { connectorId, - this.getConnectorStatus(connectorId).status - ); + status: this.getConnectorStatus(connectorId).status, + errorCode: ChargePointErrorCode.NO_ERROR, + }); } else { // Send default status - await this.ocppRequestService.sendStatusNotification( + await this.ocppRequestService.sendMessageHandler(RequestCommand.STATUS_NOTIFICATION, { connectorId, - ChargePointStatus.AVAILABLE - ); + status: ChargePointStatus.AVAILABLE, + errorCode: ChargePointErrorCode.NO_ERROR, + }); this.getConnectorStatus(connectorId).status = ChargePointStatus.AVAILABLE; } } diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index a7dae0c5..ed91c87a 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -43,6 +43,7 @@ import { DefaultResponse } from '../../../types/ocpp/Responses'; import { ErrorType } from '../../../types/ocpp/ErrorType'; import { IncomingRequestHandler } from '../../../types/ocpp/Requests'; import { JsonType } from '../../../types/JsonType'; +import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode'; import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus'; import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus'; import { OCPP16StandardParametersKey } from '../../../types/ocpp/1.6/Configuration'; @@ -212,9 +213,13 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer } return Constants.OCPP_RESPONSE_UNLOCK_FAILED; } - await this.chargingStation.ocppRequestService.sendStatusNotification( - connectorId, - OCPP16ChargePointStatus.AVAILABLE + await this.chargingStation.ocppRequestService.sendMessageHandler( + OCPP16RequestCommand.STATUS_NOTIFICATION, + { + connectorId, + status: OCPP16ChargePointStatus.AVAILABLE, + errorCode: OCPP16ChargePointErrorCode.NO_ERROR, + } ); this.chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.AVAILABLE; return Constants.OCPP_RESPONSE_UNLOCKED; @@ -462,9 +467,13 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer } this.chargingStation.getConnectorStatus(id).availability = commandPayload.type; if (response === Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED) { - await this.chargingStation.ocppRequestService.sendStatusNotification( - id, - chargePointStatus + await this.chargingStation.ocppRequestService.sendMessageHandler( + OCPP16RequestCommand.STATUS_NOTIFICATION, + { + connectorId: id, + status: chargePointStatus, + errorCode: OCPP16ChargePointErrorCode.NO_ERROR, + } ); this.chargingStation.getConnectorStatus(id).status = chargePointStatus; } @@ -483,9 +492,9 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer return Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED; } this.chargingStation.getConnectorStatus(connectorId).availability = commandPayload.type; - await this.chargingStation.ocppRequestService.sendStatusNotification( - connectorId, - chargePointStatus + await this.chargingStation.ocppRequestService.sendMessageHandler( + OCPP16RequestCommand.STATUS_NOTIFICATION, + { connectorId, status: chargePointStatus, errorCode: OCPP16ChargePointErrorCode.NO_ERROR } ); this.chargingStation.getConnectorStatus(connectorId).status = chargePointStatus; return Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED; @@ -498,9 +507,13 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer ): Promise { const transactionConnectorId: number = commandPayload.connectorId; if (transactionConnectorId) { - await this.chargingStation.ocppRequestService.sendStatusNotification( - transactionConnectorId, - OCPP16ChargePointStatus.PREPARING + await this.chargingStation.ocppRequestService.sendMessageHandler( + OCPP16RequestCommand.STATUS_NOTIFICATION, + { + connectorId: transactionConnectorId, + status: OCPP16ChargePointStatus.PREPARING, + errorCode: OCPP16ChargePointErrorCode.NO_ERROR, + } ); this.chargingStation.getConnectorStatus(transactionConnectorId).status = OCPP16ChargePointStatus.PREPARING; @@ -633,9 +646,13 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer this.chargingStation.getConnectorStatus(connectorId).status !== OCPP16ChargePointStatus.AVAILABLE ) { - await this.chargingStation.ocppRequestService.sendStatusNotification( - connectorId, - OCPP16ChargePointStatus.AVAILABLE + await this.chargingStation.ocppRequestService.sendMessageHandler( + OCPP16RequestCommand.STATUS_NOTIFICATION, + { + connectorId, + status: OCPP16ChargePointStatus.AVAILABLE, + errorCode: OCPP16ChargePointErrorCode.NO_ERROR, + } ); this.chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.AVAILABLE; @@ -686,9 +703,13 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer connectorId > 0 && this.chargingStation.getConnectorStatus(connectorId)?.transactionId === transactionId ) { - await this.chargingStation.ocppRequestService.sendStatusNotification( - connectorId, - OCPP16ChargePointStatus.FINISHING + await this.chargingStation.ocppRequestService.sendMessageHandler( + OCPP16RequestCommand.STATUS_NOTIFICATION, + { + connectorId, + status: OCPP16ChargePointStatus.FINISHING, + errorCode: OCPP16ChargePointErrorCode.NO_ERROR, + } ); this.chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.FINISHING; diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index e7fa7751..295447b0 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -63,19 +63,6 @@ export default class OCPP16RequestService extends OCPPRequestService { ); } - public async sendStatusNotification( - connectorId: number, - status: OCPP16ChargePointStatus, - errorCode: OCPP16ChargePointErrorCode = OCPP16ChargePointErrorCode.NO_ERROR - ): Promise { - const payload: StatusNotificationRequest = { - connectorId, - errorCode, - status, - }; - await this.sendMessage(Utils.generateUUID(), payload, OCPP16RequestCommand.STATUS_NOTIFICATION); - } - public async sendAuthorize( connectorId: number, idTag?: string @@ -263,8 +250,8 @@ export default class OCPP16RequestService extends OCPPRequestService { case OCPP16RequestCommand.STATUS_NOTIFICATION: return { connectorId: commandParams?.connectorId, - errorCode: commandParams?.errorCode, status: commandParams?.status, + errorCode: commandParams?.errorCode, } as StatusNotificationRequest; case OCPP16RequestCommand.START_TRANSACTION: return { diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 79064f1c..759f3705 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -25,6 +25,7 @@ import { MeterValuesRequest, MeterValuesResponse } from '../../../types/ocpp/1.6 import type ChargingStation from '../../ChargingStation'; import { ErrorType } from '../../../types/ocpp/ErrorType'; import { JsonType } from '../../../types/JsonType'; +import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode'; import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus'; import { OCPP16ServiceUtils } from './OCPP16ServiceUtils'; import { OCPP16StandardParametersKey } from '../../../types/ocpp/1.6/Configuration'; @@ -314,9 +315,13 @@ export default class OCPP16ResponseService extends OCPPResponseService { payload.transactionId, this.chargingStation.getConnectorStatus(connectorId).transactionBeginMeterValue )); - await this.chargingStation.ocppRequestService.sendStatusNotification( - connectorId, - OCPP16ChargePointStatus.CHARGING + await this.chargingStation.ocppRequestService.sendMessageHandler( + OCPP16RequestCommand.STATUS_NOTIFICATION, + { + connectorId, + status: OCPP16ChargePointStatus.CHARGING, + errorCode: OCPP16ChargePointErrorCode.NO_ERROR, + } ); this.chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.CHARGING; @@ -363,9 +368,13 @@ export default class OCPP16ResponseService extends OCPPResponseService { this.chargingStation.getConnectorStatus(connectorId).status !== OCPP16ChargePointStatus.AVAILABLE ) { - await this.chargingStation.ocppRequestService.sendStatusNotification( - connectorId, - OCPP16ChargePointStatus.AVAILABLE + await this.chargingStation.ocppRequestService.sendMessageHandler( + OCPP16RequestCommand.STATUS_NOTIFICATION, + { + connectorId, + status: OCPP16ChargePointStatus.AVAILABLE, + errorCode: OCPP16ChargePointErrorCode.NO_ERROR, + } ); this.chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.AVAILABLE; @@ -412,16 +421,24 @@ export default class OCPP16ResponseService extends OCPPResponseService { !this.chargingStation.isChargingStationAvailable() || !this.chargingStation.isConnectorAvailable(transactionConnectorId) ) { - await this.chargingStation.ocppRequestService.sendStatusNotification( - transactionConnectorId, - OCPP16ChargePointStatus.UNAVAILABLE + await this.chargingStation.ocppRequestService.sendMessageHandler( + OCPP16RequestCommand.STATUS_NOTIFICATION, + { + connectorId: transactionConnectorId, + status: OCPP16ChargePointStatus.UNAVAILABLE, + errorCode: OCPP16ChargePointErrorCode.NO_ERROR, + } ); this.chargingStation.getConnectorStatus(transactionConnectorId).status = OCPP16ChargePointStatus.UNAVAILABLE; } else { - await this.chargingStation.ocppRequestService.sendStatusNotification( - transactionConnectorId, - OCPP16ChargePointStatus.AVAILABLE + await this.chargingStation.ocppRequestService.sendMessageHandler( + OCPP16RequestCommand.STATUS_NOTIFICATION, + { + connectorId: transactionConnectorId, + status: OCPP16ChargePointStatus.AVAILABLE, + errorCode: OCPP16ChargePointErrorCode.NO_ERROR, + } ); this.chargingStation.getConnectorStatus(transactionConnectorId).status = OCPP16ChargePointStatus.AVAILABLE; diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 73fc4bf1..41e7a6ea 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -333,12 +333,6 @@ export default abstract class OCPPRequestService { params?: SendParams ): Promise; - public abstract sendStatusNotification( - connectorId: number, - status: ChargePointStatus, - errorCode?: ChargePointErrorCode - ): Promise; - public abstract sendAuthorize(connectorId: number, idTag?: string): Promise; public abstract sendStartTransaction( connectorId: number,