X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Focpp%2F1.6%2FOCPP16ServiceUtils.ts;h=23381f9ec3dd63e5e47faed0301fc6fecbc01f75;hb=7671fa0be211e944f027ebd83f3a0ad64c2ef2d6;hp=47c711af16fa7f5ba300bd51ab620b20f147188c;hpb=4ecff7ce6e87af51f1ff04e95641aee2270fbdb0;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts index 47c711af..23381f9e 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts @@ -1,8 +1,5 @@ // Partial Copyright Jerome Benoit. 2021-2023. All Rights Reserved. -import path from 'node:path'; -import { fileURLToPath } from 'node:url'; - import type { JSONSchemaType } from 'ajv'; import type { ChargingStation } from '../../../charging-station'; @@ -16,8 +13,6 @@ import { MeterValueContext, MeterValueLocation, MeterValueUnit, - OCPP16ChargePointErrorCode, - type OCPP16ChargePointStatus, type OCPP16ChargingProfile, type OCPP16IncomingRequestCommand, type OCPP16MeterValue, @@ -26,15 +21,13 @@ import { OCPP16RequestCommand, type OCPP16SampledValue, OCPP16StandardParametersKey, - type OCPP16StatusNotificationRequest, - type OCPP16StatusNotificationResponse, type OCPP16SupportedFeatureProfiles, OCPPVersion, type SampledValueTemplate, Voltage, } from '../../../types'; import { ACElectricUtils, Constants, DCElectricUtils, Utils, logger } from '../../../utils'; -import { OCPP16Constants, OCPPServiceUtils } from '../internal'; +import { OCPPServiceUtils } from '../OCPPServiceUtils'; export class OCPP16ServiceUtils extends OCPPServiceUtils { public static checkFeatureProfile( @@ -93,7 +86,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { `${chargingStation.logPrefix()} MeterValues measurand ${ meterValue.sampledValue[sampledValuesIndex].measurand ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER - }: connectorId ${connectorId}, transaction ${ + }: connector id ${connectorId}, transaction id ${ connector?.transactionId }, value: ${socMinimumValue}/${ meterValue.sampledValue[sampledValuesIndex].value @@ -388,7 +381,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { `${chargingStation.logPrefix()} MeterValues measurand ${ meterValue.sampledValue[sampledValuesIndex].measurand ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER - }: connectorId ${connectorId}, transaction ${ + }: connector id ${connectorId}, transaction id ${ connector?.transactionId }, value: ${connectorMinimumPowerRounded}/${ meterValue.sampledValue[sampledValuesIndex].value @@ -432,7 +425,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER }: phase ${ meterValue.sampledValue[sampledValuesPerPhaseIndex].phase - }, connectorId ${connectorId}, transaction ${ + }, connector id ${connectorId}, transaction id ${ connector?.transactionId }, value: ${connectorMinimumPowerPerPhaseRounded}/${ meterValue.sampledValue[sampledValuesPerPhaseIndex].value @@ -613,7 +606,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { `${chargingStation.logPrefix()} MeterValues measurand ${ meterValue.sampledValue[sampledValuesIndex].measurand ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER - }: connectorId ${connectorId}, transaction ${ + }: connector id ${connectorId}, transaction id ${ connector?.transactionId }, value: ${connectorMinimumAmperage}/${ meterValue.sampledValue[sampledValuesIndex].value @@ -649,7 +642,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER }: phase ${ meterValue.sampledValue[sampledValuesPerPhaseIndex].phase - }, connectorId ${connectorId}, transaction ${ + }, connector id ${connectorId}, transaction id ${ connector?.transactionId }, value: ${connectorMinimumAmperage}/${ meterValue.sampledValue[sampledValuesPerPhaseIndex].value @@ -720,7 +713,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { `${chargingStation.logPrefix()} MeterValues measurand ${ meterValue.sampledValue[sampledValuesIndex].measurand ?? OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER - }: connectorId ${connectorId}, transaction ${ + }: connector id ${connectorId}, transaction id ${ connector?.transactionId }, value: ${energyValueRounded}/${connectorMaximumEnergyRounded}, duration: ${Utils.roundTo( interval / (3600 * 1000), @@ -801,7 +794,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { Utils.isNullOrUndefined(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles) ) { logger.error( - `${chargingStation.logPrefix()} Trying to set a charging profile on connectorId ${connectorId} with an uninitialized charging profiles array attribute, applying deferred initialization` + `${chargingStation.logPrefix()} Trying to set a charging profile on connector id ${connectorId} with an uninitialized charging profiles array attribute, applying deferred initialization` ); chargingStation.getConnectorStatus(connectorId).chargingProfiles = []; } @@ -809,7 +802,7 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { Array.isArray(chargingStation.getConnectorStatus(connectorId)?.chargingProfiles) === false ) { logger.error( - `${chargingStation.logPrefix()} Trying to set a charging profile on connectorId ${connectorId} with an improper attribute type for the charging profiles array, applying proper type initialization` + `${chargingStation.logPrefix()} Trying to set a charging profile on connector id ${connectorId} with an improper attribute type for the charging profiles array, applying proper type initialization` ); chargingStation.getConnectorStatus(connectorId).chargingProfiles = []; } @@ -837,62 +830,13 @@ export class OCPP16ServiceUtils extends OCPPServiceUtils { methodName?: string ): JSONSchemaType { return super.parseJsonSchemaFile( - path.resolve(path.dirname(fileURLToPath(import.meta.url)), relativePath), + relativePath, OCPPVersion.VERSION_16, moduleName, methodName ); } - public static async sendAndSetConnectorStatus( - chargingStation: ChargingStation, - connectorId: number, - status: OCPP16ChargePointStatus, - errorCode: OCPP16ChargePointErrorCode = OCPP16ChargePointErrorCode.NO_ERROR - ) { - OCPP16ServiceUtils.checkConnectorStatusTransition(chargingStation, connectorId, status); - await chargingStation.ocppRequestService.requestHandler< - OCPP16StatusNotificationRequest, - OCPP16StatusNotificationResponse - >(chargingStation, OCPP16RequestCommand.STATUS_NOTIFICATION, { - connectorId, - status, - errorCode, - }); - chargingStation.getConnectorStatus(connectorId).status = status; - } - - private static checkConnectorStatusTransition( - chargingStation: ChargingStation, - connectorId: number, - status: OCPP16ChargePointStatus - ): void { - if ( - connectorId === 0 && - !OCPP16Constants.OCPP16ChargePointStatusChargingStationTransition.has([ - chargingStation.getConnectorStatus(connectorId).status as OCPP16ChargePointStatus, - status, - ]) - ) { - logger.warn( - `${chargingStation.logPrefix()} Connector ${connectorId} status transition from ${ - chargingStation.getConnectorStatus(connectorId).status - } to ${status} is not allowed` - ); - } else if ( - !OCPP16Constants.OCPP16ChargePointStatusConnectorTransition.has([ - chargingStation.getConnectorStatus(connectorId).status as OCPP16ChargePointStatus, - status, - ]) - ) { - logger.warn( - `${chargingStation.logPrefix()} Connector ${connectorId} status transition from ${ - chargingStation.getConnectorStatus(connectorId).status - } to ${status} is not allowed` - ); - } - } - private static buildSampledValue( sampledValueTemplate: SampledValueTemplate, value: number,