X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=inline;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16ResponseService.ts;h=edec1e4eb53f40bc62f93349d4e97db907637fad;hb=1b2cddaccac1c179067c7b8ce190c625c37dd5c5;hp=4e7b9716d1f11428508e8075be18c1f0b5df4ad5;hpb=d929adcc32a8cc79f0c7182d16f70367b001d28c;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 4e7b9716..edec1e4e 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,8 +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}:`, - connectorStatus, + `${chargingStation.logPrefix()} Trying to start a transaction on an already used connector id ${connectorId} by idTag ${connectorStatus?.transactionIdTag}`, ); return; } @@ -571,8 +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}:`, - evseStatus, + `${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; @@ -639,7 +629,7 @@ export class OCPP16ResponseService extends OCPPResponseService { ReservationTerminationReason.TRANSACTION_STARTED, ); } - chargingStation.getBeginEndMeterValues() && + chargingStation.stationInfo?.beginEndMeterValues && (await chargingStation.ocppRequestService.requestHandler< OCPP16MeterValuesRequest, OCPP16MeterValuesResponse @@ -703,7 +693,7 @@ export class OCPP16ResponseService extends OCPPResponseService { OCPP16ChargePointStatus.Available, ); } - parentPort?.postMessage(buildUpdatedMessage(chargingStation)); + chargingStation.emit(ChargingStationEvents.updated); } private async handleResponseStopTransaction( @@ -722,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 @@ -760,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