X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16ResponseService.ts;h=64145bb3db2fe05a7bf840462092a85ff22f7756;hb=4e3b1d6bdc767ec63949b998f0375fe2b5bc2b28;hp=6dcc5d5d2cf5f916f68838321ecb940075fdd6d4;hpb=dcda0566d1bcc7e3390faeb044a5195ac0c811a9;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 6dcc5d5d..64145bb3 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -1,7 +1,5 @@ // Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. -import { parentPort } from 'node:worker_threads'; - import type { JSONSchemaType } from 'ajv'; import { secondsToMilliseconds } from 'date-fns'; @@ -16,12 +14,12 @@ import { import { OCPPError } from '../../../exception'; import { type ChangeConfigurationResponse, + ChargingStationEvents, type ClearChargingProfileResponse, ErrorType, type GenericResponse, type GetConfigurationResponse, type GetDiagnosticsResponse, - type JsonObject, type JsonType, OCPP16AuthorizationStatus, type OCPP16AuthorizeRequest, @@ -54,13 +52,7 @@ import { type SetChargingProfileResponse, type UnlockConnectorResponse, } from '../../../types'; -import { - Constants, - buildUpdatedMessage, - convertToInt, - isNullOrUndefined, - logger, -} from '../../../utils'; +import { Constants, convertToInt, isNullOrUndefined, logger } from '../../../utils'; import { OCPPResponseService } from '../OCPPResponseService'; const moduleName = 'OCPP16ResponseService'; @@ -68,11 +60,11 @@ const moduleName = 'OCPP16ResponseService'; export class OCPP16ResponseService extends OCPPResponseService { public jsonIncomingRequestResponseSchemas: Map< OCPP16IncomingRequestCommand, - JSONSchemaType + JSONSchemaType >; private responseHandlers: Map; - private jsonSchemas: Map>; + private jsonSchemas: Map>; public constructor() { // if (new.target?.name === moduleName) { @@ -109,7 +101,7 @@ export class OCPP16ResponseService extends OCPPResponseService { this.emptyResponseHandler.bind(this) as ResponseHandler, ], ]); - this.jsonSchemas = new Map>([ + this.jsonSchemas = new Map>([ [ OCPP16RequestCommand.BOOT_NOTIFICATION, OCPP16ServiceUtils.parseJsonSchemaFile( @@ -366,7 +358,7 @@ export class OCPP16ResponseService extends OCPPResponseService { ErrorType.NOT_IMPLEMENTED, `${commandName} is not implemented to handle response PDU ${JSON.stringify( payload, - null, + undefined, 2, )}`, commandName, @@ -378,7 +370,7 @@ export class OCPP16ResponseService extends OCPPResponseService { ErrorType.SECURITY_ERROR, `${commandName} cannot be issued to handle response PDU ${JSON.stringify( payload, - null, + undefined, 2, )} while the charging station is not registered on the central server.`, commandName, @@ -524,7 +516,7 @@ export class OCPP16ResponseService extends OCPPResponseService { if ( connectorStatus?.transactionRemoteStarted === true && chargingStation.getAuthorizeRemoteTxRequests() === true && - chargingStation.getRemoteAuthorization() === true && + chargingStation.stationInfo?.remoteAuthorization === true && connectorStatus?.idTagLocalAuthorized === false && connectorStatus?.idTagAuthorized === false ) { @@ -560,7 +552,7 @@ export class OCPP16ResponseService extends OCPPResponseService { } if (connectorStatus?.transactionStarted === true) { logger.error( - `${chargingStation.logPrefix()} Trying to start a transaction on an already used connector id ${connectorId} by idTag ${connectorStatus?.transactionIdTag}}`, + `${chargingStation.logPrefix()} Trying to start a transaction on an already used connector id ${connectorId} by idTag ${connectorStatus?.transactionIdTag}`, ); return; } @@ -570,7 +562,7 @@ export class OCPP16ResponseService extends OCPPResponseService { for (const [id, status] of evseStatus.connectors) { if (id !== connectorId && status?.transactionStarted === true) { logger.error( - `${chargingStation.logPrefix()} Trying to start a transaction on an already used evse id ${evseId} by connector id ${id} with idTag ${status?.transactionIdTag}}`, + `${chargingStation.logPrefix()} Trying to start a transaction on an already used evse id ${evseId} by connector id ${id} with idTag ${status?.transactionIdTag}`, ); await this.resetConnectorOnStartTransactionError(chargingStation, connectorId); return; @@ -637,7 +629,7 @@ export class OCPP16ResponseService extends OCPPResponseService { ReservationTerminationReason.TRANSACTION_STARTED, ); } - chargingStation.getBeginEndMeterValues() && + chargingStation.stationInfo?.beginEndMeterValues && (await chargingStation.ocppRequestService.requestHandler< OCPP16MeterValuesRequest, OCPP16MeterValuesResponse @@ -665,7 +657,7 @@ export class OCPP16ResponseService extends OCPPResponseService { ); chargingStation.startMeterValues( connectorId, - configuredMeterValueSampleInterval + configuredMeterValueSampleInterval !== undefined ? secondsToMilliseconds(convertToInt(configuredMeterValueSampleInterval.value)) : Constants.DEFAULT_METER_VALUES_INTERVAL, ); @@ -701,7 +693,7 @@ export class OCPP16ResponseService extends OCPPResponseService { OCPP16ChargePointStatus.Available, ); } - parentPort?.postMessage(buildUpdatedMessage(chargingStation)); + chargingStation.emit(ChargingStationEvents.updated); } private async handleResponseStopTransaction( @@ -720,9 +712,9 @@ export class OCPP16ResponseService extends OCPPResponseService { ); return; } - chargingStation.getBeginEndMeterValues() === true && - chargingStation.getOcppStrictCompliance() === false && - chargingStation.getOutOfOrderEndMeterValues() === true && + chargingStation.stationInfo?.beginEndMeterValues === true && + chargingStation.stationInfo?.ocppStrictCompliance === false && + chargingStation.stationInfo?.outOfOrderEndMeterValues === true && (await chargingStation.ocppRequestService.requestHandler< OCPP16MeterValuesRequest, OCPP16MeterValuesResponse @@ -758,12 +750,12 @@ export class OCPP16ResponseService extends OCPPResponseService { } resetConnectorStatus(chargingStation.getConnectorStatus(transactionConnectorId!)!); chargingStation.stopMeterValues(transactionConnectorId!); - parentPort?.postMessage(buildUpdatedMessage(chargingStation)); + chargingStation.emit(ChargingStationEvents.updated); const logMsg = `${chargingStation.logPrefix()} Transaction with id ${ requestPayload.transactionId } STOPPED on ${ chargingStation.stationInfo.chargingStationId - }#${transactionConnectorId} with status '${payload.idTagInfo?.status ?? 'undefined'}'`; + }#${transactionConnectorId} with status '${payload.idTagInfo?.status}'`; if ( isNullOrUndefined(payload.idTagInfo) || payload.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED