**src/assets/config.json**:
-| Key | Value(s) | Default Value | Value type | Description |
-| -------------------------- | -------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
-| supervisionUrls | | [] | string \| string[] | string or strings array containing global connection URIs to OCPP-J servers |
-| supervisionUrlDistribution | round-robin/random/charging-station-affinity | charging-station-affinity | string | supervision urls distribution policy to simulated charging stations |
-| log | | {<br />"enabled": true,<br />"file": "logs/combined.log",<br />"errorFile": "logs/error.log",<br />"statisticsInterval": 60,<br />"level": "info",<br />"console": false,<br />"format": "simple",<br />"rotate": true<br />} | {<br />enabled: boolean;<br />file: string;<br />errorFile: string;<br />statisticsInterval: number;<br />level: string;<br />console: boolean;<br />format: string;<br />rotate: boolean;<br />maxFiles: string \| number;<br />maxSize: string \| number;<br />} | Log configuration section:<br />- _enabled_: enable logging<br />- _file_: log file relative path<br />- _errorFile_: error log file relative path<br />- _statisticsInterval_: seconds between charging stations statistics output in the logs<br />- _level_: emerg/alert/crit/error/warning/notice/info/debug [winston](https://github.com/winstonjs/winston) logging level</br >- _console_: output logs on the console<br />- _format_: [winston](https://github.com/winstonjs/winston) log format<br />- _rotate_: enable daily log files rotation<br />- _maxFiles_: maximum number of log files: https://github.com/winstonjs/winston-daily-rotate-file#options<br />- _maxSize_: maximum size of log files in bytes, or units of kb, mb, and gb: https://github.com/winstonjs/winston-daily-rotate-file#options |
-| worker | | {<br />"processType": "workerSet",<br />"startDelay": 500,<br />"elementStartDelay": 0,<br />"elementsPerWorker": 'auto',<br />"poolMinSize": 4,<br />"poolMaxSize": 16<br />} | {<br />processType: WorkerProcessType;<br />startDelay: number;<br />elementStartDelay: number;<br />elementsPerWorker: number \| 'auto';<br />poolMinSize: number;<br />poolMaxSize: number;<br />} | Worker configuration section:<br />- _processType_: worker threads process type (`workerSet`/`staticPool`/`dynamicPool`)<br />- _startDelay_: milliseconds to wait at worker threads startup (only for `workerSet` worker threads process type)<br />- _elementStartDelay_: milliseconds to wait at charging station startup<br />- _elementsPerWorker_: number of charging stations per worker threads for the `workerSet` process type (`auto` means (number of stations) / (number of CPUs) \* 1.5 if (number of stations) > (number of CPUs), otherwise 1)<br />- _poolMinSize_: worker threads pool minimum number of threads</br >- _poolMaxSize_: worker threads pool maximum number of threads |
-| uiServer | | {<br />"enabled": false,<br />"type": "ws",<br />"options": {<br />"host": "localhost",<br />"port": 8080<br />}<br />} | {<br />enabled: boolean;<br />type: ApplicationProtocol;<br />options: ServerOptions;<br />authentication: {<br />enabled: boolean;<br />type: AuthenticationType;<br />username: string;<br />password: string;<br />}<br />} | UI server configuration section |
-| performanceStorage | | {<br />"enabled": false,<br />"type": "jsonfile",<br />"file:///performanceRecords.json"<br />} | {<br />enabled: boolean;<br />type: string;<br />URI: string;<br />}<br />where type can be 'jsonfile' or 'mongodb' | performance storage configuration section |
-| stationTemplateUrls | | {}[] | {<br />file: string;<br />numberOfStations: number;<br />}[] | array of charging station configuration templates URIs configuration section (charging station configuration template file name and number of stations) |
+| Key | Value(s) | Default Value | Value type | Description |
+| -------------------------- | -------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
+| supervisionUrls | | [] | string \| string[] | string or strings array containing global connection URIs to OCPP-J servers |
+| supervisionUrlDistribution | round-robin/random/charging-station-affinity | charging-station-affinity | string | supervision urls distribution policy to simulated charging stations |
+| log | | {<br />"enabled": true,<br />"file": "logs/combined.log",<br />"errorFile": "logs/error.log",<br />"statisticsInterval": 60,<br />"level": "info",<br />"console": false,<br />"format": "simple",<br />"rotate": true<br />} | {<br />enabled: boolean;<br />file: string;<br />errorFile: string;<br />statisticsInterval: number;<br />level: string;<br />console: boolean;<br />format: string;<br />rotate: boolean;<br />maxFiles: string \| number;<br />maxSize: string \| number;<br />} | Log configuration section:<br />- _enabled_: enable logging<br />- _file_: log file relative path<br />- _errorFile_: error log file relative path<br />- _statisticsInterval_: seconds between charging stations statistics output in the logs<br />- _level_: emerg/alert/crit/error/warning/notice/info/debug [winston](https://github.com/winstonjs/winston) logging level</br >- _console_: output logs on the console<br />- _format_: [winston](https://github.com/winstonjs/winston) log format<br />- _rotate_: enable daily log files rotation<br />- _maxFiles_: maximum number of log files: https://github.com/winstonjs/winston-daily-rotate-file#options<br />- _maxSize_: maximum size of log files in bytes, or units of kb, mb, and gb: https://github.com/winstonjs/winston-daily-rotate-file#options |
+| worker | | {<br />"processType": "workerSet",<br />"startDelay": 500,<br />"elementStartDelay": 0,<br />"elementsPerWorker": 'auto',<br />"poolMinSize": 4,<br />"poolMaxSize": 16<br />} | {<br />processType: WorkerProcessType;<br />startDelay: number;<br />elementStartDelay: number;<br />elementsPerWorker: number \| 'auto';<br />poolMinSize: number;<br />poolMaxSize: number;<br />} | Worker configuration section:<br />- _processType_: worker threads process type (`workerSet`/`staticPool`/`dynamicPool`)<br />- _startDelay_: milliseconds to wait at worker threads startup (only for `workerSet` worker threads process type)<br />- _elementStartDelay_: milliseconds to wait at charging station startup<br />- _elementsPerWorker_: number of charging stations per worker threads for the `workerSet` process type (`auto` means (number of stations) / (number of CPUs) \* 1.5 if (number of stations) > (number of CPUs), otherwise 1)<br />- _poolMinSize_: worker threads pool minimum number of threads</br >- _poolMaxSize_: worker threads pool maximum number of threads |
+| uiServer | | {<br />"enabled": false,<br />"type": "ws",<br />"options": {<br />"host": "localhost",<br />"port": 8080<br />}<br />} | {<br />enabled: boolean;<br />type: ApplicationProtocol;<br />version: ApplicationProtocolVersion;<br />options: ServerOptions;<br />authentication: {<br />enabled: boolean;<br />type: AuthenticationType;<br />username: string;<br />password: string;<br />}<br />} | UI server configuration sectio9n:<br />- _enabled_: enable UI server<br />- _type_: 'http' or 'ws'<br />- _version_: '1.1' or '2.0'<br />_options_: node.js net module [listen options](https://nodejs.org/api/net.html#serverlistenoptions-callback) |
+| performanceStorage | | {<br />"enabled": false,<br />"type": "jsonfile",<br />"file:///performanceRecords.json"<br />} | {<br />enabled: boolean;<br />type: string;<br />URI: string;<br />}<br />where type can be 'jsonfile' or 'mongodb' | performance storage configuration section |
+| stationTemplateUrls | | {}[] | {<br />file: string;<br />numberOfStations: number;<br />}[] | array of charging station configuration templates URIs configuration section (charging station configuration template file name and number of stations) |
#### Worker process model
public async start(): Promise<void> {
if (!isMainThread) {
- throw new Error('Cannot start charging stations simulator from worker thread');
+ throw new BaseError('Cannot start charging stations simulator from worker thread');
}
if (this.started === false) {
if (this.starting === false) {
public async stop(): Promise<void> {
if (!isMainThread) {
- throw new Error('Cannot stop charging stations simulator from worker thread');
+ throw new BaseError('Cannot stop charging stations simulator from worker thread');
}
if (this.started === true) {
if (this.stopping === false) {
import { ThreadWorker } from 'poolifier';
import { ChargingStation } from './ChargingStation';
+import { BaseError } from '../exception';
import type { ChargingStationWorkerData } from '../types';
import { Configuration } from '../utils';
import { POOL_MAX_INACTIVE_TIME, type WorkerMessage, WorkerMessageEvents } from '../worker';
}
break;
default:
- throw new Error(
+ throw new BaseError(
`Unknown worker event: '${message.event}' received with data: '${JSON.stringify(
message.data,
null,
import { type IncomingMessage, Server, type ServerResponse } from 'node:http';
+import { type Http2Server, createServer } from 'node:http2';
import type { WebSocket } from 'ws';
import { UIServiceFactory } from './ui-services/UIServiceFactory';
import { BaseError } from '../../exception';
import {
+ ApplicationProtocolVersion,
AuthenticationType,
type ChargingStationData,
type ProcedureName,
export abstract class AbstractUIServer {
public readonly chargingStations: Map<string, ChargingStationData>;
- protected readonly httpServer: Server;
+ protected readonly httpServer: Server | Http2Server;
protected readonly responseHandlers: Map<string, ServerResponse | WebSocket>;
protected readonly uiServices: Map<ProtocolVersion, AbstractUIService>;
public constructor(protected readonly uiServerConfiguration: UIServerConfiguration) {
this.chargingStations = new Map<string, ChargingStationData>();
- this.httpServer = new Server();
+ switch (this.uiServerConfiguration.version) {
+ case ApplicationProtocolVersion.VERSION_11:
+ this.httpServer = new Server();
+ break;
+ case ApplicationProtocolVersion.VERSION_20:
+ this.httpServer = createServer();
+ break;
+ default:
+ throw new BaseError(
+ `Unsupported application protocol version ${this.uiServerConfiguration.version}`,
+ );
+ }
this.responseHandlers = new Map<string, ServerResponse | WebSocket>();
this.uiServices = new Map<ProtocolVersion, AbstractUIService>();
}
import { UIServerUtils } from './UIServerUtils';
import { BaseError } from '../../exception';
import {
+ ApplicationProtocolVersion,
type ProcedureName,
type Protocol,
type ProtocolRequest,
this.startHttpServer();
}
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
public sendRequest(request: ProtocolRequest): void {
- // This is intentionally left blank
+ switch (this.uiServerConfiguration.version) {
+ case ApplicationProtocolVersion.VERSION_20:
+ this.httpServer.emit('request', request);
+ break;
+ }
}
public sendResponse(response: ProtocolResponse): void {
import { UIHttpServer } from './UIHttpServer';
import { UIServerUtils } from './UIServerUtils';
import { UIWebSocketServer } from './UIWebSocketServer';
-import { ApplicationProtocol, type UIServerConfiguration } from '../../types';
+import {
+ ApplicationProtocol,
+ ApplicationProtocolVersion,
+ type UIServerConfiguration,
+} from '../../types';
+import { isUndefined } from '../../utils';
export class UIServerFactory {
private constructor() {
),
);
}
+ uiServerConfiguration = {
+ ...(uiServerConfiguration.type === ApplicationProtocol.HTTP &&
+ isUndefined(uiServerConfiguration.version) && {
+ version: ApplicationProtocolVersion.VERSION_11,
+ }),
+ ...uiServerConfiguration,
+ };
switch (uiServerConfiguration.type) {
case ApplicationProtocol.WS:
return new UIWebSocketServer(uiServerConfiguration);
maxSize?: string | number;
}
+export enum ApplicationProtocolVersion {
+ VERSION_11 = 1.1,
+ VERSION_20 = 2.0,
+}
+
export interface UIServerConfiguration {
enabled?: boolean;
type?: ApplicationProtocol;
+ version?: ApplicationProtocolVersion;
options?: ServerOptions;
authentication?: {
enabled: boolean;
type WsOptions,
} from './ChargingStationTemplate';
export {
+ ApplicationProtocolVersion,
type ConfigurationData,
ConfigurationSection,
type LogConfiguration,