Merge branch 'main' into reservation-feature
[e-mobility-charging-stations-simulator.git] / src / charging-station / ocpp / 1.6 / OCPP16ResponseService.ts
index 889b0235ed4536d9cd6b9925ff7d75f2ce419154..9e8a2d5f7636a33aba59c198a8a7e337cea8f0bf 100644 (file)
@@ -4,11 +4,11 @@ import { parentPort } from 'node:worker_threads';
 
 import type { JSONSchemaType } from 'ajv';
 
+import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
 import {
   type ChargingStation,
   ChargingStationConfigurationUtils,
   ChargingStationUtils,
-  MessageChannelUtils,
 } from '../../../charging-station';
 import { OCPPError } from '../../../exception';
 import {
@@ -25,6 +25,7 @@ import {
   type OCPP16AuthorizeRequest,
   type OCPP16AuthorizeResponse,
   type OCPP16BootNotificationResponse,
+  type OCPP16CancelReservationResponse,
   OCPP16ChargePointStatus,
   type OCPP16DataTransferResponse,
   type OCPP16DiagnosticsStatusNotificationResponse,
@@ -35,6 +36,7 @@ import {
   type OCPP16MeterValuesRequest,
   type OCPP16MeterValuesResponse,
   OCPP16RequestCommand,
+  type OCPP16ReserveNowResponse,
   OCPP16StandardParametersKey,
   type OCPP16StartTransactionRequest,
   type OCPP16StartTransactionResponse,
@@ -49,8 +51,8 @@ import {
   type SetChargingProfileResponse,
   type UnlockConnectorResponse,
 } from '../../../types';
-import { Constants, Utils, logger } from '../../../utils';
-import { OCPP16ServiceUtils, OCPPResponseService } from '../internal';
+import { Constants, Utils, buildUpdatedMessage, logger } from '../../../utils';
+import { OCPPResponseService } from '../OCPPResponseService';
 
 const moduleName = 'OCPP16ResponseService';
 
@@ -84,7 +86,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16RequestCommand.BOOT_NOTIFICATION,
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16BootNotificationResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/BootNotificationResponse.json',
+          'assets/json-schemas/ocpp/1.6/BootNotificationResponse.json',
           moduleName,
           'constructor'
         ),
@@ -92,7 +94,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16RequestCommand.HEARTBEAT,
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16HeartbeatResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/HeartbeatResponse.json',
+          'assets/json-schemas/ocpp/1.6/HeartbeatResponse.json',
           moduleName,
           'constructor'
         ),
@@ -100,7 +102,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16RequestCommand.AUTHORIZE,
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16AuthorizeResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/AuthorizeResponse.json',
+          'assets/json-schemas/ocpp/1.6/AuthorizeResponse.json',
           moduleName,
           'constructor'
         ),
@@ -108,7 +110,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16RequestCommand.START_TRANSACTION,
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StartTransactionResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/StartTransactionResponse.json',
+          'assets/json-schemas/ocpp/1.6/StartTransactionResponse.json',
           moduleName,
           'constructor'
         ),
@@ -116,7 +118,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16RequestCommand.STOP_TRANSACTION,
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StopTransactionResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/StopTransactionResponse.json',
+          'assets/json-schemas/ocpp/1.6/StopTransactionResponse.json',
           moduleName,
           'constructor'
         ),
@@ -124,7 +126,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16RequestCommand.STATUS_NOTIFICATION,
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16StatusNotificationResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/StatusNotificationResponse.json',
+          'assets/json-schemas/ocpp/1.6/StatusNotificationResponse.json',
           moduleName,
           'constructor'
         ),
@@ -132,7 +134,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16RequestCommand.METER_VALUES,
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16MeterValuesResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/MeterValuesResponse.json',
+          'assets/json-schemas/ocpp/1.6/MeterValuesResponse.json',
           moduleName,
           'constructor'
         ),
