X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPRequestService.ts;h=c3311b856d3a21e267dd52141715a9a3cd6bc72d;hb=60c59a02878ddd2ddbac38ec3b3d38f706e538e9;hp=e4ac7868b496e9a19951d0ddb1319336d79fa84b;hpb=06ad945f66c591d91a4c0062e9f39e007b05ba83;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index e4ac7868..c3311b85 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -1,12 +1,12 @@ -import { JSONSchemaType } from 'ajv'; +import type { JSONSchemaType } from 'ajv'; import Ajv from 'ajv-draft-04'; import ajvFormats from 'ajv-formats'; import OCPPError from '../../exception/OCPPError'; import PerformanceStatistics from '../../performance/PerformanceStatistics'; -import { EmptyObject } from '../../types/EmptyObject'; -import { HandleErrorParams } from '../../types/Error'; -import { JsonObject, JsonType } from '../../types/JsonType'; +import type { EmptyObject } from '../../types/EmptyObject'; +import type { HandleErrorParams } from '../../types/Error'; +import type { JsonObject, JsonType } from '../../types/JsonType'; import { ErrorType } from '../../types/ocpp/ErrorType'; import { MessageType } from '../../types/ocpp/MessageType'; import { @@ -16,13 +16,13 @@ import { RequestParams, ResponseType, } from '../../types/ocpp/Requests'; -import { ErrorResponse, Response } from '../../types/ocpp/Responses'; +import type { ErrorResponse, Response } from '../../types/ocpp/Responses'; import Constants from '../../utils/Constants'; import logger from '../../utils/Logger'; import Utils from '../../utils/Utils'; import type ChargingStation from '../ChargingStation'; -import { OCPP16ServiceUtils } from './1.6/OCPP16ServiceUtils'; import type OCPPResponseService from './OCPPResponseService'; +import { OCPPServiceUtils } from './OCPPServiceUtils'; const moduleName = 'OCPPRequestService'; @@ -34,18 +34,21 @@ export default abstract class OCPPRequestService { protected constructor(ocppResponseService: OCPPResponseService) { this.ocppResponseService = ocppResponseService; + this.ajv = new Ajv(); + ajvFormats(this.ajv); this.requestHandler.bind(this); this.sendResponse.bind(this); this.sendError.bind(this); - this.ajv = new Ajv(); - ajvFormats(this.ajv); + this.internalSendMessage.bind(this); + this.buildMessageToSend.bind(this); + this.validateRequestPayload.bind(this); } public static getInstance( this: new (ocppResponseService: OCPPResponseService) => T, ocppResponseService: OCPPResponseService ): T { - if (!OCPPRequestService.instance) { + if (OCPPRequestService.instance === null) { OCPPRequestService.instance = new this(ocppResponseService); } return OCPPRequestService.instance as T; @@ -133,7 +136,7 @@ export default abstract class OCPPRequestService { validate.errors ); throw new OCPPError( - OCPP16ServiceUtils.AjvErrorsToErrorType(validate.errors), + OCPPServiceUtils.ajvErrorsToErrorType(validate.errors), 'Request PDU is invalid', commandName, JSON.stringify(validate.errors, null, 2) @@ -358,17 +361,17 @@ export default abstract class OCPPRequestService { error: Error, params: HandleErrorParams = { throwError: true } ): void { - logger.error(chargingStation.logPrefix() + ' Request command %s error: %j', commandName, error); + logger.error(chargingStation.logPrefix() + ' Request command %s error:', commandName, error); if (params?.throwError) { throw error; } } // eslint-disable-next-line @typescript-eslint/no-unused-vars - public abstract requestHandler( + public abstract requestHandler( chargingStation: ChargingStation, commandName: RequestCommand, commandParams?: JsonType, params?: RequestParams - ): Promise; + ): Promise; }