import {
AuthorizationStatus,
+ AuthorizeRequest,
AuthorizeResponse,
+ StartTransactionRequest,
StartTransactionResponse,
StopTransactionReason,
+ StopTransactionRequest,
StopTransactionResponse,
} from '../types/ocpp/Transaction';
+import { MeterValuesRequest, RequestCommand } from '../types/ocpp/Requests';
import type ChargingStation from './ChargingStation';
import Constants from '../utils/Constants';
+import { MeterValuesResponse } from '../types/ocpp/Responses';
+import { OCPP16ServiceUtils } from './ocpp/1.6/OCPP16ServiceUtils';
import PerformanceStatistics from '../performance/PerformanceStatistics';
-import { RequestCommand } from '../types/ocpp/Requests';
import { Status } from '../types/AutomaticTransactionGenerator';
import Utils from '../utils/Utils';
import logger from '../utils/Logger';
}
public static getInstance(chargingStation: ChargingStation): AutomaticTransactionGenerator {
- if (!AutomaticTransactionGenerator.instances.has(chargingStation.id)) {
+ if (!AutomaticTransactionGenerator.instances.has(chargingStation.hashId)) {
AutomaticTransactionGenerator.instances.set(
- chargingStation.id,
+ chargingStation.hashId,
new AutomaticTransactionGenerator(chargingStation)
);
}
- return AutomaticTransactionGenerator.instances.get(chargingStation.id);
+ return AutomaticTransactionGenerator.instances.get(chargingStation.hashId);
}
public start(): void {
this.chargingStation.getConnectorStatus(connectorId).authorizeIdTag = idTag;
// Authorize idTag
const authorizeResponse: AuthorizeResponse =
- (await this.chargingStation.ocppRequestService.sendMessageHandler(
- RequestCommand.AUTHORIZE,
- {
- idTag,
- }
- )) as AuthorizeResponse;
+ await this.chargingStation.ocppRequestService.requestHandler<
+ AuthorizeRequest,
+ AuthorizeResponse
+ >(RequestCommand.AUTHORIZE, {
+ idTag,
+ });
this.connectorsStatus.get(connectorId).authorizeRequests++;
if (authorizeResponse?.idTagInfo?.status === AuthorizationStatus.ACCEPTED) {
this.connectorsStatus.get(connectorId).acceptedAuthorizeRequests++;
logger.info(this.logPrefix(connectorId) + ' start transaction for idTag ' + idTag);
// Start transaction
- startResponse = await this.chargingStation.ocppRequestService.sendStartTransaction(
+ startResponse = await this.chargingStation.ocppRequestService.requestHandler<
+ StartTransactionRequest,
+ StartTransactionResponse
+ >(RequestCommand.START_TRANSACTION, {
connectorId,
- idTag
- );
+ idTag,
+ });
PerformanceStatistics.endMeasure(measureId, beginId);
return startResponse;
}
}
logger.info(this.logPrefix(connectorId) + ' start transaction for idTag ' + idTag);
// Start transaction
- startResponse = await this.chargingStation.ocppRequestService.sendStartTransaction(
+ startResponse = await this.chargingStation.ocppRequestService.requestHandler<
+ StartTransactionRequest,
+ StartTransactionResponse
+ >(RequestCommand.START_TRANSACTION, {
connectorId,
- idTag
- );
+ idTag,
+ });
PerformanceStatistics.endMeasure(measureId, beginId);
return startResponse;
}
logger.info(this.logPrefix(connectorId) + ' start transaction without an idTag');
- startResponse = await this.chargingStation.ocppRequestService.sendStartTransaction(connectorId);
+ startResponse = await this.chargingStation.ocppRequestService.requestHandler<
+ StartTransactionRequest,
+ StartTransactionResponse
+ >(RequestCommand.START_TRANSACTION, { connectorId });
PerformanceStatistics.endMeasure(measureId, beginId);
return startResponse;
}
let stopResponse: StopTransactionResponse;
if (this.chargingStation.getConnectorStatus(connectorId)?.transactionStarted) {
transactionId = this.chargingStation.getConnectorStatus(connectorId).transactionId;
- stopResponse = await this.chargingStation.ocppRequestService.sendStopTransaction(
+ 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.requestHandler<
+ MeterValuesRequest,
+ MeterValuesResponse
+ >(RequestCommand.METER_VALUES, {
+ connectorId,
+ transactionId,
+ meterValue: transactionEndMeterValue,
+ });
+ }
+ stopResponse = await this.chargingStation.ocppRequestService.requestHandler<
+ StopTransactionRequest,
+ StopTransactionResponse
+ >(RequestCommand.STOP_TRANSACTION, {
transactionId,
- this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
- this.chargingStation.getTransactionIdTag(transactionId),
- reason
- );
+ meterStop: this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
+ idTag: this.chargingStation.getTransactionIdTag(transactionId),
+ reason,
+ });
this.connectorsStatus.get(connectorId).stopTransactionRequests++;
} else {
logger.warn(