X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2FOCPPRequestService.ts;h=4ef39b52ebec7e7e843a13b9b388bea1de8ec567;hb=17bc43d765c22c8d8c132484f8dc9c3edd370d91;hp=13cb170789f502fce73c4e6847b9e45f12fad6da;hpb=1431af786f4d2728bad4132d505758144798516b;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 13cb1707..4ef39b52 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -1,34 +1,36 @@ import Ajv, { type JSONSchemaType } from 'ajv'; import ajvFormats from 'ajv-formats'; -import type OCPPResponseService from './OCPPResponseService'; +import type { OCPPResponseService } from './OCPPResponseService'; import { OCPPServiceUtils } from './OCPPServiceUtils'; -import OCPPError from '../../exception/OCPPError'; -import PerformanceStatistics from '../../performance/PerformanceStatistics'; -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 type { OCPPVersion } from '../../types/ocpp/OCPPVersion'; +import { OCPPError } from '../../exception'; +import { PerformanceStatistics } from '../../performance'; import { + type EmptyObject, type ErrorCallback, + type ErrorResponse, + ErrorType, + type HandleErrorParams, type IncomingRequestCommand, + type JsonObject, + type JsonType, + MessageType, + type OCPPVersion, type OutgoingRequest, RequestCommand, type RequestParams, + type Response, type ResponseCallback, type ResponseType, -} from '../../types/ocpp/Requests'; -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'; +} from '../../types'; +import { Constants } from '../../utils/Constants'; +import { logger } from '../../utils/Logger'; +import { Utils } from '../../utils/Utils'; +import type { ChargingStation } from '../ChargingStation'; const moduleName = 'OCPPRequestService'; -export default abstract class OCPPRequestService { +export abstract class OCPPRequestService { private static instance: OCPPRequestService | null = null; private readonly version: OCPPVersion; private readonly ajv: Ajv; @@ -211,7 +213,7 @@ export default abstract class OCPPRequestService { messageId: string, messagePayload: JsonType | OCPPError, messageType: MessageType, - commandName?: RequestCommand | IncomingRequestCommand, + commandName: RequestCommand | IncomingRequestCommand, params: RequestParams = { skipBufferingOnError: false, triggerMessage: false, @@ -232,7 +234,7 @@ export default abstract class OCPPRequestService { return Utils.promiseWithTimeout( new Promise((resolve, reject) => { if (chargingStation.getEnableStatistics() === true) { - chargingStation.performanceStatistics.addRequestStatistic(commandName, messageType); + chargingStation.performanceStatistics?.addRequestStatistic(commandName, messageType); } const messageToSend = this.buildMessageToSend( chargingStation, @@ -249,7 +251,7 @@ export default abstract class OCPPRequestService { if (wsOpened) { const beginId = PerformanceStatistics.beginMeasure(commandName); try { - chargingStation.wsConnection.send(messageToSend); + chargingStation.wsConnection?.send(messageToSend); logger.debug( `${chargingStation.logPrefix()} >> Command '${commandName}' sent ${OCPPServiceUtils.getMessageTypeString( messageType @@ -306,7 +308,7 @@ export default abstract class OCPPRequestService { */ function responseCallback(payload: JsonType, requestPayload: JsonType): void { if (chargingStation.getEnableStatistics() === true) { - chargingStation.performanceStatistics.addRequestStatistic( + chargingStation.performanceStatistics?.addRequestStatistic( commandName, MessageType.CALL_RESULT_MESSAGE ); @@ -338,7 +340,7 @@ export default abstract class OCPPRequestService { */ function errorCallback(error: OCPPError, requestStatistic = true): void { if (requestStatistic === true && chargingStation.getEnableStatistics() === true) { - chargingStation.performanceStatistics.addRequestStatistic( + chargingStation.performanceStatistics?.addRequestStatistic( commandName, MessageType.CALL_ERROR_MESSAGE ); @@ -378,9 +380,9 @@ export default abstract class OCPPRequestService { messageId: string, messagePayload: JsonType | OCPPError, messageType: MessageType, - commandName?: RequestCommand | IncomingRequestCommand, - responseCallback?: ResponseCallback, - errorCallback?: ErrorCallback + commandName: RequestCommand | IncomingRequestCommand, + responseCallback: ResponseCallback, + errorCallback: ErrorCallback ): string { let messageToSend: string; // Type of message