import type { JSONSchemaType } from 'ajv';
-import { OCPP16Constants } from './OCPP16Constants';
-import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
-import type { ChargingStation } from '../../../charging-station';
-import { OCPPError } from '../../../exception';
+import { OCPP16Constants } from './OCPP16Constants.js';
+import { OCPP16ServiceUtils } from './OCPP16ServiceUtils.js';
+import type { ChargingStation } from '../../../charging-station/index.js';
+import { OCPPError } from '../../../exception/index.js';
import {
ErrorType,
type JsonObject,
type JsonType,
type OCPP16AuthorizeRequest,
type OCPP16BootNotificationRequest,
+ OCPP16ChargePointStatus,
type OCPP16DataTransferRequest,
type OCPP16DiagnosticsStatusNotificationRequest,
type OCPP16FirmwareStatusNotificationRequest,
type OCPP16StopTransactionRequest,
OCPPVersion,
type RequestParams,
-} from '../../../types';
-import { Constants, generateUUID } from '../../../utils';
-import { OCPPRequestService } from '../OCPPRequestService';
-import type { OCPPResponseService } from '../OCPPResponseService';
+} from '../../../types/index.js';
+import { Constants, generateUUID } from '../../../utils/index.js';
+import { OCPPRequestService } from '../OCPPRequestService.js';
+import type { OCPPResponseService } from '../OCPPResponseService.js';
const moduleName = 'OCPP16RequestService';
export class OCPP16RequestService extends OCPPRequestService {
- protected jsonSchemas: Map<OCPP16RequestCommand, JSONSchemaType<JsonObject>>;
+ protected jsonSchemas: Map<OCPP16RequestCommand, JSONSchemaType<JsonType>>;
public constructor(ocppResponseService: OCPPResponseService) {
// if (new.target?.name === moduleName) {
// throw new TypeError(`Cannot construct ${new.target?.name} instances directly`);
// }
super(OCPPVersion.VERSION_16, ocppResponseService);
- this.jsonSchemas = new Map<OCPP16RequestCommand, JSONSchemaType<JsonObject>>([
+ this.jsonSchemas = new Map<OCPP16RequestCommand, JSONSchemaType<JsonType>>([
[
OCPP16RequestCommand.AUTHORIZE,
OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16AuthorizeRequest>(
commandName: OCPP16RequestCommand,
commandParams?: JsonType,
): Request {
- let connectorId: number;
+ let connectorId: number | undefined;
let energyActiveImportRegister: number;
commandParams = commandParams as JsonObject;
switch (commandName) {
true,
),
timestamp: new Date(),
+ ...(OCPP16ServiceUtils.hasReservation(
+ chargingStation,
+ commandParams?.connectorId as number,
+ commandParams?.idTag as string,
+ ) && {
+ reservationId: chargingStation.getReservationBy(
+ 'connectorId',
+ chargingStation.getConnectorStatus(0)?.status === OCPP16ChargePointStatus.Reserved
+ ? 0
+ : (commandParams?.connectorId as number),
+ )!.reservationId,
+ }),
...commandParams,
} as unknown as Request;
case OCPP16RequestCommand.STOP_TRANSACTION:
- chargingStation.getTransactionDataMeterValues() &&
+ chargingStation.stationInfo?.transactionDataMeterValues &&
(connectorId = chargingStation.getConnectorIdByTransactionId(
commandParams?.transactionId as number,
- ));
+ )!);
energyActiveImportRegister = chargingStation.getEnergyActiveImportRegisterByTransactionId(
commandParams?.transactionId as number,
true,
idTag: chargingStation.getTransactionIdTag(commandParams?.transactionId as number),
meterStop: energyActiveImportRegister,
timestamp: new Date(),
- ...(chargingStation.getTransactionDataMeterValues() && {
+ ...(chargingStation.stationInfo?.transactionDataMeterValues && {
transactionData: OCPP16ServiceUtils.buildTransactionDataMeterValues(
- chargingStation.getConnectorStatus(connectorId).transactionBeginMeterValue,
+ chargingStation.getConnectorStatus(connectorId!)!.transactionBeginMeterValue!,
OCPP16ServiceUtils.buildTransactionEndMeterValue(
chargingStation,
- connectorId,
+ connectorId!,
energyActiveImportRegister,
),
),