X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16RequestService.ts;h=8ff6bea4b08406cfbcca392d456d3eca5e79b67b;hb=7edba9a79cf60b1d1113ec89f310788194ddb97a;hp=efbd603c98e170dce3f4a3192d7f62c758351f34;hpb=268a74bb051fcbbad532fd833f0d8fd2b33b6c64;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 efbd603c..8ff6bea4 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -2,7 +2,9 @@ import type { JSONSchemaType } from 'ajv'; +import { OCPP16Constants } from './OCPP16Constants'; import { OCPP16ServiceUtils } from './OCPP16ServiceUtils'; +import type { ChargingStation } from '../../../charging-station'; import { OCPPError } from '../../../exception'; import { ErrorType, @@ -22,10 +24,7 @@ import { OCPPVersion, type RequestParams, } from '../../../types'; -import { Constants } from '../../../utils/Constants'; -import { Utils } from '../../../utils/Utils'; -import type { ChargingStation } from '../../ChargingStation'; -import { OCPPConstants } from '../OCPPConstants'; +import { Constants, Utils } from '../../../utils'; import { OCPPRequestService } from '../OCPPRequestService'; import type { OCPPResponseService } from '../OCPPResponseService'; @@ -35,9 +34,9 @@ export class OCPP16RequestService extends OCPPRequestService { protected jsonSchemas: Map>; public constructor(ocppResponseService: OCPPResponseService) { - if (new.target?.name === moduleName) { - throw new TypeError(`Cannot construct ${new.target?.name} instances directly`); - } + // if (new.target?.name === moduleName) { + // throw new TypeError(`Cannot construct ${new.target?.name} instances directly`); + // } super(OCPPVersion.VERSION_16, ocppResponseService); this.jsonSchemas = new Map>([ [ @@ -121,7 +120,11 @@ export class OCPP16RequestService extends OCPPRequestService { ), ], ]); - this.buildRequestPayload.bind(this); + this.buildRequestPayload = this.buildRequestPayload.bind(this) as ( + chargingStation: ChargingStation, + commandName: OCPP16RequestCommand, + commandParams?: JsonType + ) => Request; } public async requestHandler( @@ -130,6 +133,7 @@ export class OCPP16RequestService extends OCPPRequestService { commandParams?: JsonType, params?: RequestParams ): Promise { + // FIXME?: add sanity checks on charging station availability, connector availability, connector status, etc. if (OCPP16ServiceUtils.isRequestCommandSupported(chargingStation, commandName) === true) { return (await this.sendMessage( chargingStation, @@ -137,7 +141,7 @@ export class OCPP16RequestService extends OCPPRequestService { this.buildRequestPayload(chargingStation, commandName, commandParams), commandName, params - )) as unknown as ResponseType; + )) as ResponseType; } // OCPPError usage here is debatable: it's an error in the OCPP stack but not targeted to sendError(). throw new OCPPError( @@ -170,7 +174,7 @@ export class OCPP16RequestService extends OCPPRequestService { ...commandParams, } as unknown as Request; case OCPP16RequestCommand.HEARTBEAT: - return OCPPConstants.OCPP_REQUEST_EMPTY as unknown as Request; + return OCPP16Constants.OCPP_REQUEST_EMPTY as unknown as Request; case OCPP16RequestCommand.START_TRANSACTION: return { idTag: Constants.DEFAULT_IDTAG,