X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2FChargingStationWorkerBroadcastChannel.ts;h=086278784cb5eb7b1f1e53286207c6d41314d03e;hb=b20eb107fed5d02d7c6317944c4aef034aef49b2;hp=64332533d4dfc606f9b551e5f3f0de8aa85c66ab;hpb=51c83d6f833f27f9990c17fc380ab5ee618894b1;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts index 64332533..08627878 100644 --- a/src/charging-station/ChargingStationWorkerBroadcastChannel.ts +++ b/src/charging-station/ChargingStationWorkerBroadcastChannel.ts @@ -4,7 +4,6 @@ import { AuthorizationStatus, StartTransactionRequest, StartTransactionResponse, - StopTransactionReason, StopTransactionRequest, StopTransactionResponse, } from '../types/ocpp/Transaction'; @@ -38,27 +37,27 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca if (this.isResponse(messageEvent.data)) { return; } - this.validateMessageEvent(messageEvent); + const [uuid, command, requestPayload] = this.validateMessageEvent(messageEvent) + .data as BroadcastChannelRequest; - const [uuid, command, requestPayload] = messageEvent.data as BroadcastChannelRequest; - - if ( - requestPayload?.hashId === undefined && - (requestPayload?.hashIds as string[])?.includes(this.chargingStation.stationInfo.hashId) === - false - ) { - return; - } - if ( - requestPayload?.hashIds === undefined && - requestPayload?.hashId !== this.chargingStation.stationInfo.hashId - ) { - return; - } - if (requestPayload?.hashId !== undefined) { - logger.warn( - `${this.chargingStation.logPrefix()} ${moduleName}.requestHandler: 'hashId' field usage in PDU is deprecated, use 'hashIds' instead` - ); + if (requestPayload?.hashIds !== undefined || requestPayload?.hashId !== undefined) { + if ( + requestPayload?.hashId === undefined && + requestPayload?.hashIds?.includes(this.chargingStation.stationInfo.hashId) === false + ) { + return; + } + if ( + requestPayload?.hashIds === undefined && + requestPayload?.hashId !== this.chargingStation.stationInfo.hashId + ) { + return; + } + if (requestPayload?.hashId !== undefined) { + logger.warn( + `${this.chargingStation.logPrefix()} ${moduleName}.requestHandler: 'hashId' field usage in PDU is deprecated, use 'hashIds' instead` + ); + } } let responsePayload: BroadcastChannelResponsePayload; @@ -97,7 +96,7 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca private messageErrorHandler(messageEvent: MessageEvent): void { logger.error( `${this.chargingStation.logPrefix()} ${moduleName}.messageErrorHandler: Error at handling message:`, - { messageEvent, messageEventData: messageEvent.data } + { messageEvent } ); } @@ -133,16 +132,17 @@ export default class ChargingStationWorkerBroadcastChannel extends WorkerBroadca >(this.chargingStation, RequestCommand.STOP_TRANSACTION, { transactionId: requestPayload.transactionId, meterStop: this.chargingStation.getEnergyActiveImportRegisterByTransactionId( - requestPayload.transactionId + requestPayload.transactionId, + true ), idTag: this.chargingStation.getTransactionIdTag(requestPayload.transactionId), - reason: StopTransactionReason.NONE, + ...(requestPayload.reason && { reason: requestPayload.reason }), }); case BroadcastChannelProcedureName.START_AUTOMATIC_TRANSACTION_GENERATOR: - this.chargingStation.startAutomaticTransactionGenerator(); + this.chargingStation.startAutomaticTransactionGenerator(requestPayload.connectorIds); break; case BroadcastChannelProcedureName.STOP_AUTOMATIC_TRANSACTION_GENERATOR: - this.chargingStation.stopAutomaticTransactionGenerator(); + this.chargingStation.stopAutomaticTransactionGenerator(requestPayload.connectorIds); break; default: // eslint-disable-next-line @typescript-eslint/restrict-template-expressions