From: Jérôme Benoit Date: Mon, 9 Jan 2023 21:46:56 +0000 (+0100) Subject: Add Hearbeat command to OCPP 2.0.1 X-Git-Tag: v1.1.90~30 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=81533a206ec56709897f27edf1298e7c86d74c31;p=e-mobility-charging-stations-simulator.git Add Hearbeat command to OCPP 2.0.1 Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts index ed4f1fe1..08fa5d2e 100644 --- a/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts @@ -9,7 +9,7 @@ import type { JSONSchemaType } from 'ajv'; import OCPPError from '../../../exception/OCPPError'; import type { JsonObject, JsonType } from '../../../types/JsonType'; import { - OCPP20ClearCacheRequest, + type OCPP20ClearCacheRequest, OCPP20IncomingRequestCommand, } from '../../../types/ocpp/2.0/Requests'; import { ErrorType } from '../../../types/ocpp/ErrorType'; @@ -60,9 +60,9 @@ export default class OCPP20IncomingRequestService extends OCPPIncomingRequestSer let response: JsonType; if ( chargingStation.getOcppStrictCompliance() === true && - chargingStation.isInPendingState() === true /* && - (commandName === OCPP20IncomingRequestCommand.REMOTE_START_TRANSACTION || - commandName === OCPP20IncomingRequestCommand.REMOTE_STOP_TRANSACTION ) */ + chargingStation.isInPendingState() === true && + (commandName === OCPP20IncomingRequestCommand.REQUEST_START_TRANSACTION || + commandName === OCPP20IncomingRequestCommand.REQUEST_STOP_TRANSACTION) ) { throw new OCPPError( ErrorType.SECURITY_ERROR, diff --git a/src/charging-station/ocpp/2.0/OCPP20RequestService.ts b/src/charging-station/ocpp/2.0/OCPP20RequestService.ts index bc056bef..3e54ca50 100644 --- a/src/charging-station/ocpp/2.0/OCPP20RequestService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20RequestService.ts @@ -10,6 +10,7 @@ import OCPPError from '../../../exception/OCPPError'; import type { JsonObject, JsonType } from '../../../types/JsonType'; import { type OCPP20BootNotificationRequest, + type OCPP20HeartbeatRequest, OCPP20RequestCommand, } from '../../../types/ocpp/2.0/Requests'; import { ErrorType } from '../../../types/ocpp/ErrorType'; @@ -44,6 +45,18 @@ export default class OCPP20RequestService extends OCPPRequestService { ) ) as JSONSchemaType, ], + [ + OCPP20RequestCommand.HEARTBEAT, + JSON.parse( + fs.readFileSync( + path.resolve( + path.dirname(fileURLToPath(import.meta.url)), + '../../../assets/json-schemas/ocpp/2.0/HeartbeatRequest.json' + ), + 'utf8' + ) + ) as JSONSchemaType, + ], ]); this.buildRequestPayload.bind(this); } @@ -110,6 +123,8 @@ export default class OCPP20RequestService extends OCPPRequestService { }), }, } as unknown as Request; + case OCPP20RequestCommand.HEARTBEAT: + return {} as unknown as Request; default: // OCPPError usage here is debatable: it's an error in the OCPP stack but not targeted to sendError(). throw new OCPPError( diff --git a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts index ef83ad43..15b355a5 100644 --- a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts @@ -15,6 +15,7 @@ import { import type { OCPP20BootNotificationResponse, OCPP20ClearCacheResponse, + OCPP20HeartbeatResponse, } from '../../../types/ocpp/2.0/Responses'; import { ErrorType } from '../../../types/ocpp/ErrorType'; import { OCPPVersion } from '../../../types/ocpp/OCPPVersion'; @@ -42,6 +43,7 @@ export default class OCPP20ResponseService extends OCPPResponseService { super(OCPPVersion.VERSION_20); this.responseHandlers = new Map([ [OCPP20RequestCommand.BOOT_NOTIFICATION, this.handleResponseBootNotification.bind(this)], + [OCPP20RequestCommand.HEARTBEAT, this.emptyResponseHandler.bind(this)], ]); this.jsonSchemas = new Map>([ [ @@ -56,6 +58,18 @@ export default class OCPP20ResponseService extends OCPPResponseService { ) ) as JSONSchemaType, ], + [ + OCPP20RequestCommand.HEARTBEAT, + JSON.parse( + fs.readFileSync( + path.resolve( + path.dirname(fileURLToPath(import.meta.url)), + '../../../assets/json-schemas/ocpp/2.0/HeartbeatResponse.json' + ), + 'utf8' + ) + ) as JSONSchemaType, + ], ]); this.jsonIncomingRequestResponseSchemas = new Map([ [ diff --git a/src/types/ocpp/2.0/Requests.ts b/src/types/ocpp/2.0/Requests.ts index 00826ab2..72ad392e 100644 --- a/src/types/ocpp/2.0/Requests.ts +++ b/src/types/ocpp/2.0/Requests.ts @@ -8,6 +8,8 @@ export enum OCPP20RequestCommand { export enum OCPP20IncomingRequestCommand { CLEAR_CACHE = 'ClearCache', + REQUEST_START_TRANSACTION = 'RequestStartTransaction', + REQUEST_STOP_TRANSACTION = 'RequestStopTransaction', } export enum BootReasonEnumType { @@ -40,4 +42,6 @@ export type OCPP20BootNotificationRequest = { chargingStation: ChargingStationType; } & JsonObject; +export type OCPP20HeartbeatRequest = EmptyObject; + export type OCPP20ClearCacheRequest = EmptyObject; diff --git a/src/types/ocpp/2.0/Responses.ts b/src/types/ocpp/2.0/Responses.ts index 8fdfe89b..b83f0c84 100644 --- a/src/types/ocpp/2.0/Responses.ts +++ b/src/types/ocpp/2.0/Responses.ts @@ -13,6 +13,10 @@ export type OCPP20BootNotificationResponse = { statusInfo?: StatusInfoType; } & JsonObject; +export type OCPP20HeartbeatResponse = { + currentTime: Date; +} & JsonObject; + export type OCPP20ClearCacheResponse = { status: DefaultStatus; statusInfo?: StatusInfoType;