X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F2.0%2FOCPP20ResponseService.ts;h=6bc6a5c23a390d705c43ed4dca3395223ea7279f;hb=18bf82749012da310723996912f5239c20bdc4e7;hp=ef83ad4376c1e1d4fdecb99d04cb208b8b940242;hpb=028878919a937f9307634c0316e27c677a87d305;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts index ef83ad43..6bc6a5c2 100644 --- a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts @@ -6,6 +6,7 @@ import { fileURLToPath } from 'url'; import type { JSONSchemaType } from 'ajv'; +import { OCPP20ServiceUtils } from './OCPP20ServiceUtils'; import OCPPError from '../../../exception/OCPPError'; import type { JsonObject, JsonType } from '../../../types/JsonType'; import { @@ -15,6 +16,8 @@ import { import type { OCPP20BootNotificationResponse, OCPP20ClearCacheResponse, + OCPP20HeartbeatResponse, + OCPP20StatusNotificationResponse, } from '../../../types/ocpp/2.0/Responses'; import { ErrorType } from '../../../types/ocpp/ErrorType'; import { OCPPVersion } from '../../../types/ocpp/OCPPVersion'; @@ -22,7 +25,6 @@ import { RegistrationStatusEnumType, ResponseHandler } from '../../../types/ocpp import logger from '../../../utils/Logger'; import type ChargingStation from '../../ChargingStation'; import OCPPResponseService from '../OCPPResponseService'; -import { OCPP20ServiceUtils } from './OCPP20ServiceUtils'; const moduleName = 'OCPP20ResponseService'; @@ -42,33 +44,35 @@ 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)], + [OCPP20RequestCommand.STATUS_NOTIFICATION, this.emptyResponseHandler.bind(this)], ]); this.jsonSchemas = new Map>([ [ OCPP20RequestCommand.BOOT_NOTIFICATION, - JSON.parse( - fs.readFileSync( - path.resolve( - path.dirname(fileURLToPath(import.meta.url)), - '../../../assets/json-schemas/ocpp/2.0/BootNotificationResponse.json' - ), - 'utf8' - ) - ) as JSONSchemaType, + this.parseJsonSchemaFile( + '../../../assets/json-schemas/ocpp/2.0/BootNotificationResponse.json' + ), + ], + [ + OCPP20RequestCommand.HEARTBEAT, + this.parseJsonSchemaFile( + '../../../assets/json-schemas/ocpp/2.0/HeartbeatResponse.json' + ), + ], + [ + OCPP20RequestCommand.STATUS_NOTIFICATION, + this.parseJsonSchemaFile( + '../../../assets/json-schemas/ocpp/2.0/StatusNotificationResponse.json' + ), ], ]); this.jsonIncomingRequestResponseSchemas = new Map([ [ OCPP20IncomingRequestCommand.CLEAR_CACHE, - JSON.parse( - fs.readFileSync( - path.resolve( - path.dirname(fileURLToPath(import.meta.url)), - '../../../assets/json-schemas/ocpp/2.0/ClearCacheResponse.json' - ), - 'utf8' - ) - ) as JSONSchemaType, + this.parseJsonSchemaFile( + '../../../assets/json-schemas/ocpp/2.0/ClearCacheResponse.json' + ), ], ]); this.validatePayload.bind(this); @@ -182,4 +186,13 @@ export default class OCPP20ResponseService extends OCPPResponseService { ); } } + + private parseJsonSchemaFile(relativePath: string): JSONSchemaType { + return JSON.parse( + fs.readFileSync( + path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath), + 'utf8' + ) + ) as JSONSchemaType; + } }