From: Jérôme Benoit Date: Sun, 15 Jan 2023 11:52:30 +0000 (+0100) Subject: Ensure start transaction payload is always compliant with OCA specs X-Git-Tag: v1.1.90~5 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=18bf82749012da310723996912f5239c20bdc4e7;p=e-mobility-charging-stations-simulator.git Ensure start transaction payload is always compliant with OCA specs Signed-off-by: Jérôme Benoit --- diff --git a/.cfignore b/.cfignore index 12957ca0..f23ccd14 100644 --- a/.cfignore +++ b/.cfignore @@ -11,6 +11,7 @@ .husky .editorconfig .vscode +*.code-workspace .clinic *.clinic-* .tscache @@ -45,10 +46,12 @@ *tags-template.* *config-template.* *cf-template.* +manifest-*.yml *.tar.gz *.mta rollup.config.js rollup.config.mjs +mikro-orm.config.ts mta.yaml mta_archives docker diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index ee1ebff4..ad68f09c 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -341,16 +341,16 @@ export default class ChargingStation { public getEnergyActiveImportRegisterByTransactionId( transactionId: number, - meterStop = false + rounded = false ): number { return this.getEnergyActiveImportRegister( this.getConnectorStatus(this.getConnectorIdByTransactionId(transactionId)), - meterStop + rounded ); } - public getEnergyActiveImportRegisterByConnectorId(connectorId: number): number { - return this.getEnergyActiveImportRegister(this.getConnectorStatus(connectorId)); + public getEnergyActiveImportRegisterByConnectorId(connectorId: number, rounded = false): number { + return this.getEnergyActiveImportRegister(this.getConnectorStatus(connectorId), rounded); } public getAuthorizeRemoteTxRequests(): boolean { @@ -1637,19 +1637,16 @@ export default class ChargingStation { logger.error(this.logPrefix() + ' WebSocket error:', error); } - private getEnergyActiveImportRegister( - connectorStatus: ConnectorStatus, - meterStop = false - ): number { + private getEnergyActiveImportRegister(connectorStatus: ConnectorStatus, rounded = false): number { if (this.getMeteringPerTransaction() === true) { return ( - (meterStop === true + (rounded === true ? Math.round(connectorStatus?.transactionEnergyActiveImportRegisterValue) : connectorStatus?.transactionEnergyActiveImportRegisterValue) ?? 0 ); } return ( - (meterStop === true + (rounded === true ? Math.round(connectorStatus?.energyActiveImportRegisterValue) : connectorStatus?.energyActiveImportRegisterValue) ?? 0 ); diff --git a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts index 9979c70a..15b2f2dd 100644 --- a/src/charging-station/ocpp/1.6/OCPP16RequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16RequestService.ts @@ -116,15 +116,10 @@ export default class OCPP16RequestService extends OCPPRequestService { params?: RequestParams ): Promise { if (OCPP16ServiceUtils.isRequestCommandSupported(chargingStation, commandName) === true) { - const requestPayload = this.buildRequestPayload( - chargingStation, - commandName, - commandParams - ); return (await this.sendMessage( chargingStation, Utils.generateUUID(), - requestPayload, + this.buildRequestPayload(chargingStation, commandName, commandParams), commandName, params )) as unknown as ResponseType; @@ -165,7 +160,8 @@ export default class OCPP16RequestService extends OCPPRequestService { return { idTag: Constants.DEFAULT_IDTAG, meterStart: chargingStation.getEnergyActiveImportRegisterByConnectorId( - commandParams?.connectorId as number + commandParams?.connectorId as number, + true ), timestamp: new Date(), ...commandParams, diff --git a/src/charging-station/ocpp/2.0/OCPP20RequestService.ts b/src/charging-station/ocpp/2.0/OCPP20RequestService.ts index eddbcf8d..ccacc0fa 100644 --- a/src/charging-station/ocpp/2.0/OCPP20RequestService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20RequestService.ts @@ -64,15 +64,10 @@ export default class OCPP20RequestService extends OCPPRequestService { params?: RequestParams ): Promise { if (OCPP20ServiceUtils.isRequestCommandSupported(chargingStation, commandName) === true) { - const requestPayload = this.buildRequestPayload( - chargingStation, - commandName, - commandParams - ); return (await this.sendMessage( chargingStation, Utils.generateUUID(), - requestPayload, + this.buildRequestPayload(chargingStation, commandName, commandParams), commandName, params )) as unknown as ResponseType; diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index b72c2a8c..c885a68e 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -249,15 +249,21 @@ export default abstract class OCPPRequestService { const beginId = PerformanceStatistics.beginMeasure(commandName as string); try { chargingStation.wsConnection.send(messageToSend); + logger.debug( + `${chargingStation.logPrefix()} >> Command '${commandName}' sent ${this.getMessageTypeString( + messageType + )} payload: ${messageToSend}` + ); } catch (error) { + logger.error( + `${chargingStation.logPrefix()} >> Command '${commandName}' failed to send ${this.getMessageTypeString( + messageType + )} payload: ${messageToSend}:`, + error + ); sendError = true; } PerformanceStatistics.endMeasure(commandName as string, beginId); - logger.debug( - `${chargingStation.logPrefix()} >> Command '${commandName}' sent ${this.getMessageTypeString( - messageType - )} payload: ${messageToSend}` - ); } const wsClosedOrErrored = chargingStation.isWebSocketConnectionOpened() === false || sendError === true;