import type ChargingStation from './ChargingStation';
import Constants from '../utils/Constants';
+import { OCPP16ServiceUtils } from './ocpp/1.6/OCPP16ServiceUtils';
import PerformanceStatistics from '../performance/PerformanceStatistics';
import { RequestCommand } from '../types/ocpp/Requests';
import { Status } from '../types/AutomaticTransactionGenerator';
let stopResponse: StopTransactionResponse;
if (this.chargingStation.getConnectorStatus(connectorId)?.transactionStarted) {
transactionId = this.chargingStation.getConnectorStatus(connectorId).transactionId;
- stopResponse = await this.chargingStation.ocppRequestService.sendStopTransaction(
- transactionId,
- this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
- this.chargingStation.getTransactionIdTag(transactionId),
- reason
- );
+ if (
+ this.chargingStation.getBeginEndMeterValues() &&
+ this.chargingStation.getOcppStrictCompliance() &&
+ !this.chargingStation.getOutOfOrderEndMeterValues()
+ ) {
+ // FIXME: Implement OCPP version agnostic helpers
+ const transactionEndMeterValue = OCPP16ServiceUtils.buildTransactionEndMeterValue(
+ this.chargingStation,
+ connectorId,
+ this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId)
+ );
+ await this.chargingStation.ocppRequestService.sendTransactionEndMeterValues(
+ connectorId,
+ transactionId,
+ transactionEndMeterValue
+ );
+ }
+ stopResponse = (await this.chargingStation.ocppRequestService.sendMessageHandler(
+ RequestCommand.STOP_TRANSACTION,
+ {
+ transactionId,
+ meterStop:
+ this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
+ idTag: this.chargingStation.getTransactionIdTag(transactionId),
+ reason,
+ }
+ )) as StopTransactionResponse;
this.connectorsStatus.get(connectorId).stopTransactionRequests++;
} else {
logger.warn(
import OCPP16IncomingRequestService from './ocpp/1.6/OCPP16IncomingRequestService';
import OCPP16RequestService from './ocpp/1.6/OCPP16RequestService';
import OCPP16ResponseService from './ocpp/1.6/OCPP16ResponseService';
+import { OCPP16ServiceUtils } from './ocpp/1.6/OCPP16ServiceUtils';
import OCPPError from '../exception/OCPPError';
import OCPPIncomingRequestService from './ocpp/OCPPIncomingRequestService';
import OCPPRequestService from './ocpp/OCPPRequestService';
for (const connectorId of this.connectors.keys()) {
if (connectorId > 0 && this.getConnectorStatus(connectorId)?.transactionStarted) {
const transactionId = this.getConnectorStatus(connectorId).transactionId;
- await this.ocppRequestService.sendStopTransaction(
+ if (
+ this.getBeginEndMeterValues() &&
+ this.getOcppStrictCompliance() &&
+ !this.getOutOfOrderEndMeterValues()
+ ) {
+ // FIXME: Implement OCPP version agnostic helpers
+ const transactionEndMeterValue = OCPP16ServiceUtils.buildTransactionEndMeterValue(
+ this,
+ connectorId,
+ this.getEnergyActiveImportRegisterByTransactionId(transactionId)
+ );
+ await this.ocppRequestService.sendTransactionEndMeterValues(
+ connectorId,
+ transactionId,
+ transactionEndMeterValue
+ );
+ }
+ await this.ocppRequestService.sendMessageHandler(RequestCommand.STOP_TRANSACTION, {
transactionId,
- this.getEnergyActiveImportRegisterByTransactionId(transactionId),
- this.getTransactionIdTag(transactionId),
- reason
- );
+ meterStop: this.getEnergyActiveImportRegisterByTransactionId(transactionId),
+ idTag: this.getTransactionIdTag(transactionId),
+ reason,
+ });
}
}
}
OCPP16AuthorizeResponse,
OCPP16StartTransactionResponse,
OCPP16StopTransactionReason,
+ OCPP16StopTransactionResponse,
} from '../../../types/ocpp/1.6/Transaction';
import type ChargingStation from '../../ChargingStation';
import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointErrorCode';
import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus';
import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus';
+import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
import { OCPP16StandardParametersKey } from '../../../types/ocpp/1.6/Configuration';
import { OCPPConfigurationKey } from '../../../types/ocpp/Configuration';
import OCPPError from '../../../exception/OCPPError';
}
if (this.chargingStation.getConnectorStatus(connectorId)?.transactionStarted) {
const transactionId = this.chargingStation.getConnectorStatus(connectorId).transactionId;
- const stopResponse = await this.chargingStation.ocppRequestService.sendStopTransaction(
- transactionId,
- this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
- this.chargingStation.getTransactionIdTag(transactionId),
- OCPP16StopTransactionReason.UNLOCK_COMMAND
- );
+ if (
+ this.chargingStation.getBeginEndMeterValues() &&
+ this.chargingStation.getOcppStrictCompliance() &&
+ !this.chargingStation.getOutOfOrderEndMeterValues()
+ ) {
+ // FIXME: Implement OCPP version agnostic helpers
+ const transactionEndMeterValue = OCPP16ServiceUtils.buildTransactionEndMeterValue(
+ this.chargingStation,
+ connectorId,
+ this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId)
+ );
+ await this.chargingStation.ocppRequestService.sendTransactionEndMeterValues(
+ connectorId,
+ transactionId,
+ transactionEndMeterValue
+ );
+ }
+ const stopResponse = (await this.chargingStation.ocppRequestService.sendMessageHandler(
+ OCPP16RequestCommand.STOP_TRANSACTION,
+ {
+ transactionId,
+ meterStop:
+ this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
+ idTag: this.chargingStation.getTransactionIdTag(transactionId),
+ reason: OCPP16StopTransactionReason.UNLOCK_COMMAND,
+ }
+ )) as OCPP16StopTransactionResponse;
if (stopResponse.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) {
return Constants.OCPP_RESPONSE_UNLOCKED;
}
);
this.chargingStation.getConnectorStatus(connectorId).status =
OCPP16ChargePointStatus.FINISHING;
- await this.chargingStation.ocppRequestService.sendStopTransaction(
- transactionId,
- this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
- this.chargingStation.getTransactionIdTag(transactionId)
+ if (
+ this.chargingStation.getBeginEndMeterValues() &&
+ this.chargingStation.getOcppStrictCompliance() &&
+ !this.chargingStation.getOutOfOrderEndMeterValues()
+ ) {
+ // FIXME: Implement OCPP version agnostic helpers
+ const transactionEndMeterValue = OCPP16ServiceUtils.buildTransactionEndMeterValue(
+ this.chargingStation,
+ connectorId,
+ this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId)
+ );
+ await this.chargingStation.ocppRequestService.sendTransactionEndMeterValues(
+ connectorId,
+ transactionId,
+ transactionEndMeterValue
+ );
+ }
+ await this.chargingStation.ocppRequestService.sendMessageHandler(
+ OCPP16RequestCommand.STOP_TRANSACTION,
+ {
+ transactionId,
+ meterStop:
+ this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
+ idTag: this.chargingStation.getTransactionIdTag(transactionId),
+ }
);
return Constants.OCPP_RESPONSE_ACCEPTED;
}
import {
AuthorizeRequest,
- OCPP16StartTransactionResponse,
- OCPP16StopTransactionReason,
- OCPP16StopTransactionResponse,
StartTransactionRequest,
StopTransactionRequest,
} from '../../../types/ocpp/1.6/Transaction';
);
}
- public async sendStopTransaction(
- transactionId: number,
- meterStop: number,
- idTag?: string,
- reason: OCPP16StopTransactionReason = OCPP16StopTransactionReason.NONE
- ): Promise<OCPP16StopTransactionResponse> {
- let connectorId: number;
- for (const id of this.chargingStation.connectors.keys()) {
- if (id > 0 && this.chargingStation.getConnectorStatus(id)?.transactionId === transactionId) {
- connectorId = id;
- break;
- }
- }
- const transactionEndMeterValue = OCPP16ServiceUtils.buildTransactionEndMeterValue(
- this.chargingStation,
- connectorId,
- meterStop
- );
- // FIXME: should be a callback, each OCPP commands implementation must do only one job
- this.chargingStation.getBeginEndMeterValues() &&
- this.chargingStation.getOcppStrictCompliance() &&
- !this.chargingStation.getOutOfOrderEndMeterValues() &&
- (await this.sendTransactionEndMeterValues(
- connectorId,
- transactionId,
- transactionEndMeterValue
- ));
- const payload: StopTransactionRequest = {
- transactionId,
- ...(!Utils.isUndefined(idTag) && { idTag }),
- meterStop,
- timestamp: new Date().toISOString(),
- ...(reason && { reason }),
- ...(this.chargingStation.getTransactionDataMeterValues() && {
- transactionData: OCPP16ServiceUtils.buildTransactionDataMeterValues(
- this.chargingStation.getConnectorStatus(connectorId).transactionBeginMeterValue,
- transactionEndMeterValue
- ),
- }),
- };
- return (await this.sendMessage(
- Utils.generateUUID(),
- payload,
- OCPP16RequestCommand.STOP_TRANSACTION
- )) as OCPP16StartTransactionResponse;
- }
-
public async sendMeterValues(
connectorId: number,
transactionId: number,
commandName: OCPP16RequestCommand,
commandParams?: JsonType
): JsonType {
+ let connectorId: number;
switch (commandName) {
case OCPP16RequestCommand.AUTHORIZE:
return {
timestamp: new Date().toISOString(),
} as StartTransactionRequest;
case OCPP16RequestCommand.STOP_TRANSACTION:
+ for (const id of this.chargingStation.connectors.keys()) {
+ if (
+ id > 0 &&
+ this.chargingStation.getConnectorStatus(id)?.transactionId ===
+ commandParams?.transactionId
+ ) {
+ connectorId = id;
+ break;
+ }
+ }
return {
transactionId: commandParams?.transactionId,
...(!Utils.isUndefined(commandParams?.idTag) && { idTag: commandParams.idTag }),
...(commandParams?.reason && { reason: commandParams.reason }),
...(this.chargingStation.getTransactionDataMeterValues() && {
transactionData: OCPP16ServiceUtils.buildTransactionDataMeterValues(
- this.chargingStation.getConnectorStatus(commandParams?.connectorId as number)
- .transactionBeginMeterValue,
+ this.chargingStation.getConnectorStatus(connectorId).transactionBeginMeterValue,
OCPP16ServiceUtils.buildTransactionEndMeterValue(
this.chargingStation,
- commandParams?.connectorId as number,
+ connectorId,
commandParams?.meterStop as number
)
),
params?: SendParams
): Promise<ResponseType>;
- public abstract sendStopTransaction(
- transactionId: number,
- meterStop: number,
- idTag?: string,
- reason?: StopTransactionReason
- ): Promise<StopTransactionResponse>;
-
public abstract sendMeterValues(
connectorId: number,
transactionId: number,