AvailabilityType,
BootNotificationRequest,
CachedRequest,
+ HeartbeatRequest,
IncomingRequest,
IncomingRequestCommand,
+ MeterValuesRequest,
RequestCommand,
+ StatusNotificationRequest,
} from '../types/ocpp/Requests';
import {
BootNotificationResponse,
RegistrationStatus,
StatusNotificationResponse,
} from '../types/ocpp/Responses';
+import {
+ ChargingProfile,
+ ChargingRateUnitType,
+ ChargingSchedulePeriod,
+} from '../types/ocpp/ChargingProfile';
import ChargingStationConfiguration, { Section } from '../types/ChargingStationConfiguration';
import ChargingStationOcppConfiguration, {
ConfigurationKey,
VendorDefaultParametersKey,
} from '../types/ocpp/Configuration';
import { MeterValue, MeterValueMeasurand, MeterValuePhase } from '../types/ocpp/MeterValues';
-import { StopTransactionReason, StopTransactionResponse } from '../types/ocpp/Transaction';
+import {
+ StopTransactionReason,
+ StopTransactionRequest,
+ StopTransactionResponse,
+} from '../types/ocpp/Transaction';
import { WSError, WebSocketCloseEventStatusCode } from '../types/WebSocket';
import WebSocket, { Data, OPEN, RawData } from 'ws';
import AutomaticTransactionGenerator from './AutomaticTransactionGenerator';
import { ChargePointErrorCode } from '../types/ocpp/ChargePointErrorCode';
import { ChargePointStatus } from '../types/ocpp/ChargePointStatus';
-import { ChargingProfile } from '../types/ocpp/ChargingProfile';
import ChargingStationInfo from '../types/ChargingStationInfo';
import { ChargingStationWorkerMessageEvents } from '../types/ChargingStationWorker';
import Configuration from '../utils/Configuration';
: defaultVoltageOut;
}
- public getMaximumConfiguredPower(): number | undefined {
- let maximumConfiguredPower =
- (this.stationInfo['maxPower'] as number) ?? this.stationInfo.maximumPower;
- if (this.getAmperageLimitation() < this.stationInfo.maximumAmperage) {
- maximumConfiguredPower =
- this.getCurrentOutType() === CurrentType.AC
+ public getConnectorMaximumAvailablePower(connectorId: number): number {
+ let connectorAmperageLimitationPowerLimit: number;
+ if (
+ !Utils.isNullOrUndefined(this.getAmperageLimitation()) &&
+ this.getAmperageLimitation() < this.stationInfo.maximumAmperage
+ ) {
+ connectorAmperageLimitationPowerLimit =
+ (this.getCurrentOutType() === CurrentType.AC
? ACElectricUtils.powerTotal(
this.getNumberOfPhases(),
this.getVoltageOut(),
this.getAmperageLimitation() * this.getNumberOfConnectors()
)
- : DCElectricUtils.power(this.getVoltageOut(), this.getAmperageLimitation());
- }
- return maximumConfiguredPower;
+ : DCElectricUtils.power(this.getVoltageOut(), this.getAmperageLimitation())) /
+ this.stationInfo.powerDivider;
+ }
+ const connectorMaximumPower =
+ ((this.stationInfo['maxPower'] as number) ?? this.stationInfo.maximumPower) /
+ this.stationInfo.powerDivider;
+ const connectorChargingProfilePowerLimit = this.getChargingProfilePowerLimit(connectorId);
+ return Math.min(
+ isNaN(connectorMaximumPower) ? Infinity : connectorMaximumPower,
+ isNaN(connectorAmperageLimitationPowerLimit)
+ ? Infinity
+ : connectorAmperageLimitationPowerLimit,
+ isNaN(connectorChargingProfilePowerLimit) ? Infinity : connectorChargingProfilePowerLimit
+ );
}
public getTransactionIdTag(transactionId: number): string | undefined {
}
if (
measurand !== MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER &&
- !this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData).value.includes(
+ !this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData)?.value.includes(
measurand
)
) {
phase &&
sampledValueTemplates[index]?.phase === phase &&
sampledValueTemplates[index]?.measurand === measurand &&
- this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData).value.includes(
+ this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData)?.value.includes(
measurand
)
) {
!phase &&
!sampledValueTemplates[index].phase &&
sampledValueTemplates[index]?.measurand === measurand &&
- this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData).value.includes(
+ this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData)?.value.includes(
measurand
)
) {
) {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
this.heartbeatSetInterval = setInterval(async (): Promise<void> => {
- await this.ocppRequestService.sendMessageHandler<HeartbeatResponse>(
+ await this.ocppRequestService.sendMessageHandler<HeartbeatRequest, HeartbeatResponse>(
RequestCommand.HEARTBEAT
);
}, this.getHeartbeatInterval());
this.getConnectorStatus(connectorId).transactionId,
interval
);
- await this.ocppRequestService.sendMessageHandler<MeterValuesResponse>(
+ await this.ocppRequestService.sendMessageHandler<MeterValuesRequest, MeterValuesResponse>(
RequestCommand.METER_VALUES,
{
connectorId,
await this.stopMessageSequence(reason);
for (const connectorId of this.connectors.keys()) {
if (connectorId > 0) {
- await this.ocppRequestService.sendMessageHandler<StatusNotificationResponse>(
- RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId,
- status: ChargePointStatus.UNAVAILABLE,
- errorCode: ChargePointErrorCode.NO_ERROR,
- }
- );
+ await this.ocppRequestService.sendMessageHandler<
+ StatusNotificationRequest,
+ StatusNotificationResponse
+ >(RequestCommand.STATUS_NOTIFICATION, {
+ connectorId,
+ status: ChargePointStatus.UNAVAILABLE,
+ errorCode: ChargePointErrorCode.NO_ERROR,
+ });
this.getConnectorStatus(connectorId).status = ChargePointStatus.UNAVAILABLE;
}
}
}
}
+ public getChargingProfilePowerLimit(connectorId: number): number | undefined {
+ const timestamp = new Date().getTime();
+ let matchingChargingProfile: ChargingProfile;
+ let chargingSchedulePeriods: ChargingSchedulePeriod[] = [];
+ if (!Utils.isEmptyArray(this.getConnectorStatus(connectorId)?.chargingProfiles)) {
+ const chargingProfiles: ChargingProfile[] = this.getConnectorStatus(
+ connectorId
+ ).chargingProfiles.filter(
+ (chargingProfile) =>
+ timestamp >= chargingProfile.chargingSchedule?.startSchedule.getTime() &&
+ timestamp <
+ chargingProfile.chargingSchedule?.startSchedule.getTime() +
+ chargingProfile.chargingSchedule.duration * 1000 &&
+ chargingProfile?.stackLevel === Math.max(...chargingProfiles.map((cp) => cp?.stackLevel))
+ );
+ if (!Utils.isEmptyArray(chargingProfiles)) {
+ for (const chargingProfile of chargingProfiles) {
+ if (!Utils.isEmptyArray(chargingProfile.chargingSchedule.chargingSchedulePeriod)) {
+ chargingSchedulePeriods =
+ chargingProfile.chargingSchedule.chargingSchedulePeriod.filter(
+ (chargingSchedulePeriod, index) => {
+ timestamp >=
+ chargingProfile.chargingSchedule.startSchedule.getTime() +
+ chargingSchedulePeriod.startPeriod * 1000 &&
+ ((chargingProfile.chargingSchedule.chargingSchedulePeriod[index + 1] &&
+ timestamp <
+ chargingProfile.chargingSchedule.startSchedule.getTime() +
+ chargingProfile.chargingSchedule.chargingSchedulePeriod[index + 1]
+ ?.startPeriod *
+ 1000) ||
+ !chargingProfile.chargingSchedule.chargingSchedulePeriod[index + 1]);
+ }
+ );
+ if (!Utils.isEmptyArray(chargingSchedulePeriods)) {
+ matchingChargingProfile = chargingProfile;
+ break;
+ }
+ }
+ }
+ }
+ }
+ let limit: number;
+ if (!Utils.isEmptyArray(chargingSchedulePeriods)) {
+ switch (this.getCurrentOutType()) {
+ case CurrentType.AC:
+ limit =
+ matchingChargingProfile.chargingSchedule.chargingRateUnit === ChargingRateUnitType.WATT
+ ? chargingSchedulePeriods[0].limit
+ : ACElectricUtils.powerTotal(
+ this.getNumberOfPhases(),
+ this.getVoltageOut(),
+ chargingSchedulePeriods[0].limit
+ );
+ break;
+ case CurrentType.DC:
+ limit =
+ matchingChargingProfile.chargingSchedule.chargingRateUnit === ChargingRateUnitType.WATT
+ ? chargingSchedulePeriods[0].limit
+ : DCElectricUtils.power(this.getVoltageOut(), chargingSchedulePeriods[0].limit);
+ }
+ }
+ const connectorMaximumPower =
+ ((this.stationInfo['maxPower'] as number) ?? this.stationInfo.maximumPower) /
+ this.stationInfo.powerDivider;
+ if (limit > connectorMaximumPower) {
+ logger.error(
+ `${this.logPrefix()} Charging profile id ${
+ matchingChargingProfile.chargingProfileId
+ } limit is greater than connector id ${connectorId} maximum, dump charging profiles' stack: %j`,
+ this.getConnectorStatus(connectorId).chargingProfiles
+ );
+ limit = connectorMaximumPower;
+ }
+ return limit;
+ }
+
public setChargingProfile(connectorId: number, cp: ChargingProfile): void {
let cpReplaced = false;
if (!Utils.isEmptyArray(this.getConnectorStatus(connectorId).chargingProfiles)) {
this.stopMeterValues(connectorId);
}
+ public hasFeatureProfile(featureProfile: SupportedFeatureProfiles) {
+ return this.getConfigurationKey(StandardParametersKey.SupportedFeatureProfiles)?.value.includes(
+ featureProfile
+ );
+ }
+
public bufferMessage(message: string): void {
this.messageBuffer.add(message);
}
(stationInfo.chargePointSerialNumber = existingStationInfo.chargePointSerialNumber);
existingStationInfo?.chargeBoxSerialNumber &&
(stationInfo.chargeBoxSerialNumber = existingStationInfo.chargeBoxSerialNumber);
+ existingStationInfo?.meterSerialNumber &&
+ (stationInfo.meterSerialNumber = existingStationInfo.meterSerialNumber);
} else {
const serialNumberSuffix = params?.randomSerialNumber
? this.getRandomSerialNumberSuffix({ upperCase: params.randomSerialNumberUpperCase })
stationInfo.chargeBoxSerialNumber =
stationInfo?.chargeBoxSerialNumberPrefix &&
stationInfo.chargeBoxSerialNumberPrefix + serialNumberSuffix;
+ stationInfo.meterSerialNumber =
+ stationInfo?.meterSerialNumberPrefix &&
+ stationInfo.meterSerialNumberPrefix + serialNumberSuffix;
}
}
}),
...(!Utils.isUndefined(stationInfo.iccid) && { iccid: stationInfo.iccid }),
...(!Utils.isUndefined(stationInfo.imsi) && { imsi: stationInfo.imsi }),
- ...(!Utils.isUndefined(stationInfo.meterSerialNumber) && {
- meterSerialNumber: stationInfo.meterSerialNumber,
+ ...(!Utils.isUndefined(stationInfo.meterSerialNumberPrefix) && {
+ meterSerialNumber: stationInfo.meterSerialNumberPrefix,
}),
...(!Utils.isUndefined(stationInfo.meterType) && {
meterType: stationInfo.meterType,
if (!this.getConfigurationKey(StandardParametersKey.SupportedFeatureProfiles)) {
this.addConfigurationKey(
StandardParametersKey.SupportedFeatureProfiles,
- `${SupportedFeatureProfiles.Core},${SupportedFeatureProfiles.Local_Auth_List_Management},${SupportedFeatureProfiles.Smart_Charging}`
+ `${SupportedFeatureProfiles.Core},${SupportedFeatureProfiles.FirmwareManagement},${SupportedFeatureProfiles.LocalAuthListManagement},${SupportedFeatureProfiles.SmartCharging},${SupportedFeatureProfiles.RemoteTrigger}`
);
}
this.addConfigurationKey(
}
if (
!this.getConfigurationKey(StandardParametersKey.LocalAuthListEnabled) &&
- this.getConfigurationKey(StandardParametersKey.SupportedFeatureProfiles).value.includes(
- SupportedFeatureProfiles.Local_Auth_List_Management
+ this.getConfigurationKey(StandardParametersKey.SupportedFeatureProfiles)?.value.includes(
+ SupportedFeatureProfiles.LocalAuthListManagement
)
) {
this.addConfigurationKey(StandardParametersKey.LocalAuthListEnabled, 'false');
// Send BootNotification
let registrationRetryCount = 0;
do {
- this.bootNotificationResponse =
- await this.ocppRequestService.sendMessageHandler<BootNotificationResponse>(
- RequestCommand.BOOT_NOTIFICATION,
- {
- chargePointModel: this.bootNotificationRequest.chargePointModel,
- chargePointVendor: this.bootNotificationRequest.chargePointVendor,
- chargeBoxSerialNumber: this.bootNotificationRequest.chargeBoxSerialNumber,
- firmwareVersion: this.bootNotificationRequest.firmwareVersion,
- chargePointSerialNumber: this.bootNotificationRequest.chargePointSerialNumber,
- iccid: this.bootNotificationRequest.iccid,
- imsi: this.bootNotificationRequest.imsi,
- meterSerialNumber: this.bootNotificationRequest.meterSerialNumber,
- meterType: this.bootNotificationRequest.meterType,
- },
- { skipBufferingOnError: true }
- );
+ this.bootNotificationResponse = await this.ocppRequestService.sendMessageHandler<
+ BootNotificationRequest,
+ BootNotificationResponse
+ >(
+ RequestCommand.BOOT_NOTIFICATION,
+ {
+ chargePointModel: this.bootNotificationRequest.chargePointModel,
+ chargePointVendor: this.bootNotificationRequest.chargePointVendor,
+ chargeBoxSerialNumber: this.bootNotificationRequest.chargeBoxSerialNumber,
+ firmwareVersion: this.bootNotificationRequest.firmwareVersion,
+ chargePointSerialNumber: this.bootNotificationRequest.chargePointSerialNumber,
+ iccid: this.bootNotificationRequest.iccid,
+ imsi: this.bootNotificationRequest.imsi,
+ meterSerialNumber: this.bootNotificationRequest.meterSerialNumber,
+ meterType: this.bootNotificationRequest.meterType,
+ },
+ { skipBufferingOnError: true }
+ );
if (!this.isInAcceptedState()) {
this.getRegistrationMaxRetries() !== -1 && registrationRetryCount++;
await Utils.sleep(
}
private getMaximumAmperage(): number | undefined {
+ const maximumPower = (this.stationInfo['maxPower'] as number) ?? this.stationInfo.maximumPower;
switch (this.getCurrentOutType()) {
case CurrentType.AC:
return ACElectricUtils.amperagePerPhaseFromPower(
this.getNumberOfPhases(),
- ((this.stationInfo['maxPower'] as number) ?? this.stationInfo.maximumPower) /
- this.getNumberOfConnectors(),
+ maximumPower / this.getNumberOfConnectors(),
this.getVoltageOut()
);
case CurrentType.DC:
- return DCElectricUtils.amperage(this.stationInfo.maximumPower, this.getVoltageOut());
+ return DCElectricUtils.amperage(maximumPower, this.getVoltageOut());
}
}
private async startMessageSequence(): Promise<void> {
if (this.stationInfo.autoRegister) {
- await this.ocppRequestService.sendMessageHandler<BootNotificationResponse>(
+ await this.ocppRequestService.sendMessageHandler<
+ BootNotificationRequest,
+ BootNotificationResponse
+ >(
RequestCommand.BOOT_NOTIFICATION,
{
chargePointModel: this.bootNotificationRequest.chargePointModel,
this.getConnectorStatus(connectorId)?.bootStatus
) {
// Send status in template at startup
- await this.ocppRequestService.sendMessageHandler<StatusNotificationResponse>(
- RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId,
- status: this.getConnectorStatus(connectorId).bootStatus,
- errorCode: ChargePointErrorCode.NO_ERROR,
- }
- );
+ await this.ocppRequestService.sendMessageHandler<
+ StatusNotificationRequest,
+ StatusNotificationResponse
+ >(RequestCommand.STATUS_NOTIFICATION, {
+ connectorId,
+ status: this.getConnectorStatus(connectorId).bootStatus,
+ errorCode: ChargePointErrorCode.NO_ERROR,
+ });
this.getConnectorStatus(connectorId).status =
this.getConnectorStatus(connectorId).bootStatus;
} else if (
this.getConnectorStatus(connectorId)?.bootStatus
) {
// Send status in template after reset
- await this.ocppRequestService.sendMessageHandler<StatusNotificationResponse>(
- RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId,
- status: this.getConnectorStatus(connectorId).bootStatus,
- errorCode: ChargePointErrorCode.NO_ERROR,
- }
- );
+ await this.ocppRequestService.sendMessageHandler<
+ StatusNotificationRequest,
+ StatusNotificationResponse
+ >(RequestCommand.STATUS_NOTIFICATION, {
+ connectorId,
+ status: this.getConnectorStatus(connectorId).bootStatus,
+ errorCode: ChargePointErrorCode.NO_ERROR,
+ });
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.sendMessageHandler<StatusNotificationResponse>(
- RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId,
- status: this.getConnectorStatus(connectorId).status,
- errorCode: ChargePointErrorCode.NO_ERROR,
- }
- );
+ await this.ocppRequestService.sendMessageHandler<
+ StatusNotificationRequest,
+ StatusNotificationResponse
+ >(RequestCommand.STATUS_NOTIFICATION, {
+ connectorId,
+ status: this.getConnectorStatus(connectorId).status,
+ errorCode: ChargePointErrorCode.NO_ERROR,
+ });
} else {
// Send default status
- await this.ocppRequestService.sendMessageHandler<StatusNotificationResponse>(
- RequestCommand.STATUS_NOTIFICATION,
- {
- connectorId,
- status: ChargePointStatus.AVAILABLE,
- errorCode: ChargePointErrorCode.NO_ERROR,
- }
- );
+ await this.ocppRequestService.sendMessageHandler<
+ StatusNotificationRequest,
+ StatusNotificationResponse
+ >(RequestCommand.STATUS_NOTIFICATION, {
+ connectorId,
+ status: ChargePointStatus.AVAILABLE,
+ errorCode: ChargePointErrorCode.NO_ERROR,
+ });
this.getConnectorStatus(connectorId).status = ChargePointStatus.AVAILABLE;
}
}
connectorId,
this.getEnergyActiveImportRegisterByTransactionId(transactionId)
);
- await this.ocppRequestService.sendMessageHandler<MeterValuesResponse>(
- RequestCommand.METER_VALUES,
- {
- connectorId,
- transactionId,
- meterValue: transactionEndMeterValue,
- }
- );
- }
- await this.ocppRequestService.sendMessageHandler<StopTransactionResponse>(
- RequestCommand.STOP_TRANSACTION,
- {
+ await this.ocppRequestService.sendMessageHandler<
+ MeterValuesRequest,
+ MeterValuesResponse
+ >(RequestCommand.METER_VALUES, {
+ connectorId,
transactionId,
- meterStop: this.getEnergyActiveImportRegisterByTransactionId(transactionId),
- idTag: this.getTransactionIdTag(transactionId),
- reason,
- }
- );
+ meterValue: transactionEndMeterValue,
+ });
+ }
+ await this.ocppRequestService.sendMessageHandler<
+ StopTransactionRequest,
+ StopTransactionResponse
+ >(RequestCommand.STOP_TRANSACTION, {
+ transactionId,
+ meterStop: this.getEnergyActiveImportRegisterByTransactionId(transactionId),
+ idTag: this.getTransactionIdTag(transactionId),
+ reason,
+ });
}
}
}