}
private startConnectors(): void {
- for (const connector in this.chargingStation.connectors) {
- const connectorId = Utils.convertToInt(connector);
+ for (const connectorId of this.chargingStation.connectors.keys()) {
if (connectorId > 0) {
this.startConnector(connectorId);
}
}
private stopConnectors(): void {
- for (const connector in this.chargingStation.connectors) {
- const connectorId = Utils.convertToInt(connector);
+ for (const connectorId of this.chargingStation.connectors.keys()) {
if (connectorId > 0) {
this.stopConnector(connectorId);
}
// Wait until end of transaction
const waitTrxEnd = Utils.getRandomInteger(this.chargingStation.stationInfo.AutomaticTransactionGenerator.maxDuration,
this.chargingStation.stationInfo.AutomaticTransactionGenerator.minDuration) * 1000;
- logger.info(this.logPrefix(connectorId) + ' transaction ' + this.chargingStation.getConnector(connectorId).transactionId.toString() + ' started and will stop in ' + Utils.formatDurationMilliSeconds(waitTrxEnd));
+ logger.info(this.logPrefix(connectorId) + ' transaction ' + this.chargingStation.getConnectorStatus(connectorId).transactionId.toString() + ' started and will stop in ' + Utils.formatDurationMilliSeconds(waitTrxEnd));
this.connectorsStatus.get(connectorId).acceptedStartTransactionRequests++;
await Utils.sleep(waitTrxEnd);
// Stop transaction
- logger.info(this.logPrefix(connectorId) + ' stop transaction ' + this.chargingStation.getConnector(connectorId).transactionId.toString());
+ logger.info(this.logPrefix(connectorId) + ' stop transaction ' + this.chargingStation.getConnectorStatus(connectorId).transactionId.toString());
await this.stopTransaction(connectorId);
}
} else {
const beginId = PerformanceStatistics.beginMeasure(measureId);
let transactionId = 0;
let stopResponse: StopTransactionResponse;
- if (this.chargingStation.getConnector(connectorId)?.transactionStarted) {
- transactionId = this.chargingStation.getConnector(connectorId).transactionId;
+ if (this.chargingStation.getConnectorStatus(connectorId)?.transactionStarted) {
+ transactionId = this.chargingStation.getConnectorStatus(connectorId).transactionId;
stopResponse = await this.chargingStation.ocppRequestService.sendStopTransaction(transactionId,
this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
this.chargingStation.getTransactionIdTag(transactionId),
import { BootNotificationResponse, RegistrationStatus } from '../types/ocpp/Responses';
import ChargingStationConfiguration, { ConfigurationKey } from '../types/ChargingStationConfiguration';
import ChargingStationTemplate, { CurrentType, PowerUnits, Voltage } from '../types/ChargingStationTemplate';
-import { Connector, Connectors, SampledValueTemplate } from '../types/Connectors';
import { ConnectorPhaseRotation, StandardParametersKey, SupportedFeatureProfiles } from '../types/ocpp/Configuration';
+import { ConnectorStatus, SampledValueTemplate } from '../types/Connectors';
import { MeterValueMeasurand, MeterValuePhase } from '../types/ocpp/MeterValues';
import { WSError, WebSocketCloseEventStatusCode } from '../types/WebSocket';
import WebSocket, { ClientOptions, Data, OPEN } from 'ws';
public stationTemplateFile: string;
public authorizedTags: string[];
public stationInfo!: ChargingStationInfo;
- public connectors: Connectors;
+ public connectors: Map<number, ConnectorStatus>;
public configuration!: ChargingStationConfiguration;
public wsConnection!: WebSocket;
public requests: Map<string, CachedRequest>;
constructor(index: number, stationTemplateFile: string) {
this.index = index;
this.stationTemplateFile = stationTemplateFile;
- this.connectors = {} as Connectors;
+ this.connectors = new Map<number, ConnectorStatus>();
this.initialize();
this.stopped = false;
}
public isChargingStationAvailable(): boolean {
- return this.getConnector(0).availability === AvailabilityType.OPERATIVE;
+ return this.getConnectorStatus(0).availability === AvailabilityType.OPERATIVE;
}
public isConnectorAvailable(id: number): boolean {
- return this.getConnector(id).availability === AvailabilityType.OPERATIVE;
+ return this.getConnectorStatus(id).availability === AvailabilityType.OPERATIVE;
}
- public getConnector(id: number): Connector {
- return this.connectors[id];
+ public getConnectorStatus(id: number): ConnectorStatus {
+ return this.connectors.get(id);
}
public getCurrentOutType(): CurrentType | undefined {
}
public getTransactionIdTag(transactionId: number): string | undefined {
- for (const connector in this.connectors) {
- if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector)).transactionId === transactionId) {
- return this.getConnector(Utils.convertToInt(connector)).transactionIdTag;
+ for (const connectorId of this.connectors.keys()) {
+ if (connectorId > 0 && this.getConnectorStatus(connectorId).transactionId === transactionId) {
+ return this.getConnectorStatus(connectorId).transactionIdTag;
}
}
}
public getEnergyActiveImportRegisterByTransactionId(transactionId: number): number | undefined {
if (this.getMeteringPerTransaction()) {
- for (const connector in this.connectors) {
- if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector)).transactionId === transactionId) {
- return this.getConnector(Utils.convertToInt(connector)).transactionEnergyActiveImportRegisterValue;
+ for (const connectorId of this.connectors.keys()) {
+ if (connectorId > 0 && this.getConnectorStatus(connectorId).transactionId === transactionId) {
+ return this.getConnectorStatus(connectorId).transactionEnergyActiveImportRegisterValue;
}
}
}
- for (const connector in this.connectors) {
- if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector)).transactionId === transactionId) {
- return this.getConnector(Utils.convertToInt(connector)).energyActiveImportRegisterValue;
+ for (const connectorId of this.connectors.keys()) {
+ if (connectorId > 0 && this.getConnectorStatus(connectorId).transactionId === transactionId) {
+ return this.getConnectorStatus(connectorId).energyActiveImportRegisterValue;
}
}
}
public getEnergyActiveImportRegisterByConnectorId(connectorId: number): number | undefined {
if (this.getMeteringPerTransaction()) {
- return this.getConnector(connectorId).transactionEnergyActiveImportRegisterValue;
+ return this.getConnectorStatus(connectorId).transactionEnergyActiveImportRegisterValue;
}
- return this.getConnector(connectorId).energyActiveImportRegisterValue;
+ return this.getConnectorStatus(connectorId).energyActiveImportRegisterValue;
}
public getAuthorizeRemoteTxRequests(): boolean {
logger.debug(`${this.logPrefix()} Trying to get MeterValues measurand '${measurand}' ${phase ? `on phase ${phase} ` : ''}in template on connectorId ${connectorId} not found in '${StandardParametersKey.MeterValuesSampledData}' OCPP parameter`);
return;
}
- const sampledValueTemplates: SampledValueTemplate[] = this.getConnector(connectorId).MeterValues;
+ const sampledValueTemplates: SampledValueTemplate[] = this.getConnectorStatus(connectorId).MeterValues;
for (let index = 0; !Utils.isEmptyArray(sampledValueTemplates) && index < sampledValueTemplates.length; index++) {
if (!Constants.SUPPORTED_MEASURANDS.includes(sampledValueTemplates[index]?.measurand ?? MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER)) {
logger.warn(`${this.logPrefix()} Unsupported MeterValues measurand '${measurand}' ${phase ? `on phase ${phase} ` : ''}in template on connectorId ${connectorId}`);
logger.error(`${this.logPrefix()} Trying to start MeterValues on connector Id ${connectorId.toString()}`);
return;
}
- if (!this.getConnector(connectorId)) {
+ if (!this.getConnectorStatus(connectorId)) {
logger.error(`${this.logPrefix()} Trying to start MeterValues on non existing connector Id ${connectorId.toString()}`);
return;
}
- if (!this.getConnector(connectorId)?.transactionStarted) {
+ if (!this.getConnectorStatus(connectorId)?.transactionStarted) {
logger.error(`${this.logPrefix()} Trying to start MeterValues on connector Id ${connectorId} with no transaction started`);
return;
- } else if (this.getConnector(connectorId)?.transactionStarted && !this.getConnector(connectorId)?.transactionId) {
+ } else if (this.getConnectorStatus(connectorId)?.transactionStarted && !this.getConnectorStatus(connectorId)?.transactionId) {
logger.error(`${this.logPrefix()} Trying to start MeterValues on connector Id ${connectorId} with no transaction id`);
return;
}
if (interval > 0) {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
- this.getConnector(connectorId).transactionSetInterval = setInterval(async (): Promise<void> => {
- await this.ocppRequestService.sendMeterValues(connectorId, this.getConnector(connectorId).transactionId, interval);
+ this.getConnectorStatus(connectorId).transactionSetInterval = setInterval(async (): Promise<void> => {
+ await this.ocppRequestService.sendMeterValues(connectorId, this.getConnectorStatus(connectorId).transactionId, interval);
}, interval);
} else {
logger.error(`${this.logPrefix()} Charging station ${StandardParametersKey.MeterValueSampleInterval} configuration set to ${interval ? Utils.formatDurationMilliSeconds(interval) : interval}, not sending MeterValues`);
public async stop(reason: StopTransactionReason = StopTransactionReason.NONE): Promise<void> {
// Stop message sequence
await this.stopMessageSequence(reason);
- for (const connector in this.connectors) {
- if (Utils.convertToInt(connector) > 0) {
- await this.ocppRequestService.sendStatusNotification(Utils.convertToInt(connector), ChargePointStatus.UNAVAILABLE);
- this.getConnector(Utils.convertToInt(connector)).status = ChargePointStatus.UNAVAILABLE;
+ for (const connectorId of this.connectors.keys()) {
+ if (connectorId > 0) {
+ await this.ocppRequestService.sendStatusNotification(connectorId, ChargePointStatus.UNAVAILABLE);
+ this.getConnectorStatus(connectorId).status = ChargePointStatus.UNAVAILABLE;
}
}
if (this.isWebSocketConnectionOpened()) {
public setChargingProfile(connectorId: number, cp: ChargingProfile): void {
let cpReplaced = false;
- if (!Utils.isEmptyArray(this.getConnector(connectorId).chargingProfiles)) {
- this.getConnector(connectorId).chargingProfiles?.forEach((chargingProfile: ChargingProfile, index: number) => {
+ if (!Utils.isEmptyArray(this.getConnectorStatus(connectorId).chargingProfiles)) {
+ this.getConnectorStatus(connectorId).chargingProfiles?.forEach((chargingProfile: ChargingProfile, index: number) => {
if (chargingProfile.chargingProfileId === cp.chargingProfileId
|| (chargingProfile.stackLevel === cp.stackLevel && chargingProfile.chargingProfilePurpose === cp.chargingProfilePurpose)) {
- this.getConnector(connectorId).chargingProfiles[index] = cp;
+ this.getConnectorStatus(connectorId).chargingProfiles[index] = cp;
cpReplaced = true;
}
});
}
- !cpReplaced && this.getConnector(connectorId).chargingProfiles?.push(cp);
+ !cpReplaced && this.getConnectorStatus(connectorId).chargingProfiles?.push(cp);
}
public resetTransactionOnConnector(connectorId: number): void {
- this.getConnector(connectorId).authorized = false;
- this.getConnector(connectorId).transactionStarted = false;
- delete this.getConnector(connectorId).authorizeIdTag;
- delete this.getConnector(connectorId).transactionId;
- delete this.getConnector(connectorId).transactionIdTag;
- this.getConnector(connectorId).transactionEnergyActiveImportRegisterValue = 0;
- delete this.getConnector(connectorId).transactionBeginMeterValue;
+ this.getConnectorStatus(connectorId).authorized = false;
+ this.getConnectorStatus(connectorId).transactionStarted = false;
+ 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);
}
this.stationInfo.randomConnectors = true;
}
const connectorsConfigHash = crypto.createHash('sha256').update(JSON.stringify(this.stationInfo.Connectors) + maxConnectors.toString()).digest('hex');
- const connectorsConfigChanged = !Utils.isEmptyObject(this.connectors) && this.connectorsConfigurationHash !== connectorsConfigHash;
- if (!this.connectors || Utils.isEmptyObject(this.connectors) || connectorsConfigChanged) {
- connectorsConfigChanged && (this.connectors = {} as Connectors);
+ const connectorsConfigChanged = this.connectors.size !== 0 && this.connectorsConfigurationHash !== connectorsConfigHash;
+ if (!this.connectors || this.connectors.size === 0 || connectorsConfigChanged) {
+ connectorsConfigChanged && (this.connectors.clear());
this.connectorsConfigurationHash = connectorsConfigHash;
// Add connector Id 0
let lastConnector = '0';
for (lastConnector in this.stationInfo.Connectors) {
- if (Utils.convertToInt(lastConnector) === 0 && this.getUseConnectorId0() && this.stationInfo.Connectors[lastConnector]) {
- this.connectors[lastConnector] = Utils.cloneObject<Connector>(this.stationInfo.Connectors[lastConnector]);
- this.connectors[lastConnector].availability = AvailabilityType.OPERATIVE;
- if (Utils.isUndefined(this.connectors[lastConnector]?.chargingProfiles)) {
- this.connectors[lastConnector].chargingProfiles = [];
+ const lastConnectorId = Utils.convertToInt(lastConnector);
+ if (lastConnectorId === 0 && this.getUseConnectorId0() && this.stationInfo.Connectors[lastConnector]) {
+ this.connectors.set(lastConnectorId, Utils.cloneObject<ConnectorStatus>(this.stationInfo.Connectors[lastConnector]));
+ this.getConnectorStatus(lastConnectorId).availability = AvailabilityType.OPERATIVE;
+ if (Utils.isUndefined(this.getConnectorStatus(lastConnectorId)?.chargingProfiles)) {
+ this.getConnectorStatus(lastConnectorId).chargingProfiles = [];
}
}
}
if ((this.stationInfo.Connectors[0] ? templateMaxConnectors - 1 : templateMaxConnectors) > 0) {
for (let index = 1; index <= maxConnectors; index++) {
const randConnectorId = this.stationInfo.randomConnectors ? Utils.getRandomInteger(Utils.convertToInt(lastConnector), 1) : index;
- this.connectors[index] = Utils.cloneObject<Connector>(this.stationInfo.Connectors[randConnectorId]);
- this.connectors[index].availability = AvailabilityType.OPERATIVE;
- if (Utils.isUndefined(this.connectors[lastConnector]?.chargingProfiles)) {
- this.connectors[index].chargingProfiles = [];
+ this.connectors.set(index, Utils.cloneObject<ConnectorStatus>(this.stationInfo.Connectors[randConnectorId]));
+ this.getConnectorStatus(index).availability = AvailabilityType.OPERATIVE;
+ if (Utils.isUndefined(this.getConnectorStatus(index)?.chargingProfiles)) {
+ this.getConnectorStatus(index).chargingProfiles = [];
}
}
}
// Avoid duplication of connectors related information
delete this.stationInfo.Connectors;
// Initialize transaction attributes on connectors
- for (const connector in this.connectors) {
- if (Utils.convertToInt(connector) > 0 && !this.getConnector(Utils.convertToInt(connector))?.transactionStarted) {
- this.initTransactionAttributesOnConnector(Utils.convertToInt(connector));
+ for (const connectorId of this.connectors.keys()) {
+ if (connectorId > 0 && !this.getConnectorStatus(connectorId)?.transactionStarted) {
+ this.initTransactionAttributesOnConnector(connectorId);
}
}
switch (this.getOCPPVersion()) {
}
if (!this.getConfigurationKey(StandardParametersKey.ConnectorPhaseRotation)) {
const connectorPhaseRotation = [];
- for (const connector in this.connectors) {
+ for (const connectorId of this.connectors.keys()) {
// AC/DC
- if (Utils.convertToInt(connector) === 0 && this.getNumberOfPhases() === 0) {
- connectorPhaseRotation.push(`${connector}.${ConnectorPhaseRotation.RST}`);
- } else if (Utils.convertToInt(connector) > 0 && this.getNumberOfPhases() === 0) {
- connectorPhaseRotation.push(`${connector}.${ConnectorPhaseRotation.NotApplicable}`);
+ if (connectorId === 0 && this.getNumberOfPhases() === 0) {
+ connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.RST}`);
+ } else if (connectorId > 0 && this.getNumberOfPhases() === 0) {
+ connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`);
// AC
- } else if (Utils.convertToInt(connector) > 0 && this.getNumberOfPhases() === 1) {
- connectorPhaseRotation.push(`${connector}.${ConnectorPhaseRotation.NotApplicable}`);
- } else if (Utils.convertToInt(connector) > 0 && this.getNumberOfPhases() === 3) {
- connectorPhaseRotation.push(`${connector}.${ConnectorPhaseRotation.RST}`);
+ } else if (connectorId > 0 && this.getNumberOfPhases() === 1) {
+ connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.NotApplicable}`);
+ } else if (connectorId > 0 && this.getNumberOfPhases() === 3) {
+ connectorPhaseRotation.push(`${connectorId}.${ConnectorPhaseRotation.RST}`);
}
}
this.addConfigurationKey(StandardParametersKey.ConnectorPhaseRotation, connectorPhaseRotation.toString());
private getNumberOfRunningTransactions(): number {
let trxCount = 0;
- for (const connector in this.connectors) {
- if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector))?.transactionStarted) {
+ for (const connectorId of this.connectors.keys()) {
+ if (connectorId > 0 && this.getConnectorStatus(connectorId)?.transactionStarted) {
trxCount++;
}
}
}
private getNumberOfConnectors(): number {
- return this.connectors[0] ? Object.keys(this.connectors).length - 1 : Object.keys(this.connectors).length;
+ return this.connectors.get(0) ? this.connectors.size - 1 : this.connectors.size;
}
private async startMessageSequence(): Promise<void> {
// Start heartbeat
this.startHeartbeat();
// Initialize connectors status
- for (const connector in this.connectors) {
- if (Utils.convertToInt(connector) === 0) {
+ for (const connectorId of this.connectors.keys()) {
+ if (connectorId === 0) {
continue;
- } else if (!this.stopped && !this.getConnector(Utils.convertToInt(connector))?.status && this.getConnector(Utils.convertToInt(connector))?.bootStatus) {
+ } else if (!this.stopped && !this.getConnectorStatus(connectorId)?.status && this.getConnectorStatus(connectorId)?.bootStatus) {
// Send status in template at startup
- await this.ocppRequestService.sendStatusNotification(Utils.convertToInt(connector), this.getConnector(Utils.convertToInt(connector)).bootStatus);
- this.getConnector(Utils.convertToInt(connector)).status = this.getConnector(Utils.convertToInt(connector)).bootStatus;
- } else if (this.stopped && this.getConnector(Utils.convertToInt(connector))?.bootStatus) {
+ await this.ocppRequestService.sendStatusNotification(connectorId, this.getConnectorStatus(connectorId).bootStatus);
+ this.getConnectorStatus(connectorId).status = this.getConnectorStatus(connectorId).bootStatus;
+ } else if (this.stopped && this.getConnectorStatus(connectorId)?.status && this.getConnectorStatus(connectorId)?.bootStatus) {
// Send status in template after reset
- await this.ocppRequestService.sendStatusNotification(Utils.convertToInt(connector), this.getConnector(Utils.convertToInt(connector)).bootStatus);
- this.getConnector(Utils.convertToInt(connector)).status = this.getConnector(Utils.convertToInt(connector)).bootStatus;
- } else if (!this.stopped && this.getConnector(Utils.convertToInt(connector))?.status) {
+ await this.ocppRequestService.sendStatusNotification(connectorId, this.getConnectorStatus(connectorId).bootStatus);
+ this.getConnectorStatus(connectorId).status = this.getConnectorStatus(connectorId).bootStatus;
+ } else if (!this.stopped && this.getConnectorStatus(connectorId)?.status) {
// Send previous status at template reload
- await this.ocppRequestService.sendStatusNotification(Utils.convertToInt(connector), this.getConnector(Utils.convertToInt(connector)).status);
+ await this.ocppRequestService.sendStatusNotification(connectorId, this.getConnectorStatus(connectorId).status);
} else {
// Send default status
- await this.ocppRequestService.sendStatusNotification(Utils.convertToInt(connector), ChargePointStatus.AVAILABLE);
- this.getConnector(Utils.convertToInt(connector)).status = ChargePointStatus.AVAILABLE;
+ await this.ocppRequestService.sendStatusNotification(connectorId, ChargePointStatus.AVAILABLE);
+ this.getConnectorStatus(connectorId).status = ChargePointStatus.AVAILABLE;
}
}
// Start the ATG
this.automaticTransactionGenerator.started) {
this.automaticTransactionGenerator.stop();
} else {
- for (const connector in this.connectors) {
- if (Utils.convertToInt(connector) > 0 && this.getConnector(Utils.convertToInt(connector))?.transactionStarted) {
- const transactionId = this.getConnector(Utils.convertToInt(connector)).transactionId;
+ for (const connectorId of this.connectors.keys()) {
+ if (connectorId > 0 && this.getConnectorStatus(connectorId)?.transactionStarted) {
+ const transactionId = this.getConnectorStatus(connectorId).transactionId;
await this.ocppRequestService.sendStopTransaction(transactionId, this.getEnergyActiveImportRegisterByTransactionId(transactionId),
this.getTransactionIdTag(transactionId), reason);
}
}
private stopMeterValues(connectorId: number) {
- if (this.getConnector(connectorId)?.transactionSetInterval) {
- clearInterval(this.getConnector(connectorId).transactionSetInterval);
+ if (this.getConnectorStatus(connectorId)?.transactionSetInterval) {
+ clearInterval(this.getConnectorStatus(connectorId).transactionSetInterval);
}
}
}
private initTransactionAttributesOnConnector(connectorId: number): void {
- this.getConnector(connectorId).authorized = false;
- this.getConnector(connectorId).transactionStarted = false;
- this.getConnector(connectorId).energyActiveImportRegisterValue = 0;
- this.getConnector(connectorId).transactionEnergyActiveImportRegisterValue = 0;
+ this.getConnectorStatus(connectorId).authorized = false;
+ this.getConnectorStatus(connectorId).transactionStarted = false;
+ this.getConnectorStatus(connectorId).energyActiveImportRegisterValue = 0;
+ this.getConnectorStatus(connectorId).transactionEnergyActiveImportRegisterValue = 0;
}
}
[OCPP16IncomingRequestCommand.CHANGE_AVAILABILITY, this.handleRequestChangeAvailability.bind(this)],
[OCPP16IncomingRequestCommand.REMOTE_START_TRANSACTION, this.handleRequestRemoteStartTransaction.bind(this)],
[OCPP16IncomingRequestCommand.REMOTE_STOP_TRANSACTION, this.handleRequestRemoteStopTransaction.bind(this)],
+ [OCPP16IncomingRequestCommand.GET_DIAGNOSTICS, this.handleRequestGetDiagnostics.bind(this)],
[OCPP16IncomingRequestCommand.TRIGGER_MESSAGE, this.handleRequestTriggerMessage.bind(this)]
]);
}
logger.error(this.chargingStation.logPrefix() + ' Trying to unlock connector ' + connectorId.toString());
return Constants.OCPP_RESPONSE_UNLOCK_NOT_SUPPORTED;
}
- if (this.chargingStation.getConnector(connectorId)?.transactionStarted) {
- const transactionId = this.chargingStation.getConnector(connectorId).transactionId;
+ if (this.chargingStation.getConnectorStatus(connectorId)?.transactionStarted) {
+ const transactionId = this.chargingStation.getConnectorStatus(connectorId).transactionId;
const stopResponse = await this.chargingStation.ocppRequestService.sendStopTransaction(transactionId,
this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
this.chargingStation.getTransactionIdTag(transactionId),
return Constants.OCPP_RESPONSE_UNLOCK_FAILED;
}
await this.chargingStation.ocppRequestService.sendStatusNotification(connectorId, OCPP16ChargePointStatus.AVAILABLE);
- this.chargingStation.getConnector(connectorId).status = OCPP16ChargePointStatus.AVAILABLE;
+ this.chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.AVAILABLE;
return Constants.OCPP_RESPONSE_UNLOCKED;
}
}
private handleRequestSetChargingProfile(commandPayload: SetChargingProfileRequest): SetChargingProfileResponse {
- if (!this.chargingStation.getConnector(commandPayload.connectorId)) {
+ if (!this.chargingStation.getConnectorStatus(commandPayload.connectorId)) {
logger.error(`${this.chargingStation.logPrefix()} Trying to set charging profile(s) to a non existing connector Id ${commandPayload.connectorId}`);
return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED;
}
if (commandPayload.csChargingProfiles.chargingProfilePurpose === ChargingProfilePurposeType.CHARGE_POINT_MAX_PROFILE && commandPayload.connectorId !== 0) {
return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED;
}
- if (commandPayload.csChargingProfiles.chargingProfilePurpose === ChargingProfilePurposeType.TX_PROFILE && (commandPayload.connectorId === 0 || !this.chargingStation.getConnector(commandPayload.connectorId)?.transactionStarted)) {
+ if (commandPayload.csChargingProfiles.chargingProfilePurpose === ChargingProfilePurposeType.TX_PROFILE && (commandPayload.connectorId === 0 || !this.chargingStation.getConnectorStatus(commandPayload.connectorId)?.transactionStarted)) {
return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_REJECTED;
}
this.chargingStation.setChargingProfile(commandPayload.connectorId, commandPayload.csChargingProfiles);
- logger.debug(`${this.chargingStation.logPrefix()} Charging profile(s) set, dump their stack: %j`, this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles);
+ logger.debug(`${this.chargingStation.logPrefix()} Charging profile(s) set, dump their stack: %j`, this.chargingStation.getConnectorStatus(commandPayload.connectorId).chargingProfiles);
return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_ACCEPTED;
}
private handleRequestClearChargingProfile(commandPayload: ClearChargingProfileRequest): ClearChargingProfileResponse {
- if (!this.chargingStation.getConnector(commandPayload.connectorId)) {
+ if (!this.chargingStation.getConnectorStatus(commandPayload.connectorId)) {
logger.error(`${this.chargingStation.logPrefix()} Trying to clear a charging profile(s) to a non existing connector Id ${commandPayload.connectorId}`);
return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN;
}
- if (commandPayload.connectorId && !Utils.isEmptyArray(this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles)) {
- this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles = [];
- logger.debug(`${this.chargingStation.logPrefix()} Charging profile(s) cleared, dump their stack: %j`, this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles);
+ if (commandPayload.connectorId && !Utils.isEmptyArray(this.chargingStation.getConnectorStatus(commandPayload.connectorId).chargingProfiles)) {
+ this.chargingStation.getConnectorStatus(commandPayload.connectorId).chargingProfiles = [];
+ logger.debug(`${this.chargingStation.logPrefix()} Charging profile(s) cleared, dump their stack: %j`, this.chargingStation.getConnectorStatus(commandPayload.connectorId).chargingProfiles);
return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_ACCEPTED;
}
if (!commandPayload.connectorId) {
let clearedCP = false;
- for (const connector in this.chargingStation.connectors) {
- if (!Utils.isEmptyArray(this.chargingStation.getConnector(Utils.convertToInt(connector)).chargingProfiles)) {
- this.chargingStation.getConnector(Utils.convertToInt(connector)).chargingProfiles?.forEach((chargingProfile: OCPP16ChargingProfile, index: number) => {
+ for (const connectorId of this.chargingStation.connectors.keys()) {
+ if (!Utils.isEmptyArray(this.chargingStation.getConnectorStatus(connectorId).chargingProfiles)) {
+ this.chargingStation.getConnectorStatus(connectorId).chargingProfiles?.forEach((chargingProfile: OCPP16ChargingProfile, index: number) => {
let clearCurrentCP = false;
if (chargingProfile.chargingProfileId === commandPayload.id) {
clearCurrentCP = true;
clearCurrentCP = true;
}
if (clearCurrentCP) {
- this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles[index] = {} as OCPP16ChargingProfile;
- logger.debug(`${this.chargingStation.logPrefix()} Charging profile(s) cleared, dump their stack: %j`, this.chargingStation.getConnector(commandPayload.connectorId).chargingProfiles);
+ this.chargingStation.getConnectorStatus(commandPayload.connectorId).chargingProfiles[index] = {} as OCPP16ChargingProfile;
+ logger.debug(`${this.chargingStation.logPrefix()} Charging profile(s) cleared, dump their stack: %j`, this.chargingStation.getConnectorStatus(commandPayload.connectorId).chargingProfiles);
clearedCP = true;
}
});
private async handleRequestChangeAvailability(commandPayload: ChangeAvailabilityRequest): Promise<ChangeAvailabilityResponse> {
const connectorId: number = commandPayload.connectorId;
- if (!this.chargingStation.getConnector(connectorId)) {
+ if (!this.chargingStation.getConnectorStatus(connectorId)) {
logger.error(`${this.chargingStation.logPrefix()} Trying to change the availability of a non existing connector Id ${connectorId.toString()}`);
return Constants.OCPP_AVAILABILITY_RESPONSE_REJECTED;
}
- const chargePointStatus: OCPP16ChargePointStatus = commandPayload.type === OCPP16AvailabilityType.OPERATIVE ? OCPP16ChargePointStatus.AVAILABLE : OCPP16ChargePointStatus.UNAVAILABLE;
+ const chargePointStatus: OCPP16ChargePointStatus = commandPayload.type === OCPP16AvailabilityType.OPERATIVE
+ ? OCPP16ChargePointStatus.AVAILABLE
+ : OCPP16ChargePointStatus.UNAVAILABLE;
if (connectorId === 0) {
let response: ChangeAvailabilityResponse = Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED;
- for (const connector in this.chargingStation.connectors) {
- if (this.chargingStation.getConnector(Utils.convertToInt(connector))?.transactionStarted) {
+ for (const id of this.chargingStation.connectors.keys()) {
+ if (this.chargingStation.getConnectorStatus(id)?.transactionStarted) {
response = Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED;
}
- this.chargingStation.getConnector(Utils.convertToInt(connector)).availability = commandPayload.type;
+ this.chargingStation.getConnectorStatus(id).availability = commandPayload.type;
if (response === Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED) {
- await this.chargingStation.ocppRequestService.sendStatusNotification(Utils.convertToInt(connector), chargePointStatus);
- this.chargingStation.getConnector(Utils.convertToInt(connector)).status = chargePointStatus;
+ await this.chargingStation.ocppRequestService.sendStatusNotification(id, chargePointStatus);
+ this.chargingStation.getConnectorStatus(id).status = chargePointStatus;
}
}
return response;
- } else if (connectorId > 0 && (this.chargingStation.getConnector(0).availability === OCPP16AvailabilityType.OPERATIVE || (this.chargingStation.getConnector(0).availability === OCPP16AvailabilityType.INOPERATIVE && commandPayload.type === OCPP16AvailabilityType.INOPERATIVE))) {
- if (this.chargingStation.getConnector(connectorId)?.transactionStarted) {
- this.chargingStation.getConnector(connectorId).availability = commandPayload.type;
+ } else if (connectorId > 0 && (this.chargingStation.getConnectorStatus(0).availability === OCPP16AvailabilityType.OPERATIVE || (this.chargingStation.getConnectorStatus(0).availability === OCPP16AvailabilityType.INOPERATIVE && commandPayload.type === OCPP16AvailabilityType.INOPERATIVE))) {
+ if (this.chargingStation.getConnectorStatus(connectorId)?.transactionStarted) {
+ this.chargingStation.getConnectorStatus(connectorId).availability = commandPayload.type;
return Constants.OCPP_AVAILABILITY_RESPONSE_SCHEDULED;
}
- this.chargingStation.getConnector(connectorId).availability = commandPayload.type;
+ this.chargingStation.getConnectorStatus(connectorId).availability = commandPayload.type;
await this.chargingStation.ocppRequestService.sendStatusNotification(connectorId, chargePointStatus);
- this.chargingStation.getConnector(connectorId).status = chargePointStatus;
+ this.chargingStation.getConnectorStatus(connectorId).status = chargePointStatus;
return Constants.OCPP_AVAILABILITY_RESPONSE_ACCEPTED;
}
return Constants.OCPP_AVAILABILITY_RESPONSE_REJECTED;
const transactionConnectorId: number = commandPayload.connectorId;
if (transactionConnectorId) {
await this.chargingStation.ocppRequestService.sendStatusNotification(transactionConnectorId, OCPP16ChargePointStatus.PREPARING);
- this.chargingStation.getConnector(transactionConnectorId).status = OCPP16ChargePointStatus.PREPARING;
+ this.chargingStation.getConnectorStatus(transactionConnectorId).status = OCPP16ChargePointStatus.PREPARING;
if (this.chargingStation.isChargingStationAvailable() && this.chargingStation.isConnectorAvailable(transactionConnectorId)) {
// Check if authorized
if (this.chargingStation.getAuthorizeRemoteTxRequests()) {
}
private async notifyRemoteStartTransactionRejected(connectorId: number, idTag: string): Promise<DefaultResponse> {
- if (this.chargingStation.getConnector(connectorId).status !== OCPP16ChargePointStatus.AVAILABLE) {
+ if (this.chargingStation.getConnectorStatus(connectorId).status !== OCPP16ChargePointStatus.AVAILABLE) {
await this.chargingStation.ocppRequestService.sendStatusNotification(connectorId, OCPP16ChargePointStatus.AVAILABLE);
- this.chargingStation.getConnector(connectorId).status = OCPP16ChargePointStatus.AVAILABLE;
+ this.chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.AVAILABLE;
}
- logger.warn(this.chargingStation.logPrefix() + ' Remote starting transaction REJECTED on connector Id ' + connectorId.toString() + ', idTag ' + idTag + ', availability ' + this.chargingStation.getConnector(connectorId).availability + ', status ' + this.chargingStation.getConnector(connectorId).status);
+ logger.warn(this.chargingStation.logPrefix() + ' Remote starting transaction REJECTED on connector Id ' + connectorId.toString() + ', idTag ' + idTag + ', availability ' + this.chargingStation.getConnectorStatus(connectorId).availability + ', status ' + this.chargingStation.getConnectorStatus(connectorId).status);
return Constants.OCPP_RESPONSE_REJECTED;
}
private setRemoteStartTransactionChargingProfile(connectorId: number, cp: OCPP16ChargingProfile): boolean {
if (cp && cp.chargingProfilePurpose === ChargingProfilePurposeType.TX_PROFILE) {
this.chargingStation.setChargingProfile(connectorId, cp);
- logger.debug(`${this.chargingStation.logPrefix()} Charging profile(s) set at remote start transaction, dump their stack: %j`, this.chargingStation.getConnector(connectorId).chargingProfiles);
+ logger.debug(`${this.chargingStation.logPrefix()} Charging profile(s) set at remote start transaction, dump their stack: %j`, this.chargingStation.getConnectorStatus(connectorId).chargingProfiles);
return true;
} else if (cp && cp.chargingProfilePurpose !== ChargingProfilePurposeType.TX_PROFILE) {
logger.warn(`${this.chargingStation.logPrefix()} Not allowed to set ${cp.chargingProfilePurpose} charging profile(s) at remote start transaction`);
private async handleRequestRemoteStopTransaction(commandPayload: RemoteStopTransactionRequest): Promise<DefaultResponse> {
const transactionId = commandPayload.transactionId;
- for (const connector in this.chargingStation.connectors) {
- if (Utils.convertToInt(connector) > 0 && this.chargingStation.getConnector(Utils.convertToInt(connector))?.transactionId === transactionId) {
- await this.chargingStation.ocppRequestService.sendStatusNotification(Utils.convertToInt(connector), OCPP16ChargePointStatus.FINISHING);
- this.chargingStation.getConnector(Utils.convertToInt(connector)).status = OCPP16ChargePointStatus.FINISHING;
+ for (const connectorId of this.chargingStation.connectors.keys()) {
+ if (connectorId > 0 && this.chargingStation.getConnectorStatus(connectorId)?.transactionId === transactionId) {
+ await this.chargingStation.ocppRequestService.sendStatusNotification(connectorId, OCPP16ChargePointStatus.FINISHING);
+ this.chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.FINISHING;
await this.chargingStation.ocppRequestService.sendStopTransaction(transactionId, this.chargingStation.getEnergyActiveImportRegisterByTransactionId(transactionId),
this.chargingStation.getTransactionIdTag(transactionId));
return Constants.OCPP_RESPONSE_ACCEPTED;
const payload: AuthorizeRequest = {
...!Utils.isUndefined(idTag) ? { idTag } : { idTag: Constants.TRANSACTION_DEFAULT_IDTAG },
};
- this.chargingStation.getConnector(connectorId).authorizeIdTag = idTag;
+ this.chargingStation.getConnectorStatus(connectorId).authorizeIdTag = idTag;
return await this.sendMessage(Utils.generateUUID(), payload, MessageType.CALL_MESSAGE, OCPP16RequestCommand.AUTHORIZE) as OCPP16AuthorizeResponse;
} catch (error) {
this.handleRequestError(OCPP16RequestCommand.AUTHORIZE, error);
reason: OCPP16StopTransactionReason = OCPP16StopTransactionReason.NONE): Promise<OCPP16StopTransactionResponse> {
try {
let connectorId: number;
- for (const connector in this.chargingStation.connectors) {
- if (Utils.convertToInt(connector) > 0 && this.chargingStation.getConnector(Utils.convertToInt(connector))?.transactionId === transactionId) {
- connectorId = Utils.convertToInt(connector);
+ for (const id of this.chargingStation.connectors.keys()) {
+ if (id > 0 && this.chargingStation.getConnectorStatus(id)?.transactionId === transactionId) {
+ connectorId = id;
break;
}
}
meterStop,
timestamp: new Date().toISOString(),
...reason && { reason },
- ...this.chargingStation.getTransactionDataMeterValues() && { transactionData: OCPP16ServiceUtils.buildTransactionDataMeterValues(this.chargingStation.getConnector(connectorId).transactionBeginMeterValue, transactionEndMeterValue) },
+ ...this.chargingStation.getTransactionDataMeterValues() && { transactionData: OCPP16ServiceUtils.buildTransactionDataMeterValues(this.chargingStation.getConnectorStatus(connectorId).transactionBeginMeterValue, transactionEndMeterValue) },
};
return await this.sendMessage(Utils.generateUUID(), payload, MessageType.CALL_MESSAGE, OCPP16RequestCommand.STOP_TRANSACTION) as OCPP16StartTransactionResponse;
} catch (error) {
timestamp: new Date().toISOString(),
sampledValue: [],
};
- const connector = this.chargingStation.getConnector(connectorId);
+ const connector = this.chargingStation.getConnectorStatus(connectorId);
// SoC measurand
const socSampledValueTemplate = this.chargingStation.getSampledValueTemplate(connectorId, OCPP16MeterValueMeasurand.STATE_OF_CHARGE);
if (socSampledValueTemplate) {
private handleResponseAuthorize(payload: OCPP16AuthorizeResponse, requestPayload: AuthorizeRequest): void {
let authorizeConnectorId: number;
- for (const connector in this.chargingStation.connectors) {
- if (Utils.convertToInt(connector) > 0 && this.chargingStation.getConnector(Utils.convertToInt(connector))?.authorizeIdTag === requestPayload.idTag) {
- authorizeConnectorId = Utils.convertToInt(connector);
+ for (const connectorId of this.chargingStation.connectors.keys()) {
+ if (connectorId > 0 && this.chargingStation.getConnectorStatus(connectorId)?.authorizeIdTag === requestPayload.idTag) {
+ authorizeConnectorId = connectorId;
break;
}
}
if (payload.idTagInfo.status === OCPP16AuthorizationStatus.ACCEPTED) {
- this.chargingStation.getConnector(authorizeConnectorId).authorized = true;
+ this.chargingStation.getConnectorStatus(authorizeConnectorId).authorized = true;
logger.debug(`${this.chargingStation.logPrefix()} IdTag ${requestPayload.idTag} authorized on connector ${authorizeConnectorId}`);
} else {
- this.chargingStation.getConnector(authorizeConnectorId).authorized = false;
- delete this.chargingStation.getConnector(authorizeConnectorId).authorizeIdTag;
+ this.chargingStation.getConnectorStatus(authorizeConnectorId).authorized = false;
+ delete this.chargingStation.getConnectorStatus(authorizeConnectorId).authorizeIdTag;
logger.debug(`${this.chargingStation.logPrefix()} IdTag ${requestPayload.idTag} refused with status ${payload.idTagInfo.status} on connector ${authorizeConnectorId}`);
}
}
const connectorId = requestPayload.connectorId;
let transactionConnectorId: number;
- for (const connector in this.chargingStation.connectors) {
- if (Utils.convertToInt(connector) > 0 && Utils.convertToInt(connector) === connectorId) {
- transactionConnectorId = Utils.convertToInt(connector);
+ for (const id of this.chargingStation.connectors.keys()) {
+ if (id > 0 && id === connectorId) {
+ transactionConnectorId = id;
break;
}
}
logger.error(this.chargingStation.logPrefix() + ' Trying to start a transaction on a non existing connector Id ' + connectorId.toString());
return;
}
- if (this.chargingStation.getConnector(connectorId).authorized && this.chargingStation.getConnector(connectorId).authorizeIdTag !== requestPayload.idTag) {
- logger.error(this.chargingStation.logPrefix() + ' Trying to start a transaction with an idTag ' + requestPayload.idTag + ' different from the authorize request one ' + this.chargingStation.getConnector(connectorId).authorizeIdTag + ' on connector Id ' + connectorId.toString());
+ if (this.chargingStation.getConnectorStatus(connectorId).authorized && this.chargingStation.getConnectorStatus(connectorId).authorizeIdTag !== requestPayload.idTag) {
+ logger.error(this.chargingStation.logPrefix() + ' Trying to start a transaction with an idTag ' + requestPayload.idTag + ' different from the authorize request one ' + this.chargingStation.getConnectorStatus(connectorId).authorizeIdTag + ' on connector Id ' + connectorId.toString());
return;
}
- if (this.chargingStation.getConnector(connectorId)?.transactionStarted) {
- logger.debug(this.chargingStation.logPrefix() + ' Trying to start a transaction on an already used connector ' + connectorId.toString() + ': %j', this.chargingStation.getConnector(connectorId));
+ if (this.chargingStation.getConnectorStatus(connectorId)?.transactionStarted) {
+ logger.debug(this.chargingStation.logPrefix() + ' Trying to start a transaction on an already used connector ' + connectorId.toString() + ': %j', this.chargingStation.getConnectorStatus(connectorId));
return;
}
- if (this.chargingStation.getConnector(connectorId)?.status !== OCPP16ChargePointStatus.AVAILABLE
- && this.chargingStation.getConnector(connectorId)?.status !== OCPP16ChargePointStatus.PREPARING) {
- logger.error(`${this.chargingStation.logPrefix()} Trying to start a transaction on connector ${connectorId.toString()} with status ${this.chargingStation.getConnector(connectorId)?.status}`);
+ if (this.chargingStation.getConnectorStatus(connectorId)?.status !== OCPP16ChargePointStatus.AVAILABLE
+ && this.chargingStation.getConnectorStatus(connectorId)?.status !== OCPP16ChargePointStatus.PREPARING) {
+ logger.error(`${this.chargingStation.logPrefix()} Trying to start a transaction on connector ${connectorId.toString()} with status ${this.chargingStation.getConnectorStatus(connectorId)?.status}`);
return;
}
if (!Number.isInteger(payload.transactionId)) {
}
if (payload.idTagInfo?.status === OCPP16AuthorizationStatus.ACCEPTED) {
- this.chargingStation.getConnector(connectorId).transactionStarted = true;
- this.chargingStation.getConnector(connectorId).transactionId = payload.transactionId;
- this.chargingStation.getConnector(connectorId).transactionIdTag = requestPayload.idTag;
- this.chargingStation.getConnector(connectorId).transactionEnergyActiveImportRegisterValue = 0;
- this.chargingStation.getConnector(connectorId).transactionBeginMeterValue = OCPP16ServiceUtils.buildTransactionBeginMeterValue(this.chargingStation, connectorId,
+ this.chargingStation.getConnectorStatus(connectorId).transactionStarted = true;
+ this.chargingStation.getConnectorStatus(connectorId).transactionId = payload.transactionId;
+ this.chargingStation.getConnectorStatus(connectorId).transactionIdTag = requestPayload.idTag;
+ this.chargingStation.getConnectorStatus(connectorId).transactionEnergyActiveImportRegisterValue = 0;
+ this.chargingStation.getConnectorStatus(connectorId).transactionBeginMeterValue = OCPP16ServiceUtils.buildTransactionBeginMeterValue(this.chargingStation, connectorId,
requestPayload.meterStart);
this.chargingStation.getBeginEndMeterValues() && await this.chargingStation.ocppRequestService.sendTransactionBeginMeterValues(connectorId, payload.transactionId,
- this.chargingStation.getConnector(connectorId).transactionBeginMeterValue);
+ this.chargingStation.getConnectorStatus(connectorId).transactionBeginMeterValue);
await this.chargingStation.ocppRequestService.sendStatusNotification(connectorId, OCPP16ChargePointStatus.CHARGING);
- this.chargingStation.getConnector(connectorId).status = OCPP16ChargePointStatus.CHARGING;
+ this.chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.CHARGING;
logger.info(this.chargingStation.logPrefix() + ' Transaction ' + payload.transactionId.toString() + ' STARTED on ' + this.chargingStation.stationInfo.chargingStationId + '#' + connectorId.toString() + ' for idTag ' + requestPayload.idTag);
if (this.chargingStation.stationInfo.powerSharedByConnectors) {
this.chargingStation.stationInfo.powerDivider++;
} else {
logger.warn(this.chargingStation.logPrefix() + ' Starting transaction id ' + payload.transactionId.toString() + ' REJECTED with status ' + payload?.idTagInfo?.status + ', idTag ' + requestPayload.idTag);
this.chargingStation.resetTransactionOnConnector(connectorId);
- if (this.chargingStation.getConnector(connectorId).status !== OCPP16ChargePointStatus.AVAILABLE) {
+ if (this.chargingStation.getConnectorStatus(connectorId).status !== OCPP16ChargePointStatus.AVAILABLE) {
await this.chargingStation.ocppRequestService.sendStatusNotification(connectorId, OCPP16ChargePointStatus.AVAILABLE);
- this.chargingStation.getConnector(connectorId).status = OCPP16ChargePointStatus.AVAILABLE;
+ this.chargingStation.getConnectorStatus(connectorId).status = OCPP16ChargePointStatus.AVAILABLE;
}
}
}
private async handleResponseStopTransaction(payload: OCPP16StopTransactionResponse, requestPayload: StopTransactionRequest): Promise<void> {
let transactionConnectorId: number;
- for (const connector in this.chargingStation.connectors) {
- if (Utils.convertToInt(connector) > 0 && this.chargingStation.getConnector(Utils.convertToInt(connector))?.transactionId === requestPayload.transactionId) {
- transactionConnectorId = Utils.convertToInt(connector);
+ for (const connectorId of this.chargingStation.connectors.keys()) {
+ if (connectorId > 0 && this.chargingStation.getConnectorStatus(connectorId)?.transactionId === requestPayload.transactionId) {
+ transactionConnectorId = connectorId;
break;
}
}
OCPP16ServiceUtils.buildTransactionEndMeterValue(this.chargingStation, transactionConnectorId, requestPayload.meterStop));
if (!this.chargingStation.isChargingStationAvailable() || !this.chargingStation.isConnectorAvailable(transactionConnectorId)) {
await this.chargingStation.ocppRequestService.sendStatusNotification(transactionConnectorId, OCPP16ChargePointStatus.UNAVAILABLE);
- this.chargingStation.getConnector(transactionConnectorId).status = OCPP16ChargePointStatus.UNAVAILABLE;
+ this.chargingStation.getConnectorStatus(transactionConnectorId).status = OCPP16ChargePointStatus.UNAVAILABLE;
} else {
await this.chargingStation.ocppRequestService.sendStatusNotification(transactionConnectorId, OCPP16ChargePointStatus.AVAILABLE);
- this.chargingStation.getConnector(transactionConnectorId).status = OCPP16ChargePointStatus.AVAILABLE;
+ this.chargingStation.getConnectorStatus(transactionConnectorId).status = OCPP16ChargePointStatus.AVAILABLE;
}
if (this.chargingStation.stationInfo.powerSharedByConnectors) {
this.chargingStation.stationInfo.powerDivider--;
import ChargingStationConfiguration from './ChargingStationConfiguration';
-import { Connectors } from './Connectors';
+import { ConnectorStatus } from './Connectors';
import { OCPPProtocol } from './ocpp/OCPPProtocol';
import { OCPPVersion } from './ocpp/OCPPVersion';
phaseLineToLineVoltageMeterValues?: boolean;
Configuration?: ChargingStationConfiguration;
AutomaticTransactionGenerator: AutomaticTransactionGenerator;
- Connectors: Connectors;
+ Connectors: Record<string, ConnectorStatus>;
}
fluctuationPercent?: number;
}
-export interface Connector {
+export interface ConnectorStatus {
availability: AvailabilityType;
bootStatus?: ChargePointStatus;
status?: ChargePointStatus;
transactionBeginMeterValue?: MeterValue;
chargingProfiles?: ChargingProfile[];
}
-
-export type Connectors = Record<string, Connector>;