StopTransactionRequest,
StopTransactionResponse,
} from '../types/ocpp/Transaction';
+import { URL, fileURLToPath } from 'url';
import { WSError, WebSocketCloseEventStatusCode } from '../types/WebSocket';
-import WebSocket, { Data, OPEN, RawData } from 'ws';
+import WebSocket, { Data, RawData } from 'ws';
import AutomaticTransactionGenerator from './AutomaticTransactionGenerator';
import { AutomaticTransactionGeneratorConfiguration } from '../types/AutomaticTransactionGenerator';
import { OCPPVersion } from '../types/ocpp/OCPPVersion';
import PerformanceStatistics from '../performance/PerformanceStatistics';
import { SupervisionUrlDistribution } from '../types/ConfigurationData';
-import { URL } from 'url';
import Utils from '../utils/Utils';
import crypto from 'crypto';
import fs from 'fs';
}
public isWebSocketConnectionOpened(): boolean {
- return this?.wsConnection?.readyState === OPEN;
+ return this?.wsConnection?.readyState === WebSocket.OPEN;
}
public getRegistrationStatus(): RegistrationStatus {
this.getConnectorStatus(connectorId).status = ChargePointStatus.UNAVAILABLE;
}
}
- if (this.isWebSocketConnectionOpened()) {
- this.wsConnection.close();
- }
+ this.closeWSConnection();
if (this.getEnableStatistics()) {
this.performanceStatistics.stop();
}
this.hashId = ChargingStationUtils.getHashId(this.index, this.getTemplateFromFile());
logger.info(`${this.logPrefix()} Charging station hashId '${this.hashId}'`);
this.configurationFile = path.join(
- path.resolve(__dirname, '../'),
+ path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'),
'assets',
'configurations',
this.hashId + '.json'
) {
options.auth = `${this.stationInfo.supervisionUser}:${this.stationInfo.supervisionPassword}`;
}
- if (this.isWebSocketConnectionOpened() && params?.closeOpened) {
- this.wsConnection.close();
+ if (params?.closeOpened) {
+ this.closeWSConnection();
}
- if (this.isWebSocketConnectionOpened() && params?.terminateOpened) {
- this.wsConnection.terminate();
+ if (params?.terminateOpened) {
+ this.terminateWSConnection();
}
let protocol: string;
switch (this.getOcppVersion()) {
);
}
+ private closeWSConnection(): void {
+ if (this.isWebSocketConnectionOpened()) {
+ this.wsConnection.close();
+ this.wsConnection = null;
+ }
+ }
+
+ private terminateWSConnection(): void {
+ if (this.isWebSocketConnectionOpened()) {
+ this.wsConnection.terminate();
+ this.wsConnection = null;
+ }
+ }
+
private stopMeterValues(connectorId: number) {
if (this.getConnectorStatus(connectorId)?.transactionSetInterval) {
clearInterval(this.getConnectorStatus(connectorId).transactionSetInterval);