Remove circular deps between CS Vendors -> OCPPUtils
MODIFY
src/integration/charging-station-vendor/ChargingStationVendorIntegration.ts
src/integration/charging-station-vendor/ChargingStationVendorIntegration.ts
@@ -7,7 +7,7 @@ import ChargingStationClientFactory from '../../client/ocpp/ChargingStationClien
import ChargingStationStorage from '../../storage/mongodb/ChargingStationStorage';
import Constants from '../../utils/Constants';
import Logging from '../../utils/Logging';
-import OCPPUtils from '../../server/ocpp/utils/OCPPUtils';
+import OCPPCommon from '../../server/ocpp/utils/OCPPCommon';
import { ServerAction } from '../../types/Server';
import Tenant from '../../types/Tenant';
import Utils from '../../utils/Utils';
@@ -114,7 +114,7 @@ export default abstract class ChargingStationVendorIntegration {
detailedMessages: { maxAmps, ocppParam: chargePoint.ocppParamForPowerLimitation, ocppLimitAmpValue: ocppLimitAmpValue }
});
// Change the OCPP Parameter
- result = await OCPPUtils.requestChangeChargingStationOcppParameter(tenant, chargingStation, {
+ result = await OCPPCommon.requestChangeChargingStationOcppParameter(tenant, chargingStation, {
key: chargePoint.ocppParamForPowerLimitation,
value: ocppLimitAmpValue.toString()
});

MODIFY
src/scheduler/tasks/CheckOfflineChargingStationsTask.ts
src/scheduler/tasks/CheckOfflineChargingStationsTask.ts
@@ -6,8 +6,8 @@ import { LockEntity } from '../../types/Locking';
import LockingManager from '../../locking/LockingManager';
import Logging from '../../utils/Logging';
import NotificationHandler from '../../notification/NotificationHandler';
+import OCPPCommon from '../../server/ocpp/utils/OCPPCommon';
import { OCPPGetConfigurationCommandResult } from '../../types/ocpp/OCPPClient';
-import OCPPUtils from '../../server/ocpp/utils/OCPPUtils';
import SchedulerTask from '../SchedulerTask';
import { ServerAction } from '../../types/Server';
import Tenant from '../../types/Tenant';
@@ -35,7 +35,7 @@ export default class CheckOfflineChargingStationsTask extends SchedulerTask {
try {
// Send credentials to get the token
ocppHeartbeatConfiguration = await Utils.executePromiseWithTimeout(
- 5000, OCPPUtils.requestChargingStationOcppParameters(tenant, chargingStation, { key: Constants.OCPP_HEARTBEAT_KEYS as string[] }),
+ 5000, OCPPCommon.requestChargingStationOcppParameters(tenant, chargingStation, { key: Constants.OCPP_HEARTBEAT_KEYS as string[] }),
`Time out error (5s) when trying to get OCPP configuration from '${chargingStation.id}'`
);
} catch (error) {

MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
import { ChargePointErrorCode, ChargePointStatus, OCPPAttribute, OCPPAuthorizationStatus, OCPPAuthorizeRequestExtended, OCPPAuthorizeResponse, OCPPBootNotificationRequestExtended, OCPPBootNotificationResponse, OCPPDataTransferRequestExtended, OCPPDataTransferResponse, OCPPDataTransferStatus, OCPPDiagnosticsStatusNotificationRequestExtended, OCPPDiagnosticsStatusNotificationResponse, OCPPFirmwareStatusNotificationRequestExtended, OCPPFirmwareStatusNotificationResponse, OCPPHeartbeatRequestExtended, OCPPHeartbeatResponse, OCPPLocation, OCPPMeasurand, OCPPMeterValue, OCPPMeterValuesRequest, OCPPMeterValuesRequestExtended, OCPPMeterValuesResponse, OCPPNormalizedMeterValue, OCPPNormalizedMeterValues, OCPPPhase, OCPPProtocol, OCPPReadingContext, OCPPSampledValue, OCPPStartTransactionRequestExtended, OCPPStartTransactionResponse, OCPPStatusNotificationRequestExtended, OCPPStatusNotificationResponse, OCPPStopTransactionRequestExtended, OCPPStopTransactionResponse, OCPPUnitOfMeasure, OCPPValueFormat, OCPPVersion, RegistrationStatus } from '../../../types/ocpp/OCPPServer';
import { ChargingProfilePurposeType, ChargingRateUnitType } from '../../../types/ChargingProfile';
import ChargingStation, { ChargerVendor, Connector, ConnectorCurrentLimitSource, ConnectorType, CurrentType, StaticLimitAmps, TemplateUpdateResult } from '../../../types/ChargingStation';
-import { OCPPChangeConfigurationCommandResult, OCPPConfigurationStatus, OCPPRemoteStartStopStatus } from '../../../types/ocpp/OCPPClient';
+import { OCPPConfigurationStatus, OCPPRemoteStartStopStatus } from '../../../types/ocpp/OCPPClient';
import Tenant, { TenantComponents } from '../../../types/Tenant';
import Transaction, { InactivityStatus, TransactionAction } from '../../../types/Transaction';
@@ -25,6 +25,7 @@ import Logging from '../../../utils/Logging';
import NotificationHandler from '../../../notification/NotificationHandler';
import OCPIClientFactory from '../../../client/ocpi/OCPIClientFactory';
import { OCPIRole } from '../../../types/ocpi/OCPIRole';
+import OCPPCommon from '../utils/OCPPCommon';
import { OCPPHeader } from '../../../types/ocpp/OCPPHeader';
import OCPPStorage from '../../../storage/mongodb/OCPPStorage';
import OCPPUtils from '../utils/OCPPUtils';
@@ -1958,7 +1959,7 @@ export default class OCPPService {
// Synchronize heartbeat interval OCPP parameter for charging stations that do not take into account its value in the boot notification response
for (const heartbeatOcppKey of Constants.OCPP_HEARTBEAT_KEYS) {
try {
- const result = await OCPPUtils.requestChangeChargingStationOcppParameter(tenant, chargingStation, {
+ const result = await OCPPCommon.requestChangeChargingStationOcppParameter(tenant, chargingStation, {
key: heartbeatOcppKey,
value: heartbeatIntervalSecs.toString()
}, false);

ADD
src/server/ocpp/utils/OCPPCommon.ts
+import ChargingStation, { ChargingStationOcppParameters } from '../../../types/ChargingStation';
+import { OCPPChangeConfigurationCommandParam, OCPPChangeConfigurationCommandResult, OCPPConfigurationStatus, OCPPGetConfigurationCommandParam, OCPPGetConfigurationCommandResult, OCPPResetCommandResult, OCPPResetStatus, OCPPResetType } from '../../../types/ocpp/OCPPClient';
+
+import BackendError from '../../../exception/BackendError';
+import ChargingStationClientFactory from '../../../client/ocpp/ChargingStationClientFactory';
+import ChargingStationStorage from '../../../storage/mongodb/ChargingStationStorage';
+import Constants from '../../../utils/Constants';
+import Logging from '../../../utils/Logging';
+import { ServerAction } from '../../../types/Server';
+import Tenant from '../../../types/Tenant';
+import Utils from '../../../utils/Utils';
+
+const MODULE_NAME = 'OCPPCommon';
+
+export default class OCPPCommon {
+ public static async requestChangeChargingStationOcppParameter(tenant: Tenant, chargingStation: ChargingStation, params: OCPPChangeConfigurationCommandParam,
+ saveChange = true, triggerConditionalReset = false): Promise<OCPPChangeConfigurationCommandResult> {
+ // Get the OCPP Client
+ const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant, chargingStation);
+ if (!chargingStationClient) {
+ throw new BackendError({
+ chargingStationID: chargingStation.id,
+ siteID: chargingStation.siteID,
+ siteAreaID: chargingStation.siteAreaID,
+ companyID: chargingStation.companyID,
+ action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION,
+ module: MODULE_NAME, method: 'requestChangeChargingStationOcppParameter',
+ message: 'Charging Station is not connected to the backend',
+ });
+ }
+ // Apply the configuration change
+ const result = await chargingStationClient.changeConfiguration(params);
+ const isValidResultStatus: boolean = result.status === OCPPConfigurationStatus.ACCEPTED || result.status === OCPPConfigurationStatus.REBOOT_REQUIRED;
+ // Request the new Configuration?
+ if (saveChange && isValidResultStatus) {
+ // Request and save it
+ await OCPPCommon.requestAndSaveChargingStationOcppParameters(tenant, chargingStation);
+ }
+ if (triggerConditionalReset && result.status === OCPPConfigurationStatus.REBOOT_REQUIRED) {
+ await Logging.logInfo({
+ tenantID: tenant.id,
+ siteID: chargingStation.siteID,
+ siteAreaID: chargingStation.siteAreaID,
+ companyID: chargingStation.companyID,
+ chargingStationID: chargingStation.id,
+ action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION,
+ module: MODULE_NAME, method: 'requestChangeChargingStationOcppParameter',
+ message: `Reboot triggered due to change of OCPP Parameter '${params.key}' to '${params.value}'`,
+ detailedMessages: { result }
+ });
+ await OCPPCommon.triggerChargingStationReset(tenant, chargingStation, true);
+ }
+ // Return
+ return result;
+ }
+
+ public static async requestAndSaveChargingStationOcppParameters(tenant: Tenant, chargingStation: ChargingStation): Promise<OCPPChangeConfigurationCommandResult> {
+ try {
+ // Get the OCPP Configuration
+ const ocppConfiguration = await OCPPCommon.requestChargingStationOcppParameters(tenant, chargingStation, {});
+ await Logging.logDebug({
+ tenantID: tenant.id,
+ siteID: chargingStation.siteID,
+ siteAreaID: chargingStation.siteAreaID,
+ companyID: chargingStation.companyID,
+ chargingStationID: chargingStation.id,
+ action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION,
+ module: MODULE_NAME, method: 'requestAndSaveChargingStationOcppParameters',
+ message: 'Get charging station OCPP parameters successfully',
+ detailedMessages: { ocppConfiguration }
+ });
+ // Set OCPP configuration
+ const chargingStationOcppParameters: ChargingStationOcppParameters = {
+ id: chargingStation.id,
+ configuration: ocppConfiguration.configurationKey,
+ timestamp: new Date()
+ };
+ // Get saved OCPP configuration from DB
+ const ocppParametersFromDB = await ChargingStationStorage.getOcppParameters(tenant, chargingStation.id);
+ // Charging Station configuration not found
+ if (!chargingStationOcppParameters.configuration) {
+ if (ocppParametersFromDB.count === 0) {
+ // No config at all: set default OCPP configuration
+ chargingStationOcppParameters.configuration = Constants.DEFAULT_OCPP_16_CONFIGURATION;
+ } else {
+ // Set from DB
+ chargingStationOcppParameters.configuration = ocppParametersFromDB.result;
+ }
+ }
+ // Add the existing custom params
+ const customParams = ocppParametersFromDB.result.filter((customParam) => customParam.custom);
+ if (!Utils.isEmptyArray(customParams)) {
+ for (const customParam of customParams) {
+ const foundCustomParam = chargingStationOcppParameters.configuration.find((configuration) => configuration.key === customParam.key);
+ if (!foundCustomParam) {
+ chargingStationOcppParameters.configuration.push(customParam);
+ }
+ }
+ }
+ // Save configuration
+ await ChargingStationStorage.saveOcppParameters(tenant, chargingStationOcppParameters);
+ // Ok
+ await Logging.logInfo({
+ tenantID: tenant.id,
+ siteID: chargingStation.siteID,
+ siteAreaID: chargingStation.siteAreaID,
+ companyID: chargingStation.companyID,
+ chargingStationID: chargingStation.id,
+ action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION,
+ module: MODULE_NAME, method: 'requestAndSaveChargingStationOcppParameters',
+ message: 'Save charging station OCPP parameters successfully'
+ });
+ return { status: OCPPConfigurationStatus.ACCEPTED };
+ } catch (error) {
+ await Logging.logActionExceptionMessage(tenant.id, ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, error);
+ return { status: OCPPConfigurationStatus.REJECTED };
+ }
+ }
+
+ public static async triggerChargingStationReset(tenant: Tenant, chargingStation: ChargingStation,
+ hardResetFallback = false, resetType: OCPPResetType = OCPPResetType.SOFT): Promise<OCPPResetCommandResult> {
+ // Get the Charging Station client
+ const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant, chargingStation);
+ if (!chargingStationClient) {
+ throw new BackendError({
+ chargingStationID: chargingStation.id,
+ siteID: chargingStation.siteID,
+ siteAreaID: chargingStation.siteAreaID,
+ companyID: chargingStation.companyID,
+ action: ServerAction.CHARGING_STATION_RESET,
+ module: MODULE_NAME, method: 'triggerChargingStationReset',
+ message: 'Charging Station is not connected to the backend',
+ });
+ }
+ let resetResult = await chargingStationClient.reset({ type: resetType });
+ if (resetResult.status === OCPPResetStatus.REJECTED) {
+ await Logging.logError({
+ tenantID: tenant.id,
+ siteID: chargingStation.siteID,
+ siteAreaID: chargingStation.siteAreaID,
+ companyID: chargingStation.companyID,
+ chargingStationID: chargingStation.id,
+ action: ServerAction.CHARGING_STATION_RESET,
+ module: MODULE_NAME, method: 'triggerChargingStationReset',
+ message: `Error at ${resetType} Rebooting charging station`,
+ });
+ if (hardResetFallback && resetType !== OCPPResetType.HARD) {
+ await Logging.logInfo({
+ tenantID: tenant.id,
+ siteID: chargingStation.siteID,
+ siteAreaID: chargingStation.siteAreaID,
+ companyID: chargingStation.companyID,
+ chargingStationID: chargingStation.id,
+ action: ServerAction.CHARGING_STATION_RESET,
+ module: MODULE_NAME, method: 'triggerChargingStationReset',
+ message: `Conditional ${OCPPResetType.HARD} Reboot requested`,
+ });
+ resetResult = await chargingStationClient.reset({ type: OCPPResetType.HARD });
+ if (resetResult.status === OCPPResetStatus.REJECTED) {
+ await Logging.logError({
+ tenantID: tenant.id,
+ siteID: chargingStation.siteID,
+ siteAreaID: chargingStation.siteAreaID,
+ companyID: chargingStation.companyID,
+ chargingStationID: chargingStation.id,
+ action: ServerAction.CHARGING_STATION_RESET,
+ module: MODULE_NAME, method: 'triggerChargingStationReset',
+ message: `Error at ${OCPPResetType.HARD} Rebooting charging station`,
+ });
+ }
+ }
+ }
+ return resetResult;
+ }
+
+ public static async requestChargingStationOcppParameters(tenant: Tenant, chargingStation: ChargingStation,
+ params: OCPPGetConfigurationCommandParam): Promise<OCPPGetConfigurationCommandResult> {
+ // Get the OCPP Client
+ const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant, chargingStation);
+ if (!chargingStationClient) {
+ throw new BackendError({
+ chargingStationID: chargingStation.id,
+ siteID: chargingStation.siteID,
+ siteAreaID: chargingStation.siteAreaID,
+ companyID: chargingStation.companyID,
+ action: ServerAction.CHARGING_STATION_REQUEST_OCPP_PARAMETERS,
+ module: MODULE_NAME, method: 'requestChargingStationOcppParameters',
+ message: 'Charging Station is not connected to the backend',
+ });
+ }
+ // Get the configuration
+ const result = await chargingStationClient.getConfiguration(params);
+ // Return
+ return result;
+ }
+}

MODIFY
src/server/ocpp/utils/OCPPUtils.ts
src/server/ocpp/utils/OCPPUtils.ts
import { BillingDataTransactionStart, BillingDataTransactionStop } from '../../../types/Billing';
import { ChargingProfile, ChargingProfilePurposeType } from '../../../types/ChargingProfile';
import ChargingStation, { ChargingStationCapabilities, ChargingStationOcppParameters, ChargingStationTemplate, Command, Connector, ConnectorCurrentLimitSource, CurrentType, OcppParameter, SiteAreaLimitSource, StaticLimitAmps, TemplateUpdate, TemplateUpdateResult } from '../../../types/ChargingStation';
-import { OCPPChangeConfigurationCommandParam, OCPPChangeConfigurationCommandResult, OCPPChargingProfileStatus, OCPPConfigurationStatus, OCPPGetConfigurationCommandParam, OCPPGetConfigurationCommandResult, OCPPResetCommandResult, OCPPResetStatus, OCPPResetType } from '../../../types/ocpp/OCPPClient';
+import { OCPPChangeConfigurationCommandResult, OCPPChargingProfileStatus, OCPPConfigurationStatus, OCPPGetConfigurationCommandParam, OCPPGetConfigurationCommandResult, OCPPResetCommandResult, OCPPResetStatus, OCPPResetType } from '../../../types/ocpp/OCPPClient';
import { OCPPMeasurand, OCPPNormalizedMeterValue, OCPPPhase, OCPPReadingContext, OCPPStopTransactionRequestExtended, OCPPUnitOfMeasure, OCPPValueFormat } from '../../../types/ocpp/OCPPServer';
import { OICPIdentification, OICPSessionID } from '../../../types/oicp/OICPIdentification';
import Tenant, { TenantComponents } from '../../../types/Tenant';
@@ -25,6 +25,7 @@ import LockingManager from '../../../locking/LockingManager';
import Logging from '../../../utils/Logging';
import OCPIClientFactory from '../../../client/ocpi/OCPIClientFactory';
import { OCPIRole } from '../../../types/ocpi/OCPIRole';
+import OCPPCommon from './OCPPCommon';
import { OCPPHeader } from '../../../types/ocpp/OCPPHeader';
import OICPClientFactory from '../../../client/oicp/OICPClientFactory';
import { OICPRole } from '../../../types/oicp/OICPRole';
@@ -1227,7 +1228,7 @@ export default class OCPPUtils {
});
// Request and save the latest OCPP parameters
let result = await Utils.executePromiseWithTimeout<OCPPChangeConfigurationCommandResult>(
- Constants.DELAY_CHANGE_CONFIGURATION_EXECUTION_MILLIS, OCPPUtils.requestAndSaveChargingStationOcppParameters(tenant, chargingStation),
+ Constants.DELAY_CHANGE_CONFIGURATION_EXECUTION_MILLIS, OCPPCommon.requestAndSaveChargingStationOcppParameters(tenant, chargingStation),
`Time out error (${Constants.DELAY_CHANGE_CONFIGURATION_EXECUTION_MILLIS.toString()} ms) in requesting OCPP Parameters`);
// Update the OCPP Parameters from the template
result = await Utils.executePromiseWithTimeout<OCPPChangeConfigurationCommandResult>(
@@ -1642,69 +1643,6 @@ export default class OCPPUtils {
return { tenant, chargingStation, token, lock };
}
- public static async requestAndSaveChargingStationOcppParameters(tenant: Tenant, chargingStation: ChargingStation): Promise<OCPPChangeConfigurationCommandResult> {
- try {
- // Get the OCPP Configuration
- const ocppConfiguration = await OCPPUtils.requestChargingStationOcppParameters(tenant, chargingStation, {});
- await Logging.logDebug({
- tenantID: tenant.id,
- siteID: chargingStation.siteID,
- siteAreaID: chargingStation.siteAreaID,
- companyID: chargingStation.companyID,
- chargingStationID: chargingStation.id,
- action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION,
- module: MODULE_NAME, method: 'requestAndSaveChargingStationOcppParameters',
- message: 'Get charging station OCPP parameters successfully',
- detailedMessages: { ocppConfiguration }
- });
- // Set OCPP configuration
- const chargingStationOcppParameters: ChargingStationOcppParameters = {
- id: chargingStation.id,
- configuration: ocppConfiguration.configurationKey,
- timestamp: new Date()
- };
- // Get saved OCPP configuration from DB
- const ocppParametersFromDB = await ChargingStationStorage.getOcppParameters(tenant, chargingStation.id);
- // Charging Station configuration not found
- if (!chargingStationOcppParameters.configuration) {
- if (ocppParametersFromDB.count === 0) {
- // No config at all: set default OCPP configuration
- chargingStationOcppParameters.configuration = Constants.DEFAULT_OCPP_16_CONFIGURATION;
- } else {
- // Set from DB
- chargingStationOcppParameters.configuration = ocppParametersFromDB.result;
- }
- }
- // Add the existing custom params
- const customParams = ocppParametersFromDB.result.filter((customParam) => customParam.custom);
- if (!Utils.isEmptyArray(customParams)) {
- for (const customParam of customParams) {
- const foundCustomParam = chargingStationOcppParameters.configuration.find((configuration) => configuration.key === customParam.key);
- if (!foundCustomParam) {
- chargingStationOcppParameters.configuration.push(customParam);
- }
- }
- }
- // Save configuration
- await ChargingStationStorage.saveOcppParameters(tenant, chargingStationOcppParameters);
- // Ok
- await Logging.logInfo({
- tenantID: tenant.id,
- siteID: chargingStation.siteID,
- siteAreaID: chargingStation.siteAreaID,
- companyID: chargingStation.companyID,
- chargingStationID: chargingStation.id,
- action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION,
- module: MODULE_NAME, method: 'requestAndSaveChargingStationOcppParameters',
- message: 'Save charging station OCPP parameters successfully'
- });
- return { status: OCPPConfigurationStatus.ACCEPTED };
- } catch (error) {
- await Logging.logActionExceptionMessage(tenant.id, ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION, error);
- return { status: OCPPConfigurationStatus.REJECTED };
- }
- }
-
public static async updateChargingStationOcppParametersWithTemplate(tenant: Tenant, chargingStation: ChargingStation): Promise<OCPPChangeConfigurationCommandResult> {
let result: OCPPChangeConfigurationCommandResult;
const updatedOcppParameters: ActionsResponse = {
@@ -1756,7 +1694,7 @@ export default class OCPPUtils {
continue;
}
// Execute OCPP change configuration command
- result = await OCPPUtils.requestChangeChargingStationOcppParameter(tenant, chargingStation, {
+ result = await OCPPCommon.requestChangeChargingStationOcppParameter(tenant, chargingStation, {
key: ocppParameter.key,
value: ocppParameter.value
}, false);
@@ -1823,77 +1761,15 @@ export default class OCPPUtils {
);
// Parameter(s) updated?
if (updatedOcppParameters.inSuccess) {
- result = await OCPPUtils.requestAndSaveChargingStationOcppParameters(tenant, chargingStation);
+ result = await OCPPCommon.requestAndSaveChargingStationOcppParameters(tenant, chargingStation);
}
// Reboot required?
if (rebootRequired) {
- await OCPPUtils.triggerChargingStationReset(tenant, chargingStation, true);
+ await OCPPCommon.triggerChargingStationReset(tenant, chargingStation, true);
}
return result;
}
- public static async requestChangeChargingStationOcppParameter(tenant: Tenant, chargingStation: ChargingStation, params: OCPPChangeConfigurationCommandParam,
- saveChange = true, triggerConditionalReset = false): Promise<OCPPChangeConfigurationCommandResult> {
- // Get the OCPP Client
- const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant, chargingStation);
- if (!chargingStationClient) {
- throw new BackendError({
- chargingStationID: chargingStation.id,
- siteID: chargingStation.siteID,
- siteAreaID: chargingStation.siteAreaID,
- companyID: chargingStation.companyID,
- action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION,
- module: MODULE_NAME, method: 'requestChangeChargingStationOcppParameter',
- message: 'Charging Station is not connected to the backend',
- });
- }
- // Apply the configuration change
- const result = await chargingStationClient.changeConfiguration(params);
- const isValidResultStatus: boolean = result.status === OCPPConfigurationStatus.ACCEPTED || result.status === OCPPConfigurationStatus.REBOOT_REQUIRED;
- // Request the new Configuration?
- if (saveChange && isValidResultStatus) {
- // Request and save it
- await OCPPUtils.requestAndSaveChargingStationOcppParameters(tenant, chargingStation);
- }
- if (triggerConditionalReset && result.status === OCPPConfigurationStatus.REBOOT_REQUIRED) {
- await Logging.logInfo({
- tenantID: tenant.id,
- siteID: chargingStation.siteID,
- siteAreaID: chargingStation.siteAreaID,
- companyID: chargingStation.companyID,
- chargingStationID: chargingStation.id,
- action: ServerAction.CHARGING_STATION_CHANGE_CONFIGURATION,
- module: MODULE_NAME, method: 'requestChangeChargingStationOcppParameter',
- message: `Reboot triggered due to change of OCPP Parameter '${params.key}' to '${params.value}'`,
- detailedMessages: { result }
- });
- await OCPPUtils.triggerChargingStationReset(tenant, chargingStation, true);
- }
- // Return
- return result;
- }
-
- public static async requestChargingStationOcppParameters(tenant: Tenant, chargingStation: ChargingStation,
- params: OCPPGetConfigurationCommandParam): Promise<OCPPGetConfigurationCommandResult> {
- // Get the OCPP Client
- const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant, chargingStation);
- if (!chargingStationClient) {
- throw new BackendError({
- chargingStationID: chargingStation.id,
- siteID: chargingStation.siteID,
- siteAreaID: chargingStation.siteAreaID,
- companyID: chargingStation.companyID,
- action: ServerAction.CHARGING_STATION_REQUEST_OCPP_PARAMETERS,
- module: MODULE_NAME, method: 'requestChargingStationOcppParameters',
- message: 'Charging Station is not connected to the backend',
- });
- }
- // Get the configuration
- const result = await chargingStationClient.getConfiguration(params);
- // Return
- return result;
- }
-
public static clearChargingStationConnectorRuntimeData(chargingStation: ChargingStation, connectorID: number): void {
// Cleanup connector transaction data
const foundConnector = Utils.getConnectorFromID(chargingStation, connectorID);
@@ -1910,63 +1786,6 @@ export default class OCPPUtils {
}
}
- public static async triggerChargingStationReset(tenant: Tenant, chargingStation: ChargingStation,
- hardResetFallback = false, resetType: OCPPResetType = OCPPResetType.SOFT): Promise<OCPPResetCommandResult> {
- // Get the Charging Station client
- const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant, chargingStation);
- if (!chargingStationClient) {
- throw new BackendError({
- chargingStationID: chargingStation.id,
- siteID: chargingStation.siteID,
- siteAreaID: chargingStation.siteAreaID,
- companyID: chargingStation.companyID,
- action: ServerAction.CHARGING_STATION_RESET,
- module: MODULE_NAME, method: 'triggerChargingStationReset',
- message: 'Charging Station is not connected to the backend',
- });
- }
-
- let resetResult = await chargingStationClient.reset({ type: resetType });
- if (resetResult.status === OCPPResetStatus.REJECTED) {
- await Logging.logError({
- tenantID: tenant.id,
- siteID: chargingStation.siteID,
- siteAreaID: chargingStation.siteAreaID,
- companyID: chargingStation.companyID,
- chargingStationID: chargingStation.id,
- action: ServerAction.CHARGING_STATION_RESET,
- module: MODULE_NAME, method: 'triggerChargingStationReset',
- message: `Error at ${resetType} Rebooting charging station`,
- });
- if (hardResetFallback && resetType !== OCPPResetType.HARD) {
- await Logging.logInfo({
- tenantID: tenant.id,
- siteID: chargingStation.siteID,
- siteAreaID: chargingStation.siteAreaID,
- companyID: chargingStation.companyID,
- chargingStationID: chargingStation.id,
- action: ServerAction.CHARGING_STATION_RESET,
- module: MODULE_NAME, method: 'triggerChargingStationReset',
- message: `Conditional ${OCPPResetType.HARD} Reboot requested`,
- });
- resetResult = await chargingStationClient.reset({ type: OCPPResetType.HARD });
- if (resetResult.status === OCPPResetStatus.REJECTED) {
- await Logging.logError({
- tenantID: tenant.id,
- siteID: chargingStation.siteID,
- siteAreaID: chargingStation.siteAreaID,
- companyID: chargingStation.companyID,
- chargingStationID: chargingStation.id,
- action: ServerAction.CHARGING_STATION_RESET,
- module: MODULE_NAME, method: 'triggerChargingStationReset',
- message: `Error at ${OCPPResetType.HARD} Rebooting charging station`,
- });
- }
- }
- }
- return resetResult;
- }
-
public static updateSignedData(transaction: Transaction, meterValue: OCPPNormalizedMeterValue): boolean {
if (meterValue.attribute.format === OCPPValueFormat.SIGNED_DATA) {
if (meterValue.attribute.context === OCPPReadingContext.TRANSACTION_BEGIN) {

MODIFY
src/server/rest/v1/service/ChargingStationService.ts
src/server/rest/v1/service/ChargingStationService.ts
@@ -27,6 +27,7 @@ import Logging from '../../../../utils/Logging';
import OCPIClientFactory from '../../../../client/ocpi/OCPIClientFactory';
import { OCPIEvseStatus } from '../../../../types/ocpi/OCPIEvse';
import { OCPIRole } from '../../../../types/ocpi/OCPIRole';
+import OCPPCommon from '../../../ocpp/utils/OCPPCommon';
import OCPPStorage from '../../../../storage/mongodb/OCPPStorage';
import OCPPUtils from '../../../ocpp/utils/OCPPUtils';
import { OICPActionType } from '../../../../types/oicp/OICPEvseData';
@@ -309,7 +310,7 @@ export default class ChargingStationService {
if (resetAndApplyTemplate) {
try {
// Use the reset to apply the template again
- await OCPPUtils.triggerChargingStationReset(req.tenant, chargingStation, true);
+ await OCPPCommon.triggerChargingStationReset(req.tenant, chargingStation, true);
} catch (error) {
throw new AppError({
action: action,
@@ -796,7 +797,7 @@ export default class ChargingStationService {
UtilsService.assertObjectExists(action, chargingStation, `Charging Station ID '${filteredRequest.chargingStationID}' does not exist`,
MODULE_NAME, 'handleRequestChargingStationOcppParameters', req.user);
// Get the configuration
- let result = await OCPPUtils.requestAndSaveChargingStationOcppParameters(req.tenant, chargingStation);
+ let result = await OCPPCommon.requestAndSaveChargingStationOcppParameters(req.tenant, chargingStation);
if (filteredRequest.forceUpdateOCPPParamsFromTemplate) {
result = await OCPPUtils.updateChargingStationOcppParametersWithTemplate(req.tenant, chargingStation);
}
@@ -1961,7 +1962,7 @@ export default class ChargingStationService {
await ChargingStationStorage.saveOcppParameters(req.tenant, chargingStationOcppParameters);
} else {
// Not a custom param: refresh the whole OCPP Parameters
- await OCPPUtils.requestAndSaveChargingStationOcppParameters(req.tenant, chargingStation);
+ await OCPPCommon.requestAndSaveChargingStationOcppParameters(req.tenant, chargingStation);
}
} else {
// Add custom param
@@ -1971,7 +1972,7 @@ export default class ChargingStationService {
}
} else {
// Refresh the whole OCPP Parameters
- await OCPPUtils.requestAndSaveChargingStationOcppParameters(req.tenant, chargingStation);
+ await OCPPCommon.requestAndSaveChargingStationOcppParameters(req.tenant, chargingStation);
}
// Check update with Vendor
const chargingStationVendor = ChargingStationVendorFactory.getChargingStationVendorImpl(chargingStation);

Remove circular deps between CS Vendors -> OCPPUtils