Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Introduce a CS instance hashId dependent on its specifications and us…
Browse files Browse the repository at this point in the history
…e it in

various places such as OCPP parameters persistence

Reference #196

Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
  • Loading branch information
Jérôme Benoit committed Mar 13, 2022
1 parent 25b292f commit 3f94cab
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 71 deletions.
90 changes: 45 additions & 45 deletions README.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/charging-station/AutomaticTransactionGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ export default class AutomaticTransactionGenerator {
}

public static getInstance(chargingStation: ChargingStation): AutomaticTransactionGenerator {
if (!AutomaticTransactionGenerator.instances.has(chargingStation.id)) {
if (!AutomaticTransactionGenerator.instances.has(chargingStation.hashId)) {
AutomaticTransactionGenerator.instances.set(
chargingStation.id,
chargingStation.hashId,
new AutomaticTransactionGenerator(chargingStation)
);
}
return AutomaticTransactionGenerator.instances.get(chargingStation.id);
return AutomaticTransactionGenerator.instances.get(chargingStation.hashId);
}

public start(): void {
Expand Down
40 changes: 27 additions & 13 deletions src/charging-station/ChargingStation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import { parentPort } from 'worker_threads';
import path from 'path';

export default class ChargingStation {
public readonly id: string;
public hashId!: string;
public readonly stationTemplateFile: string;
public authorizedTags: string[];
public stationInfo!: ChargingStationInfo;
Expand All @@ -89,7 +89,6 @@ export default class ChargingStation {
private webSocketPingSetInterval!: NodeJS.Timeout;

constructor(index: number, stationTemplateFile: string) {
this.id = Utils.generateUUID();
this.index = index;
this.stationTemplateFile = stationTemplateFile;
this.stopped = false;
Expand Down Expand Up @@ -815,13 +814,6 @@ export default class ChargingStation {

private initialize(): void {
this.stationInfo = this.buildStationInfo();
this.configurationFile = path.join(
path.resolve(__dirname, '../'),
'assets/configurations',
this.stationInfo.chargingStationId + '.json'
);
this.configuration = this.getConfiguration();
delete this.stationInfo.Configuration;
this.bootNotificationRequest = {
chargePointModel: this.stationInfo.chargePointModel,
chargePointVendor: this.stationInfo.chargePointVendor,
Expand All @@ -831,7 +823,29 @@ export default class ChargingStation {
...(!Utils.isUndefined(this.stationInfo.firmwareVersion) && {
firmwareVersion: this.stationInfo.firmwareVersion,
}),
...(Utils.isUndefined(this.stationInfo.iccid) && { iccid: this.stationInfo.iccid }),
...(Utils.isUndefined(this.stationInfo.imsi) && { imsi: this.stationInfo.imsi }),
...(Utils.isUndefined(this.stationInfo.meterSerialNumber) && {
meterSerialNumber: this.stationInfo.meterSerialNumber,
}),
...(Utils.isUndefined(this.stationInfo.meterType) && {
meterType: this.stationInfo.meterType,
}),
};

this.hashId = crypto
.createHash(Constants.DEFAULT_HASH_ALGORITHM)
.update(JSON.stringify(this.bootNotificationRequest) + this.stationInfo.chargingStationId)
.digest('hex');
logger.info(`${this.logPrefix()} Charging station hashId '${this.hashId}'`);
this.configurationFile = path.join(
path.resolve(__dirname, '../'),
'assets',
'configurations',
this.hashId + '.json'
);
this.configuration = this.getConfiguration();
delete this.stationInfo.Configuration;
// Build connectors if needed
const maxConnectors = this.getMaxNumberOfConnectors();
if (maxConnectors <= 0) {
Expand Down Expand Up @@ -870,7 +884,7 @@ export default class ChargingStation {
this.stationInfo.randomConnectors = true;
}
const connectorsConfigHash = crypto
.createHash('sha256')
.createHash(Constants.DEFAULT_HASH_ALGORITHM)
.update(JSON.stringify(this.stationInfo.Connectors) + maxConnectors.toString())
.digest('hex');
const connectorsConfigChanged =
Expand Down Expand Up @@ -927,6 +941,8 @@ export default class ChargingStation {
this.wsConfiguredConnectionUrl = new URL(
this.getConfiguredSupervisionUrl().href + '/' + this.stationInfo.chargingStationId
);
// OCPP parameters
this.initOcppParameters();
switch (this.getOcppVersion()) {
case OCPPVersion.VERSION_16:
this.ocppIncomingRequestService =
Expand All @@ -940,8 +956,6 @@ export default class ChargingStation {
this.handleUnsupportedVersion(this.getOcppVersion());
break;
}
// OCPP parameters
this.initOcppParameters();
if (this.stationInfo.autoRegister) {
this.bootNotificationResponse = {
currentTime: new Date().toISOString(),
Expand All @@ -952,7 +966,7 @@ export default class ChargingStation {
this.stationInfo.powerDivider = this.getPowerDivider();
if (this.getEnableStatistics()) {
this.performanceStatistics = PerformanceStatistics.getInstance(
this.id,
this.hashId,
this.stationInfo.chargingStationId,
this.wsConnectionUrl
);
Expand Down
2 changes: 1 addition & 1 deletion src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default class OCPP16ResponseService extends OCPPResponseService {
this.chargingStation.addConfigurationKey(
OCPP16StandardParametersKey.HeartbeatInterval,
payload.interval.toString(),
{ visible: false },
{ visible: false, reboot: false },
{ overwrite: true, save: true }
);
this.chargingStation.heartbeatSetInterval
Expand Down
6 changes: 3 additions & 3 deletions src/charging-station/ocpp/OCPPIncomingRequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export default abstract class OCPPIncomingRequestService {
this: new (chargingStation: ChargingStation) => T,
chargingStation: ChargingStation
): T {
if (!OCPPIncomingRequestService.instances.has(chargingStation.id)) {
OCPPIncomingRequestService.instances.set(chargingStation.id, new this(chargingStation));
if (!OCPPIncomingRequestService.instances.has(chargingStation.hashId)) {
OCPPIncomingRequestService.instances.set(chargingStation.hashId, new this(chargingStation));
}
return OCPPIncomingRequestService.instances.get(chargingStation.id) as T;
return OCPPIncomingRequestService.instances.get(chargingStation.hashId) as T;
}

protected handleIncomingRequestError<T>(
Expand Down
6 changes: 3 additions & 3 deletions src/charging-station/ocpp/OCPPRequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ export default abstract class OCPPRequestService {
chargingStation: ChargingStation,
ocppResponseService: OCPPResponseService
): T {
if (!OCPPRequestService.instances.has(chargingStation.id)) {
if (!OCPPRequestService.instances.has(chargingStation.hashId)) {
OCPPRequestService.instances.set(
chargingStation.id,
chargingStation.hashId,
new this(chargingStation, ocppResponseService)
);
}
return OCPPRequestService.instances.get(chargingStation.id) as T;
return OCPPRequestService.instances.get(chargingStation.hashId) as T;
}

public async sendResult(
Expand Down
6 changes: 3 additions & 3 deletions src/charging-station/ocpp/OCPPResponseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export default abstract class OCPPResponseService {
this: new (chargingStation: ChargingStation) => T,
chargingStation: ChargingStation
): T {
if (!OCPPResponseService.instances.has(chargingStation.id)) {
OCPPResponseService.instances.set(chargingStation.id, new this(chargingStation));
if (!OCPPResponseService.instances.has(chargingStation.hashId)) {
OCPPResponseService.instances.set(chargingStation.hashId, new this(chargingStation));
}
return OCPPResponseService.instances.get(chargingStation.id) as T;
return OCPPResponseService.instances.get(chargingStation.hashId) as T;
}

public abstract handleResponse(
Expand Down
4 changes: 4 additions & 0 deletions src/types/ChargingStationTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export default interface ChargingStationTemplate {
chargePointVendor: string;
chargeBoxSerialNumberPrefix?: string;
firmwareVersion?: string;
iccid?: string;
imsi?: string;
meterSerialNumber?: string;
meterType?: string;
power: number | number[];
powerSharedByConnectors?: boolean;
powerUnit: PowerUnits;
Expand Down
2 changes: 2 additions & 0 deletions src/utils/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ export default class Constants {
static readonly CHARGING_STATION_ATG_INITIALIZATION_TIME = 1000; // Ms
static readonly CHARGING_STATION_ATG_DEFAULT_STOP_AFTER_HOURS = 0.25; // Hours

static readonly DEFAULT_HASH_ALGORITHM = 'sha384';

static readonly DEFAULT_IDTAG = '00000000';

static readonly DEFAULT_CONNECTION_TIMEOUT = 30;
Expand Down

0 comments on commit 3f94cab

Please sign in to comment.