@@ -140,7 +142,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION,
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DiagnosticsStatusNotificationResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/DiagnosticsStatusNotificationResponse.json',
+          'assets/json-schemas/ocpp/1.6/DiagnosticsStatusNotificationResponse.json',
           moduleName,
           'constructor'
         ),
@@ -148,7 +150,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16RequestCommand.DATA_TRANSFER,
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DataTransferResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/DataTransferResponse.json',
+          'assets/json-schemas/ocpp/1.6/DataTransferResponse.json',
           moduleName,
           'constructor'
         ),
@@ -156,7 +158,23 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION,
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16FirmwareStatusNotificationResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/FirmwareStatusNotificationResponse.json',
+          'assets/json-schemas/ocpp/1.6/FirmwareStatusNotificationResponse.json',
+          moduleName,
+          'constructor'
+        ),
+      ],
+      [
+        OCPP16RequestCommand.RESERVE_NOW,
+        OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16ReserveNowResponse>(
+          'assets/json-schemas/ocpp/1.6/ReserveNowResponse.json',
+          moduleName,
+          'constructor'
+        ),
+      ],
+      [
+        OCPP16RequestCommand.CANCEL_RESERVATION,
+        OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16CancelReservationResponse>(
+          'assets/json-schemas/ocpp/1.6/CancelReservationResponse.json',
           moduleName,
           'constructor'
         ),
@@ -166,7 +184,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16IncomingRequestCommand.RESET,
         OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/ResetResponse.json',
+          'assets/json-schemas/ocpp/1.6/ResetResponse.json',
           moduleName,
           'constructor'
         ),
@@ -174,7 +192,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16IncomingRequestCommand.CLEAR_CACHE,
         OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/ClearCacheResponse.json',
+          'assets/json-schemas/ocpp/1.6/ClearCacheResponse.json',
           moduleName,
           'constructor'
         ),
@@ -182,7 +200,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16IncomingRequestCommand.CHANGE_AVAILABILITY,
         OCPP16ServiceUtils.parseJsonSchemaFile<ChangeAvailabilityResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/ChangeAvailabilityResponse.json',
+          'assets/json-schemas/ocpp/1.6/ChangeAvailabilityResponse.json',
           moduleName,
           'constructor'
         ),
@@ -190,7 +208,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16IncomingRequestCommand.UNLOCK_CONNECTOR,
         OCPP16ServiceUtils.parseJsonSchemaFile<UnlockConnectorResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/UnlockConnectorResponse.json',
+          'assets/json-schemas/ocpp/1.6/UnlockConnectorResponse.json',
           moduleName,
           'constructor'
         ),
@@ -198,7 +216,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16IncomingRequestCommand.GET_CONFIGURATION,
         OCPP16ServiceUtils.parseJsonSchemaFile<GetConfigurationResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/GetConfigurationResponse.json',
+          'assets/json-schemas/ocpp/1.6/GetConfigurationResponse.json',
           moduleName,
           'constructor'
         ),
@@ -206,7 +224,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16IncomingRequestCommand.CHANGE_CONFIGURATION,
         OCPP16ServiceUtils.parseJsonSchemaFile<ChangeConfigurationResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/ChangeConfigurationResponse.json',
+          'assets/json-schemas/ocpp/1.6/ChangeConfigurationResponse.json',
           moduleName,
           'constructor'
         ),
@@ -214,7 +232,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16IncomingRequestCommand.GET_COMPOSITE_SCHEDULE,
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16GetCompositeScheduleResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/GetCompositeScheduleResponse.json',
+          'assets/json-schemas/ocpp/1.6/GetCompositeScheduleResponse.json',
           moduleName,
           'constructor'
         ),
@@ -222,7 +240,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16IncomingRequestCommand.SET_CHARGING_PROFILE,
         OCPP16ServiceUtils.parseJsonSchemaFile<SetChargingProfileResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/SetChargingProfileResponse.json',
