-// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import { AsyncResource } from 'async_hooks';
-// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import path from 'path';
import { fileURLToPath } from 'url';
-// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import crypto from 'crypto';
import fs from 'fs';
import OCPP16RequestService from './ocpp/1.6/OCPP16RequestService';
import OCPP16ResponseService from './ocpp/1.6/OCPP16ResponseService';
import { OCPP16ServiceUtils } from './ocpp/1.6/OCPP16ServiceUtils';
+import OCPP20IncomingRequestService from './ocpp/2.0/OCPP20IncomingRequestService';
+import OCPP20RequestService from './ocpp/2.0/OCPP20RequestService';
+import OCPP20ResponseService from './ocpp/2.0/OCPP20ResponseService';
import type OCPPIncomingRequestService from './ocpp/OCPPIncomingRequestService';
import type OCPPRequestService from './ocpp/OCPPRequestService';
import SharedLRUCache from './SharedLRUCache';
if (params?.terminateOpened) {
this.terminateWSConnection();
}
+ const ocppVersion = this.getOcppVersion();
let protocol: string;
- switch (this.getOcppVersion()) {
+ switch (ocppVersion) {
case OCPPVersion.VERSION_16:
- protocol = 'ocpp' + OCPPVersion.VERSION_16;
+ case OCPPVersion.VERSION_20:
+ case OCPPVersion.VERSION_201:
+ protocol = 'ocpp' + ocppVersion;
break;
default:
- this.handleUnsupportedVersion(this.getOcppVersion());
+ this.handleUnsupportedVersion(ocppVersion);
break;
}
OCPP16ResponseService.getInstance<OCPP16ResponseService>()
);
break;
+ case OCPPVersion.VERSION_20:
+ case OCPPVersion.VERSION_201:
+ this.ocppIncomingRequestService =
+ OCPP20IncomingRequestService.getInstance<OCPP20IncomingRequestService>();
+ this.ocppRequestService = OCPP20RequestService.getInstance<OCPP20RequestService>(
+ OCPP20ResponseService.getInstance<OCPP20ResponseService>()
+ );
+ break;
default:
this.handleUnsupportedVersion(this.getOcppVersion());
break;
-// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import { parentPort, workerData } from 'worker_threads';
}
if (requestPayload?.hashId !== undefined) {
logger.error(
- `${this.chargingStation.logPrefix()} ${moduleName}.requestHandler: 'hashId' field usage in PDU is deprecated, use 'hashIds' instead`
+ `${this.chargingStation.logPrefix()} ${moduleName}.requestHandler: 'hashId' field usage in PDU is deprecated, use 'hashIds' array instead`
);
return;
}
-// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import fs from 'fs';
import path from 'path';
-// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import fs from 'fs';
import path from 'path';
-// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import fs from 'fs';
import path from 'path';
-// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import OCPPError from '../../../exception/OCPPError';
import { CurrentType, Voltage } from '../../../types/ChargingStationTemplate';
-// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import type { JSONSchemaType } from 'ajv';
-// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import type { JSONSchemaType } from 'ajv';
-// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import type { JSONSchemaType } from 'ajv';
-// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import { OCPPServiceUtils } from '../OCPPServiceUtils';
// Check if wsConnection opened
if (chargingStation.isWebSocketConnectionOpened() === true) {
// Yes: Send Message
- const beginId = PerformanceStatistics.beginMeasure(commandName);
+ const beginId = PerformanceStatistics.beginMeasure(commandName as string);
// FIXME: Handle sending error
chargingStation.wsConnection.send(messageToSend);
- PerformanceStatistics.endMeasure(commandName, beginId);
+ PerformanceStatistics.endMeasure(commandName as string, beginId);
logger.debug(
`${chargingStation.logPrefix()} >> Command '${commandName}' sent ${this.getMessageTypeString(
messageType
chargingStation: ChargingStation,
command: RequestCommand
): boolean {
- const isRequestCommand = Object.values(RequestCommand).includes(command);
+ const isRequestCommand = Object.values<RequestCommand>(RequestCommand).includes(command);
if (
isRequestCommand === true &&
!chargingStation.stationInfo?.commandsSupport?.outgoingCommands
chargingStation: ChargingStation,
command: IncomingRequestCommand
): boolean {
- const isIncomingRequestCommand = Object.values(IncomingRequestCommand).includes(command);
+ const isIncomingRequestCommand =
+ Object.values<IncomingRequestCommand>(IncomingRequestCommand).includes(command);
if (
isIncomingRequestCommand === true &&
!chargingStation.stationInfo?.commandsSupport?.incomingCommands
-// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import type { JsonType } from '../types/JsonType';
import { ErrorType } from '../types/ocpp/ErrorType';
-// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import { PerformanceEntry, PerformanceObserver, performance } from 'perf_hooks';
import type { URL } from 'url';
-// Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import fs from 'fs';
-// Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import { Configuration, Connection, IDatabaseDriver, MikroORM, Options } from '@mikro-orm/core';
import { TsMorphMetadataProvider } from '@mikro-orm/reflection';
-// Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import { MongoClient } from 'mongodb';
-// Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import { URL } from 'url';
-// Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import { StorageType } from '../../types/Storage';
import { JsonFileStorage } from './JsonFileStorage';
-// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import chalk from 'chalk';
PERFORMANCE_STATISTICS = 'performanceStatistics',
}
-export type ChargingStationWorkerMessageEvents = WorkerMessageEvents | ChargingStationMessageEvents;
-
export const ChargingStationWorkerMessageEvents = {
...WorkerMessageEvents,
...ChargingStationMessageEvents,
-};
+} as const;
+export type ChargingStationWorkerMessageEvents = WorkerMessageEvents | ChargingStationMessageEvents;
export type ChargingStationWorkerMessageData = ChargingStationData | Statistics;
performanceStorage?: StorageConfiguration;
worker?: WorkerConfiguration;
autoReconnectMaxRetries?: number;
- // deprecated
+ /** @deprecated Moved to worker configuration section. */
workerProcess?: WorkerProcessType;
- // deprecated
+ /** @deprecated Moved to worker configuration section. */
workerStartDelay?: number;
- // deprecated
+ /** @deprecated Moved to worker configuration section. */
elementStartDelay?: number;
- // deprecated
+ /** @deprecated Moved to worker configuration section. */
workerPoolMinSize?: number;
- // deprecated
+ /** @deprecated Moved to worker configuration section. */
workerPoolMaxSize?: number;
- // deprecated
+ /** @deprecated Moved to worker configuration section. */
workerPoolStrategy?: WorkerChoiceStrategy;
- // deprecated
+ /** @deprecated Moved to worker configuration section. */
chargingStationsPerWorker?: number;
logStatisticsInterval?: number;
logFormat?: string;
uri: string;
createdAt: Date;
updatedAt?: Date;
- statisticsData: Map<string, Partial<StatisticsData>>;
+ statisticsData: Map<string | RequestCommand | IncomingRequestCommand, Partial<StatisticsData>>;
};
import { OCPP16ChargePointErrorCode } from './1.6/ChargePointErrorCode';
-export type ChargePointErrorCode = OCPP16ChargePointErrorCode;
-
export const ChargePointErrorCode = {
...OCPP16ChargePointErrorCode,
-};
+} as const;
+export type ChargePointErrorCode = OCPP16ChargePointErrorCode;
import { OCPP16ChargePointStatus } from './1.6/ChargePointStatus';
-export type ChargePointStatus = OCPP16ChargePointStatus;
-
export const ChargePointStatus = {
...OCPP16ChargePointStatus,
-};
+} as const;
+export type ChargePointStatus = OCPP16ChargePointStatus;
export type ChargingSchedulePeriod = OCPP16ChargingSchedulePeriod;
-export type ChargingRateUnitType = OCPP16ChargingRateUnitType;
-
export const ChargingRateUnitType = {
...OCPP16ChargingRateUnitType,
-};
+} as const;
+export type ChargingRateUnitType = OCPP16ChargingRateUnitType;
OCPP16VendorDefaultParametersKey,
} from './1.6/Configuration';
-export type StandardParametersKey = OCPP16StandardParametersKey;
-
export const StandardParametersKey = {
...OCPP16StandardParametersKey,
-};
-
-export type VendorDefaultParametersKey = OCPP16VendorDefaultParametersKey;
+} as const;
+export type StandardParametersKey = OCPP16StandardParametersKey;
export const VendorDefaultParametersKey = {
...OCPP16VendorDefaultParametersKey,
-};
-
-export type SupportedFeatureProfiles = OCPP16SupportedFeatureProfiles;
+} as const;
+export type VendorDefaultParametersKey = OCPP16VendorDefaultParametersKey;
export const SupportedFeatureProfiles = {
...OCPP16SupportedFeatureProfiles,
-};
+} as const;
+export type SupportedFeatureProfiles = OCPP16SupportedFeatureProfiles;
export enum ConnectorPhaseRotation {
NotApplicable = 'NotApplicable',
import {
- OCPP16MeterValue,
+ type OCPP16MeterValue,
OCPP16MeterValueMeasurand,
OCPP16MeterValuePhase,
- OCPP16SampledValue,
+ type OCPP16SampledValue,
} from './1.6/MeterValues';
-export type MeterValueMeasurand = OCPP16MeterValueMeasurand;
-
export const MeterValueMeasurand = {
...OCPP16MeterValueMeasurand,
-};
-
-export type MeterValuePhase = OCPP16MeterValuePhase;
+} as const;
+export type MeterValueMeasurand = OCPP16MeterValueMeasurand;
export const MeterValuePhase = {
...OCPP16MeterValuePhase,
-};
+} as const;
+export type MeterValuePhase = OCPP16MeterValuePhase;
export type SampledValue = OCPP16SampledValue;
export enum OCPPVersion {
VERSION_16 = '1.6',
VERSION_20 = '2.0',
+ VERSION_201 = '2.0.1',
}
import { OCPP20IncomingRequestCommand, OCPP20RequestCommand } from './2.0/Requests';
import type { MessageType } from './MessageType';
-export type RequestCommand = OCPP16RequestCommand;
-
export const RequestCommand = {
...OCPP16RequestCommand,
...OCPP20RequestCommand,
-};
+} as const;
+export type RequestCommand = OCPP16RequestCommand | OCPP20RequestCommand;
export type OutgoingRequest = [MessageType.CALL_MESSAGE, string, RequestCommand, JsonType];
triggerMessage?: boolean;
};
-export type IncomingRequestCommand = OCPP16IncomingRequestCommand;
-
export const IncomingRequestCommand = {
...OCPP16IncomingRequestCommand,
...OCPP20IncomingRequestCommand,
-};
+} as const;
+export type IncomingRequestCommand = OCPP16IncomingRequestCommand | OCPP20IncomingRequestCommand;
export type IncomingRequest = [MessageType.CALL_MESSAGE, string, IncomingRequestCommand, JsonType];
JsonType
];
-export type MessageTrigger = OCPP16MessageTrigger;
-
export const MessageTrigger = {
...OCPP16MessageTrigger,
-};
+} as const;
+export type MessageTrigger = OCPP16MessageTrigger;
export type BootNotificationRequest = OCPP16BootNotificationRequest;
commandPayload: JsonType
) => JsonType | Promise<JsonType>;
-export type AvailabilityType = OCPP16AvailabilityType;
-
export const AvailabilityType = {
...OCPP16AvailabilityType,
-};
-
-export type DiagnosticsStatus = OCPP16DiagnosticsStatus;
+} as const;
+export type AvailabilityType = OCPP16AvailabilityType;
export const DiagnosticsStatus = {
...OCPP16DiagnosticsStatus,
-};
+} as const;
+export type DiagnosticsStatus = OCPP16DiagnosticsStatus;
export type ResponseType = JsonType | OCPPError;
import type { OCPP16MeterValuesResponse } from './1.6/MeterValues';
import {
OCPP16AvailabilityStatus,
- OCPP16BootNotificationResponse,
+ type OCPP16BootNotificationResponse,
OCPP16ChargingProfileStatus,
OCPP16ClearChargingProfileStatus,
OCPP16ConfigurationStatus,
- OCPP16DataTransferResponse,
+ type OCPP16DataTransferResponse,
OCPP16DataTransferStatus,
- OCPP16HeartbeatResponse,
+ type OCPP16HeartbeatResponse,
OCPP16RegistrationStatus,
- OCPP16StatusNotificationResponse,
+ type OCPP16StatusNotificationResponse,
OCPP16TriggerMessageStatus,
OCPP16UnlockStatus,
} from './1.6/Responses';
status: DefaultStatus;
};
-export type RegistrationStatus = OCPP16RegistrationStatus;
-
export const RegistrationStatus = {
...OCPP16RegistrationStatus,
-};
-
-export type AvailabilityStatus = OCPP16AvailabilityStatus;
+} as const;
+export type RegistrationStatus = OCPP16RegistrationStatus;
export const AvailabilityStatus = {
...OCPP16AvailabilityStatus,
-};
-
-export type ChargingProfileStatus = OCPP16ChargingProfileStatus;
+} as const;
+export type AvailabilityStatus = OCPP16AvailabilityStatus;
export const ChargingProfileStatus = {
...OCPP16ChargingProfileStatus,
-};
-
-export type ClearChargingProfileStatus = OCPP16ClearChargingProfileStatus;
+} as const;
+export type ChargingProfileStatus = OCPP16ChargingProfileStatus;
export const ClearChargingProfileStatus = {
...OCPP16ClearChargingProfileStatus,
-};
-
-export type ConfigurationStatus = OCPP16ConfigurationStatus;
+} as const;
+export type ClearChargingProfileStatus = OCPP16ClearChargingProfileStatus;
export const ConfigurationStatus = {
...OCPP16ConfigurationStatus,
-};
-
-export type UnlockStatus = OCPP16UnlockStatus;
+} as const;
+export type ConfigurationStatus = OCPP16ConfigurationStatus;
export const UnlockStatus = {
...OCPP16UnlockStatus,
-};
-
-export type TriggerMessageStatus = OCPP16TriggerMessageStatus;
+} as const;
+export type UnlockStatus = OCPP16UnlockStatus;
export const TriggerMessageStatus = {
...OCPP16TriggerMessageStatus,
-};
-
-export type DataTransferStatus = OCPP16DataTransferStatus;
+} as const;
+export type TriggerMessageStatus = OCPP16TriggerMessageStatus;
export const DataTransferStatus = {
...OCPP16DataTransferStatus,
-};
+} as const;
+export type DataTransferStatus = OCPP16DataTransferStatus;
import {
OCPP16AuthorizationStatus,
- OCPP16AuthorizeRequest,
- OCPP16AuthorizeResponse,
- OCPP16StartTransactionRequest,
- OCPP16StartTransactionResponse,
+ type OCPP16AuthorizeRequest,
+ type OCPP16AuthorizeResponse,
+ type OCPP16StartTransactionRequest,
+ type OCPP16StartTransactionResponse,
OCPP16StopTransactionReason,
- OCPP16StopTransactionRequest,
- OCPP16StopTransactionResponse,
+ type OCPP16StopTransactionRequest,
+ type OCPP16StopTransactionResponse,
} from './1.6/Transaction';
-export type AuthorizationStatus = OCPP16AuthorizationStatus;
-
export const AuthorizationStatus = {
...OCPP16AuthorizationStatus,
-};
+} as const;
+export type AuthorizationStatus = OCPP16AuthorizationStatus;
export type AuthorizeRequest = OCPP16AuthorizeRequest;
export type AuthorizeResponse = OCPP16AuthorizeResponse;
-export type StopTransactionReason = OCPP16StopTransactionReason;
-
export const StopTransactionReason = {
...OCPP16StopTransactionReason,
-};
+} as const;
+export type StopTransactionReason = OCPP16StopTransactionReason;
export type StartTransactionRequest = OCPP16StartTransactionRequest;
-// Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
export const DEFAULT_CIRCULAR_ARRAY_SIZE = Number.MAX_SAFE_INTEGER;
-// Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
/**
* Rationale: https://wiki.piment-noir.org/doku.php/en:cs:modelling_multi-phased_electrical_system_interconnexion
}
public static JSONStringifyWithMapSupport(
- obj: Record<string, unknown> | Record<string, unknown>[] | Map<string, unknown>,
+ obj: Record<string, unknown> | Record<string, unknown>[] | Map<unknown, unknown>,
space?: number
): string {
return JSON.stringify(
-// Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
+// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
import { Worker } from 'worker_threads';
TRIGGER_MESSAGE = 'TriggerMessage',
}
-export type IncomingRequestCommand = OCPP16IncomingRequestCommand;
-
export const IncomingRequestCommand = {
...OCPP16IncomingRequestCommand,
-};
+} as const;
+export type IncomingRequestCommand = OCPP16IncomingRequestCommand;
export enum OCPP16RequestCommand {
BOOT_NOTIFICATION = 'BootNotification',
DIAGNOSTICS_STATUS_NOTIFICATION = 'DiagnosticsStatusNotification',
}
-export type RequestCommand = OCPP16RequestCommand;
-
export const RequestCommand = {
...OCPP16RequestCommand,
-};
+} as const;
+export type RequestCommand = OCPP16RequestCommand;
export type BootNotificationResponse = OCPP16BootNotificationResponse;
StatusNotification = 'StatusNotification',
}
-export type MessageTrigger = OCPP16MessageTrigger;
-
export const MessageTrigger = {
...OCPP16MessageTrigger,
-};
+} as const;
+export type MessageTrigger = OCPP16MessageTrigger;
type CommandsSupport = {
incomingCommands: Record<IncomingRequestCommand, boolean>;