+export const 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;
+};
+
+export const createBootNotificationRequest = (
+ stationInfo: ChargingStationInfo,
+ bootReason: BootReasonEnumType = BootReasonEnumType.PowerUp,
+): BootNotificationRequest => {
+ const ocppVersion = stationInfo.ocppVersion ?? OCPPVersion.VERSION_16;
+ switch (ocppVersion) {
+ case OCPPVersion.VERSION_16:
+ return {
+ chargePointModel: stationInfo.chargePointModel,
+ chargePointVendor: stationInfo.chargePointVendor,
+ ...(!isUndefined(stationInfo.chargeBoxSerialNumber) && {
+ chargeBoxSerialNumber: stationInfo.chargeBoxSerialNumber,
+ }),
+ ...(!isUndefined(stationInfo.chargePointSerialNumber) && {
+ chargePointSerialNumber: stationInfo.chargePointSerialNumber,
+ }),
+ ...(!isUndefined(stationInfo.firmwareVersion) && {
+ firmwareVersion: stationInfo.firmwareVersion,
+ }),
+ ...(!isUndefined(stationInfo.iccid) && { iccid: stationInfo.iccid }),
+ ...(!isUndefined(stationInfo.imsi) && { imsi: stationInfo.imsi }),
+ ...(!isUndefined(stationInfo.meterSerialNumber) && {
+ meterSerialNumber: stationInfo.meterSerialNumber,
+ }),
+ ...(!isUndefined(stationInfo.meterType) && {
+ meterType: stationInfo.meterType,
+ }),
+ } as OCPP16BootNotificationRequest;
+ case OCPPVersion.VERSION_20:
+ case OCPPVersion.VERSION_201:
+ return {
+ reason: bootReason,
+ chargingStation: {
+ model: stationInfo.chargePointModel,
+ vendorName: stationInfo.chargePointVendor,
+ ...(!isUndefined(stationInfo.firmwareVersion) && {
+ firmwareVersion: stationInfo.firmwareVersion,
+ }),
+ ...(!isUndefined(stationInfo.chargeBoxSerialNumber) && {
+ serialNumber: stationInfo.chargeBoxSerialNumber,
+ }),
+ ...((!isUndefined(stationInfo.iccid) || !isUndefined(stationInfo.imsi)) && {
+ modem: {
+ ...(!isUndefined(stationInfo.iccid) && { iccid: stationInfo.iccid }),
+ ...(!isUndefined(stationInfo.imsi) && { imsi: stationInfo.imsi }),
+ },
+ }),
+ },
+ } as OCPP20BootNotificationRequest;
+ }
+};
+
+export const warnTemplateKeysDeprecation = (
+ stationTemplate: ChargingStationTemplate,
+ logPrefix: string,
+ templateFile: string,
+) => {
+ const templateKeys: { deprecatedKey: string; key?: string }[] = [
+ { deprecatedKey: 'supervisionUrl', key: 'supervisionUrls' },
+ { deprecatedKey: 'authorizationFile', key: 'idTagsFile' },
+ { deprecatedKey: 'payloadSchemaValidation', key: 'ocppStrictCompliance' },
+ ];
+ for (const templateKey of templateKeys) {
+ warnDeprecatedTemplateKey(
+ stationTemplate,
+ templateKey.deprecatedKey,
+ logPrefix,
+ templateFile,
+ !isUndefined(templateKey.key) ? `Use '${templateKey.key}' instead` : undefined,
+ );
+ convertDeprecatedTemplateKey(stationTemplate, templateKey.deprecatedKey, templateKey.key);
+ }
+};
+
+export const stationTemplateToStationInfo = (
+ stationTemplate: ChargingStationTemplate,
+): ChargingStationInfo => {
+ stationTemplate = cloneObject<ChargingStationTemplate>(stationTemplate);
+ delete stationTemplate.power;
+ delete stationTemplate.powerUnit;
+ delete stationTemplate.Connectors;
+ delete stationTemplate.Evses;
+ delete stationTemplate.Configuration;
+ delete stationTemplate.AutomaticTransactionGenerator;
+ delete stationTemplate.chargeBoxSerialNumberPrefix;
+ delete stationTemplate.chargePointSerialNumberPrefix;
+ delete stationTemplate.meterSerialNumberPrefix;
+ return stationTemplate as unknown as ChargingStationInfo;
+};
+
+export const createSerialNumber = (
+ stationTemplate: ChargingStationTemplate,
+ stationInfo: ChargingStationInfo,
+ params: {
+ randomSerialNumberUpperCase?: boolean;
+ randomSerialNumber?: boolean;
+ } = {
+ randomSerialNumberUpperCase: true,
+ randomSerialNumber: true,
+ },
+): void => {
+ params = { ...{ randomSerialNumberUpperCase: true, randomSerialNumber: true }, ...params };
+ const serialNumberSuffix = params?.randomSerialNumber
+ ? getRandomSerialNumberSuffix({
+ upperCase: params.randomSerialNumberUpperCase,
+ })
+ : '';
+ isNotEmptyString(stationTemplate?.chargePointSerialNumberPrefix) &&
+ (stationInfo.chargePointSerialNumber = `${stationTemplate.chargePointSerialNumberPrefix}${serialNumberSuffix}`);
+ isNotEmptyString(stationTemplate?.chargeBoxSerialNumberPrefix) &&
+ (stationInfo.chargeBoxSerialNumber = `${stationTemplate.chargeBoxSerialNumberPrefix}${serialNumberSuffix}`);
+ isNotEmptyString(stationTemplate?.meterSerialNumberPrefix) &&
+ (stationInfo.meterSerialNumber = `${stationTemplate.meterSerialNumberPrefix}${serialNumberSuffix}`);
+};
+
+export const propagateSerialNumber = (
+ stationTemplate: ChargingStationTemplate,
+ stationInfoSrc: ChargingStationInfo,
+ stationInfoDst: ChargingStationInfo,
+) => {
+ if (!stationInfoSrc || !stationTemplate) {
+ throw new BaseError(
+ 'Missing charging station template or existing configuration to propagate serial number',
+ );
+ }
+ stationTemplate?.chargePointSerialNumberPrefix && stationInfoSrc?.chargePointSerialNumber
+ ? (stationInfoDst.chargePointSerialNumber = stationInfoSrc.chargePointSerialNumber)
+ : stationInfoDst?.chargePointSerialNumber && delete stationInfoDst.chargePointSerialNumber;
+ stationTemplate?.chargeBoxSerialNumberPrefix && stationInfoSrc?.chargeBoxSerialNumber
+ ? (stationInfoDst.chargeBoxSerialNumber = stationInfoSrc.chargeBoxSerialNumber)
+ : stationInfoDst?.chargeBoxSerialNumber && delete stationInfoDst.chargeBoxSerialNumber;
+ stationTemplate?.meterSerialNumberPrefix && stationInfoSrc?.meterSerialNumber
+ ? (stationInfoDst.meterSerialNumber = stationInfoSrc.meterSerialNumber)
+ : stationInfoDst?.meterSerialNumber && delete stationInfoDst.meterSerialNumber;
+};
+
+export const getAmperageLimitationUnitDivider = (stationInfo: ChargingStationInfo): number => {
+ let unitDivider = 1;
+ switch (stationInfo.amperageLimitationUnit) {
+ case AmpereUnits.DECI_AMPERE:
+ unitDivider = 10;
+ break;
+ case AmpereUnits.CENTI_AMPERE:
+ unitDivider = 100;
+ break;
+ case AmpereUnits.MILLI_AMPERE:
+ unitDivider = 1000;
+ break;