+          'assets/json-schemas/ocpp/1.6/SetChargingProfileResponse.json',
           moduleName,
           'constructor'
         ),
@@ -230,7 +248,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16IncomingRequestCommand.CLEAR_CHARGING_PROFILE,
         OCPP16ServiceUtils.parseJsonSchemaFile<ClearChargingProfileResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/ClearChargingProfileResponse.json',
+          'assets/json-schemas/ocpp/1.6/ClearChargingProfileResponse.json',
           moduleName,
           'constructor'
         ),
@@ -238,7 +256,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16IncomingRequestCommand.REMOTE_START_TRANSACTION,
         OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/RemoteStartTransactionResponse.json',
+          'assets/json-schemas/ocpp/1.6/RemoteStartTransactionResponse.json',
           moduleName,
           'constructor'
         ),
@@ -246,7 +264,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16IncomingRequestCommand.REMOTE_STOP_TRANSACTION,
         OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/RemoteStopTransactionResponse.json',
+          'assets/json-schemas/ocpp/1.6/RemoteStopTransactionResponse.json',
           moduleName,
           'constructor'
         ),
@@ -254,7 +272,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16IncomingRequestCommand.GET_DIAGNOSTICS,
         OCPP16ServiceUtils.parseJsonSchemaFile<GetDiagnosticsResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/GetDiagnosticsResponse.json',
+          'assets/json-schemas/ocpp/1.6/GetDiagnosticsResponse.json',
           moduleName,
           'constructor'
         ),
@@ -262,7 +280,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16IncomingRequestCommand.TRIGGER_MESSAGE,
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16TriggerMessageResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/TriggerMessageResponse.json',
+          'assets/json-schemas/ocpp/1.6/TriggerMessageResponse.json',
           moduleName,
           'constructor'
         ),
@@ -270,7 +288,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16IncomingRequestCommand.DATA_TRANSFER,
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16DataTransferResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/DataTransferResponse.json',
+          'assets/json-schemas/ocpp/1.6/DataTransferResponse.json',
           moduleName,
           'constructor'
         ),
@@ -278,7 +296,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       [
         OCPP16IncomingRequestCommand.UPDATE_FIRMWARE,
         OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16UpdateFirmwareResponse>(
-          '../../../assets/json-schemas/ocpp/1.6/UpdateFirmwareResponse.json',
+          'assets/json-schemas/ocpp/1.6/UpdateFirmwareResponse.json',
           moduleName,
           'constructor'
         ),
@@ -612,7 +630,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
         }#${transactionConnectorId.toString()} for idTag '${requestPayload.idTag}'`
       );
       if (chargingStation.stationInfo.powerSharedByConnectors) {
-        chargingStation.powerDivider++;
+        ++chargingStation.powerDivider;
       }
       const configuredMeterValueSampleInterval =
         ChargingStationConfigurationUtils.getConfigurationKey(
@@ -641,7 +659,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
   ): Promise<void> {
     ChargingStationUtils.resetConnectorStatus(chargingStation.getConnectorStatus(connectorId));
     chargingStation.stopMeterValues(connectorId);
-    parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(chargingStation));
+    parentPort?.postMessage(buildUpdatedMessage(chargingStation));
     if (
       chargingStation.getConnectorStatus(connectorId)?.status !== OCPP16ChargePointStatus.Available
     ) {
@@ -707,7 +725,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
       chargingStation.getConnectorStatus(transactionConnectorId)
     );
     chargingStation.stopMeterValues(transactionConnectorId);
-    parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(chargingStation));
+    parentPort?.postMessage(buildUpdatedMessage(chargingStation));
     const logMsg = `${chargingStation.logPrefix()} Transaction with id ${requestPayload.transactionId.toString()} STOPPED on ${
       chargingStation.stationInfo.chargingStationId
     }#${transactionConnectorId?.toString()} with status '${