}
}
+ public stopMeterValues(connectorId: number) {
+ if (this.getConnectorStatus(connectorId)?.transactionSetInterval) {
+ clearInterval(this.getConnectorStatus(connectorId)?.transactionSetInterval);
+ }
+ }
+
public start(): void {
if (this.started === false) {
if (this.starting === false) {
}
}
- public resetConnectorStatus(connectorId: number): void {
- this.getConnectorStatus(connectorId).idTagLocalAuthorized = false;
- this.getConnectorStatus(connectorId).idTagAuthorized = false;
- this.getConnectorStatus(connectorId).transactionRemoteStarted = false;
- this.getConnectorStatus(connectorId).transactionStarted = false;
- delete this.getConnectorStatus(connectorId)?.localAuthorizeIdTag;
- delete this.getConnectorStatus(connectorId)?.authorizeIdTag;
- delete this.getConnectorStatus(connectorId)?.transactionId;
- delete this.getConnectorStatus(connectorId)?.transactionIdTag;
- this.getConnectorStatus(connectorId).transactionEnergyActiveImportRegisterValue = 0;
- delete this.getConnectorStatus(connectorId)?.transactionBeginMeterValue;
- this.stopMeterValues(connectorId);
- parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(this));
- }
-
public hasFeatureProfile(featureProfile: SupportedFeatureProfiles): boolean | undefined {
return ChargingStationConfigurationUtils.getConfigurationKey(
this,
this.getUseConnectorId0(stationInfo) === true &&
connectorStatus
) {
- this.checkStationInfoConnectorStatus(lastConnectorId, connectorStatus);
+ ChargingStationUtils.checkStationInfoConnectorStatus(
+ lastConnectorId,
+ connectorStatus,
+ this.logPrefix(),
+ this.templateFile
+ );
this.connectors.set(
lastConnectorId,
Utils.cloneObject<ConnectorStatus>(connectorStatus)
? Utils.getRandomInteger(Utils.convertToInt(lastConnector), 1)
: index;
const connectorStatus = stationInfo?.Connectors[randConnectorId.toString()];
- this.checkStationInfoConnectorStatus(randConnectorId, connectorStatus);
+ ChargingStationUtils.checkStationInfoConnectorStatus(
+ randConnectorId,
+ connectorStatus,
+ this.logPrefix(),
+ this.templateFile
+ );
this.connectors.set(index, Utils.cloneObject<ConnectorStatus>(connectorStatus));
this.getConnectorStatus(index).availability = AvailabilityType.Operative;
if (Utils.isUndefined(this.getConnectorStatus(index)?.chargingProfiles)) {
connectorId > 0 &&
Utils.isNullOrUndefined(this.getConnectorStatus(connectorId)?.transactionStarted)
) {
- this.initializeConnectorStatus(this.getConnectorStatus(connectorId));
- }
- }
- }
-
- private buildConnectorsMap(
- connectors: Record<string, ConnectorStatus>
- ): Map<number, ConnectorStatus> {
- const connectorsMap = new Map<number, ConnectorStatus>();
- for (const connector in connectors) {
- const connectorStatus = connectors[connector];
- const connectorId = Utils.convertToInt(connector);
- this.checkStationInfoConnectorStatus(connectorId, connectorStatus);
- connectorsMap.set(connectorId, Utils.cloneObject<ConnectorStatus>(connectorStatus));
- connectorsMap.get(connectorId).availability = AvailabilityType.Operative;
- if (Utils.isUndefined(connectorsMap.get(connectorId)?.chargingProfiles)) {
- connectorsMap.get(connectorId).chargingProfiles = [];
- }
- }
- return connectorsMap;
- }
-
- private initializeConnectorsMapStatus(connectors: Map<number, ConnectorStatus>): void {
- for (const connectorId of connectors.keys()) {
- if (connectorId > 0 && connectors.get(connectorId)?.transactionStarted === true) {
- logger.warn(
- `${this.logPrefix()} Connector ${connectorId} at initialization has a transaction started: ${
- connectors.get(connectorId)?.transactionId
- }`
- );
- }
- if (
- connectorId > 0 &&
- Utils.isNullOrUndefined(connectors.get(connectorId)?.transactionStarted)
- ) {
- this.initializeConnectorStatus(connectors.get(connectorId));
+ ChargingStationUtils.initializeConnectorStatus(this.getConnectorStatus(connectorId));
}
}
}
this.evsesConfigurationHash = evsesConfigHash;
for (const evse in stationInfo?.Evses) {
this.evses.set(Utils.convertToInt(evse), {
- connectors: this.buildConnectorsMap(stationInfo?.Evses[evse]?.Connectors),
+ connectors: ChargingStationUtils.buildConnectorsMap(
+ stationInfo?.Evses[evse]?.Connectors,
+ this.logPrefix(),
+ this.templateFile
+ ),
availability: AvailabilityType.Operative,
});
- this.initializeConnectorsMapStatus(this.evses.get(Utils.convertToInt(evse))?.connectors);
+ ChargingStationUtils.initializeConnectorsMapStatus(
+ this.evses.get(Utils.convertToInt(evse))?.connectors,
+ this.logPrefix()
+ );
}
}
} else {
}
}
- private checkStationInfoConnectorStatus(
- connectorId: number,
- connectorStatus: ConnectorStatus
- ): void {
- if (!Utils.isNullOrUndefined(connectorStatus?.status)) {
- logger.warn(
- `${this.logPrefix()} Charging station information from template ${
- this.templateFile
- } with connector ${connectorId} status configuration defined, undefine it`
- );
- delete connectorStatus.status;
- }
- }
-
private getConfigurationFromFile(): ChargingStationConfiguration | undefined {
let configuration: ChargingStationConfiguration | undefined;
if (this.configurationFile && fs.existsSync(this.configurationFile)) {
}
}
- private stopMeterValues(connectorId: number) {
- if (this.getConnectorStatus(connectorId)?.transactionSetInterval) {
- clearInterval(this.getConnectorStatus(connectorId)?.transactionSetInterval);
- }
- }
-
private getReconnectExponentialDelay(): boolean {
return this.stationInfo?.reconnectExponentialDelay ?? false;
}
| undefined {
return this.getTemplateFromFile()?.AutomaticTransactionGenerator;
}
-
- private initializeConnectorStatus(connectorStatus: ConnectorStatus): void {
- connectorStatus.idTagLocalAuthorized = false;
- connectorStatus.idTagAuthorized = false;
- connectorStatus.transactionRemoteStarted = false;
- connectorStatus.transactionStarted = false;
- connectorStatus.energyActiveImportRegisterValue = 0;
- connectorStatus.transactionEnergyActiveImportRegisterValue = 0;
- }
}
import { BaseError } from '../exception';
import {
AmpereUnits,
+ AvailabilityType,
type BootNotificationRequest,
BootReasonEnumType,
type ChargingProfile,
}
}
+ public static checkStationInfoConnectorStatus(
+ connectorId: number,
+ connectorStatus: ConnectorStatus,
+ logPrefix: string,
+ templateFile: string
+ ): void {
+ if (!Utils.isNullOrUndefined(connectorStatus?.status)) {
+ logger.warn(
+ `${logPrefix} Charging station information from template ${templateFile} with connector ${connectorId} status configuration defined, undefine it`
+ );
+ delete connectorStatus.status;
+ }
+ }
+
+ public static buildConnectorsMap(
+ connectors: Record<string, ConnectorStatus>,
+ logPrefix: string,
+ templateFile: string
+ ): Map<number, ConnectorStatus> {
+ const connectorsMap = new Map<number, ConnectorStatus>();
+ for (const connector in connectors) {
+ const connectorStatus = connectors[connector];
+ const connectorId = Utils.convertToInt(connector);
+ ChargingStationUtils.checkStationInfoConnectorStatus(
+ connectorId,
+ connectorStatus,
+ logPrefix,
+ templateFile
+ );
+ connectorsMap.set(connectorId, Utils.cloneObject<ConnectorStatus>(connectorStatus));
+ connectorsMap.get(connectorId).availability = AvailabilityType.Operative;
+ if (Utils.isUndefined(connectorsMap.get(connectorId)?.chargingProfiles)) {
+ connectorsMap.get(connectorId).chargingProfiles = [];
+ }
+ }
+ return connectorsMap;
+ }
+
+ public static initializeConnectorsMapStatus(
+ connectors: Map<number, ConnectorStatus>,
+ logPrefix: string
+ ): void {
+ for (const connectorId of connectors.keys()) {
+ if (connectorId > 0 && connectors.get(connectorId)?.transactionStarted === true) {
+ logger.warn(
+ `${logPrefix} Connector ${connectorId} at initialization has a transaction started: ${
+ connectors.get(connectorId)?.transactionId
+ }`
+ );
+ }
+ if (
+ connectorId > 0 &&
+ Utils.isNullOrUndefined(connectors.get(connectorId)?.transactionStarted)
+ ) {
+ ChargingStationUtils.initializeConnectorStatus(connectors.get(connectorId));
+ }
+ }
+ }
+
+ public static initializeConnectorStatus(connectorStatus: ConnectorStatus): void {
+ connectorStatus.idTagLocalAuthorized = false;
+ connectorStatus.idTagAuthorized = false;
+ connectorStatus.transactionRemoteStarted = false;
+ connectorStatus.transactionStarted = false;
+ connectorStatus.energyActiveImportRegisterValue = 0;
+ connectorStatus.transactionEnergyActiveImportRegisterValue = 0;
+ }
+
+ public static resetConnectorStatus(connectorStatus: ConnectorStatus): void {
+ connectorStatus.idTagLocalAuthorized = false;
+ connectorStatus.idTagAuthorized = false;
+ connectorStatus.transactionRemoteStarted = false;
+ connectorStatus.transactionStarted = false;
+ delete connectorStatus?.localAuthorizeIdTag;
+ delete connectorStatus?.authorizeIdTag;
+ delete connectorStatus?.transactionId;
+ delete connectorStatus?.transactionIdTag;
+ connectorStatus.transactionEnergyActiveImportRegisterValue = 0;
+ delete connectorStatus?.transactionBeginMeterValue;
+ }
+
public static createBootNotificationRequest(
stationInfo: ChargingStationInfo,
bootReason: BootReasonEnumType = BootReasonEnumType.PowerUp
// Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
+import { parentPort } from 'node:worker_threads';
+
import type { JSONSchemaType } from 'ajv';
-import { type ChargingStation, ChargingStationConfigurationUtils } from '../../../charging-station';
+import {
+ type ChargingStation,
+ ChargingStationConfigurationUtils,
+ ChargingStationUtils,
+ MessageChannelUtils,
+} from '../../../charging-station';
import { OCPPError } from '../../../exception';
import {
type ChangeAvailabilityResponse,
chargingStation: ChargingStation,
connectorId: number
): Promise<void> {
- chargingStation.resetConnectorStatus(connectorId);
+ ChargingStationUtils.resetConnectorStatus(chargingStation.getConnectorStatus(connectorId));
+ chargingStation.stopMeterValues(connectorId);
+ parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(chargingStation));
if (
chargingStation.getConnectorStatus(connectorId)?.status !== OCPP16ChargePointStatus.Available
) {
if (chargingStation.stationInfo.powerSharedByConnectors) {
chargingStation.powerDivider--;
}
- chargingStation.resetConnectorStatus(transactionConnectorId);
+ ChargingStationUtils.resetConnectorStatus(
+ chargingStation.getConnectorStatus(transactionConnectorId)
+ );
+ chargingStation.stopMeterValues(transactionConnectorId);
+ parentPort?.postMessage(MessageChannelUtils.buildUpdatedMessage(chargingStation));
const logMsg = `${chargingStation.logPrefix()} Transaction ${requestPayload.transactionId.toString()} STOPPED on ${
chargingStation.stationInfo.chargingStationId
}#${transactionConnectorId?.toString()} with status '${