import chalk from 'chalk';
+import { ChargingStationUtils } from './ChargingStationUtils';
import type { AbstractUIServer } from './ui-server/AbstractUIServer';
import { UIServerFactory } from './ui-server/UIServerFactory';
import packageJson from '../../package.json' assert { type: 'json' };
Constants.EMPTY_FREEZED_OBJECT
)
);
- await this.waitForChargingStationsStopped();
+ await ChargingStationUtils.waitForChargingStationEvents(
+ this,
+ ChargingStationWorkerMessageEvents.stopped,
+ this.numberOfChargingStations
+ );
await this.workerImplementation?.stop();
this.workerImplementation = null;
this.uiServer?.stop();
});
};
- private waitForChargingStationsStopped = async (
- stoppedEventsToWait = this.numberOfStartedChargingStations
- ): Promise<number> => {
- return new Promise((resolve) => {
- let stoppedEvents = 0;
- if (stoppedEventsToWait === 0) {
- resolve(stoppedEvents);
- }
- this.on(ChargingStationWorkerMessageEvents.stopped, () => {
- ++stoppedEvents;
- if (stoppedEvents === stoppedEventsToWait) {
- resolve(stoppedEvents);
- }
- });
- });
- };
-
private logPrefix = (): string => {
return Utils.logPrefix(' Bootstrap |');
};
import crypto from 'node:crypto';
+import type EventEmitter from 'node:events';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
type ChargingSchedulePeriod,
type ChargingStationInfo,
type ChargingStationTemplate,
+ ChargingStationWorkerMessageEvents,
ConnectorPhaseRotation,
type ConnectorStatus,
ConnectorStatusEnum,
);
}
+ public static waitForChargingStationEvents = async (
+ emitter: EventEmitter,
+ event: ChargingStationWorkerMessageEvents,
+ eventsToWait: number
+ ): Promise<number> => {
+ return new Promise((resolve) => {
+ let events = 0;
+ if (eventsToWait === 0) {
+ resolve(events);
+ }
+ emitter.on(event, () => {
+ ++events;
+ if (events === eventsToWait) {
+ resolve(events);
+ }
+ });
+ });
+ };
+
private static getConfiguredNumberOfConnectors(stationTemplate: ChargingStationTemplate): number {
let configuredMaxConnectors: number;
if (Utils.isNotEmptyArray(stationTemplate.numberOfConnectors) === true) {
type OCPP16BootNotificationRequest,
type OCPP16BootNotificationResponse,
type OCPP16CancelReservationRequest,
- type OCPP16CancelReservationResponse,
OCPP16ChargePointErrorCode,
OCPP16ChargePointStatus,
type OCPP16ChargingProfile,
private async handleRequestCancelReservation(
chargingStation: ChargingStation,
commandPayload: OCPP16CancelReservationRequest
- ): Promise<OCPP16CancelReservationResponse> {
+ ): Promise<GenericResponse> {
if (
!OCPP16ServiceUtils.checkFeatureProfile(
chargingStation,
type OCPP16AuthorizeRequest,
type OCPP16AuthorizeResponse,
type OCPP16BootNotificationResponse,
- type OCPP16CancelReservationResponse,
OCPP16ChargePointStatus,
type OCPP16DataTransferResponse,
type OCPP16DiagnosticsStatusNotificationResponse,
],
[
OCPP16IncomingRequestCommand.CANCEL_RESERVATION,
- OCPP16ServiceUtils.parseJsonSchemaFile<OCPP16CancelReservationResponse>(
+ OCPP16ServiceUtils.parseJsonSchemaFile<GenericResponse>(
'assets/json-schemas/ocpp/1.6/CancelReservationResponse.json',
moduleName,
'constructor'
type SetChargingProfileResponse,
type UnlockConnectorResponse,
type OCPP16ReserveNowResponse,
- type OCPP16CancelReservationResponse,
} from './ocpp/1.6/Responses';
export { ChargePointErrorCode } from './ocpp/ChargePointErrorCode';
export {
data?: string;
}
-export interface OCPP16CancelReservationResponse extends JsonObject {
- status: GenericStatus;
-}
-
export enum OCPP16ReservationStatus {
ACCEPTED = 'Accepted',
FAULTED = 'Faulted',
import {
OCPP16AvailabilityStatus,
type OCPP16BootNotificationResponse,
- type OCPP16CancelReservationResponse,
OCPP16ChargingProfileStatus,
OCPP16ClearChargingProfileStatus,
OCPP16ConfigurationStatus,
...OCPP16ReservationStatus,
};
+export type CancelReservationStatus = GenericStatus;
export const CancelReservationStatus = {
...GenericStatus,
};
-export type CancelReservationResponse = OCPP16CancelReservationResponse;
+export type CancelReservationResponse = GenericResponse;