X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16RequestService.ts;h=658664092d71451b5e088bd3e3390fba6deb69c8;hb=262c47b2dbe7ad59fa523e77668dd0b994214cb2;hp=ffbc15d79f634af24399dee71e35ec941e2767e9;hpb=27782dbc3512349e7ff5e9fab9180dd31bf68ffa;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 ffbc15d7..65866409 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -1,4 +1,4 @@ -// Partial Copyright Jerome Benoit. 2021. All Rights Reserved. +// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. import fs from 'fs'; import path from 'path'; @@ -23,6 +23,7 @@ import type { OCPP16StopTransactionRequest, } from '../../../types/ocpp/1.6/Transaction'; import { ErrorType } from '../../../types/ocpp/ErrorType'; +import { OCPPVersion } from '../../../types/ocpp/OCPPVersion'; import type { RequestParams } from '../../../types/ocpp/Requests'; import Constants from '../../../utils/Constants'; import logger from '../../../utils/Logger'; @@ -41,7 +42,7 @@ export default class OCPP16RequestService extends OCPPRequestService { if (new.target?.name === moduleName) { throw new TypeError(`Cannot construct ${new.target?.name} instances directly`); } - super(ocppResponseService); + super(OCPPVersion.VERSION_16, ocppResponseService); this.jsonSchemas = new Map>([ [ OCPP16RequestCommand.AUTHORIZE, @@ -153,7 +154,6 @@ export default class OCPP16RequestService extends OCPPRequestService { ], ]); this.buildRequestPayload.bind(this); - this.validatePayload.bind(this); } public async requestHandler( @@ -168,7 +168,6 @@ export default class OCPP16RequestService extends OCPPRequestService { commandName, commandParams ); - this.validatePayload(chargingStation, commandName, requestPayload); return (await this.sendMessage( chargingStation, Utils.generateUUID(), @@ -186,6 +185,19 @@ export default class OCPP16RequestService extends OCPPRequestService { ); } + protected getRequestPayloadValidationSchema( + chargingStation: ChargingStation, + commandName: OCPP16RequestCommand + ): JSONSchemaType | false { + if (this.jsonSchemas.has(commandName) === true) { + return this.jsonSchemas.get(commandName); + } + logger.warn( + `${chargingStation.logPrefix()} ${moduleName}.getPayloadValidationSchema: No JSON schema found for command ${commandName} PDU validation` + ); + return false; + } + private buildRequestPayload( chargingStation: ChargingStation, commandName: OCPP16RequestCommand, @@ -250,7 +262,7 @@ export default class OCPP16RequestService extends OCPPRequestService { meterStart: chargingStation.getEnergyActiveImportRegisterByConnectorId( commandParams?.connectorId as number ), - timestamp: new Date().toISOString(), + timestamp: new Date(), } as unknown as Request; case OCPP16RequestCommand.STOP_TRANSACTION: connectorId = chargingStation.getConnectorIdByTransactionId( @@ -268,7 +280,7 @@ export default class OCPP16RequestService extends OCPPRequestService { commandParams?.idTag ?? chargingStation.getTransactionIdTag(commandParams?.transactionId as number), meterStop: commandParams?.meterStop ?? energyActiveImportRegister, - timestamp: new Date().toISOString(), + timestamp: new Date(), reason: commandParams?.reason, ...(chargingStation.getTransactionDataMeterValues() && { transactionData: OCPP16ServiceUtils.buildTransactionDataMeterValues( @@ -294,23 +306,4 @@ 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; - } }