X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16RequestService.ts;h=1f8e58d5748c1db5cdf0e338ef08597b2033234f;hb=1c3cfd4f4074733491c8e9ceee59c044a0d0800b;hp=3ff3bdcbddd6758b4020633663928747ba95004a;hpb=85c603dabe1b0415dfa956baec73f34267093cf0;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index 3ff3bdcb..1f8e58d5 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -140,6 +140,8 @@ export default class OCPP16RequestService extends OCPPRequestService { ) as JSONSchemaType, ], ]); + this.buildRequestPayload.bind(this); + this.validatePayload.bind(this); } public async requestHandler( @@ -154,18 +156,7 @@ export default class OCPP16RequestService extends OCPPRequestService { commandName, commandParams ); - if (this.jsonSchemas.has(commandName)) { - this.validateRequestPayload( - chargingStation, - commandName, - this.jsonSchemas.get(commandName), - requestPayload - ); - } else { - logger.warn( - `${chargingStation.logPrefix()} ${moduleName}.requestHandler: No JSON schema found for command ${commandName} PDU validation` - ); - } + this.validatePayload(chargingStation, commandName, requestPayload); return (await this.sendMessage( chargingStation, Utils.generateUUID(), @@ -278,4 +269,23 @@ export default class OCPP16RequestService extends OCPPRequestService { ); } } + + private validatePayload( + chargingStation: ChargingStation, + commandName: OCPP16RequestCommand, + requestPayload: Request + ): boolean { + if (this.jsonSchemas.has(commandName)) { + return this.validateRequestPayload( + chargingStation, + commandName, + this.jsonSchemas.get(commandName), + requestPayload + ); + } + logger.warn( + `${chargingStation.logPrefix()} ${moduleName}.validatePayload: No JSON schema found for command ${commandName} PDU validation` + ); + return false; + } }