X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16ResponseService.ts;h=146778141abdbcc3c72b7860d2fde9b5d8792c8e;hb=33276ba6a447f0beb92b934d2b8d5cb08eababb4;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..14677814 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'; @@ -21,7 +19,6 @@ import { type GenericResponse, type GetConfigurationResponse, type GetDiagnosticsResponse, - type JsonObject, type JsonType, OCPP16AuthorizationStatus, type OCPP16AuthorizeRequest, @@ -54,13 +51,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 +59,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 +100,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 +357,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 +369,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 +515,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 +551,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 +561,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 +628,7 @@ export class OCPP16ResponseService extends OCPPResponseService { ReservationTerminationReason.TRANSACTION_STARTED, ); } - chargingStation.getBeginEndMeterValues() && + chargingStation.stationInfo?.beginEndMeterValues && (await chargingStation.ocppRequestService.requestHandler< OCPP16MeterValuesRequest, OCPP16MeterValuesResponse @@ -667,7 +656,7 @@ export class OCPP16ResponseService extends OCPPResponseService { ); chargingStation.startMeterValues( connectorId, - configuredMeterValueSampleInterval + configuredMeterValueSampleInterval !== undefined ? secondsToMilliseconds(convertToInt(configuredMeterValueSampleInterval.value)) : Constants.DEFAULT_METER_VALUES_INTERVAL, ); @@ -703,7 +692,6 @@ export class OCPP16ResponseService extends OCPPResponseService { OCPP16ChargePointStatus.Available, ); } - parentPort?.postMessage(buildUpdatedMessage(chargingStation)); } private async handleResponseStopTransaction( @@ -722,9 +710,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 +748,11 @@ export class OCPP16ResponseService extends OCPPResponseService { } resetConnectorStatus(chargingStation.getConnectorStatus(transactionConnectorId!)!); chargingStation.stopMeterValues(transactionConnectorId!); - parentPort?.postMessage(buildUpdatedMessage(chargingStation)); 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