Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Enforce SupportedFeatureProfiles check on some OCPP commands
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
  • Loading branch information
Jérôme Benoit committed Mar 29, 2022
1 parent ddab9df commit 68cb8b9
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ make SUBMODULES_INIT=true
#### Smart Charging Profile

- :white_check_mark: ClearChargingProfile
- :white_check_mark: GetCompositeSchedule
- :x: GetCompositeSchedule
- :white_check_mark: SetChargingProfile

#### Remote Trigger Profile
Expand Down
2 changes: 1 addition & 1 deletion src/assets/station-templates/abb-atg.station-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{
"key": "SupportedFeatureProfiles",
"readonly": true,
"value": "Core,LocalAuthListManagement"
"value": "Core,FirmwareManagement,LocalAuthListManagement,SmartCharging,RemoteTrigger"
},
{
"key": "LocalAuthListEnabled",
Expand Down
2 changes: 1 addition & 1 deletion src/assets/station-templates/abb.station-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{
"key": "SupportedFeatureProfiles",
"readonly": true,
"value": "Core,LocalAuthListManagement"
"value": "Core,FirmwareManagement,LocalAuthListManagement,SmartCharging,RemoteTrigger"
},
{
"key": "LocalAuthListEnabled",
Expand Down
4 changes: 2 additions & 2 deletions src/assets/station-templates/evlink.station-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{
"key": "MeterValuesSampledData",
"readonly": false,
"value": "Energy.Active.Import.Register"
"value": "Energy.Active.Import.Register,Current.Import,Voltage"
},
{
"key": "MeterValueSampleInterval",
Expand All @@ -29,7 +29,7 @@
{
"key": "SupportedFeatureProfiles",
"readonly": true,
"value": "Core,LocalAuthListManagement"
"value": "Core,FirmwareManagement,LocalAuthListManagement,SmartCharging,RemoteTrigger"
},
{
"key": "LocalAuthListEnabled",
Expand Down
2 changes: 1 addition & 1 deletion src/assets/station-templates/keba.station-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
{
"key": "SupportedFeatureProfiles",
"readonly": true,
"value": "Core,LocalAuthListManagement"
"value": "Core,FirmwareManagement,LocalAuthListManagement,SmartCharging,RemoteTrigger"
},
{
"key": "LocalAuthListEnabled",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{
"key": "MeterValuesSampledData",
"readonly": false,
"value": "Energy.Active.Import.Register"
"value": "Energy.Active.Import.Register,Current.Import,Voltage"
},
{
"key": "MeterValueSampleInterval",
Expand All @@ -28,7 +28,7 @@
{
"key": "SupportedFeatureProfiles",
"readonly": true,
"value": "Core,LocalAuthListManagement"
"value": "Core,FirmwareManagement,LocalAuthListManagement,SmartCharging,RemoteTrigger"
},
{
"key": "LocalAuthListEnabled",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{
"key": "SupportedFeatureProfiles",
"readonly": true,
"value": "Core,LocalAuthListManagement"
"value": "Core,FirmwareManagement,LocalAuthListManagement,SmartCharging,RemoteTrigger"
},
{
"key": "LocalAuthListEnabled",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
{
"key": "MeterValuesSampledData",
"readonly": false,
"value": "SoC,Energy.Active.Import.Register"
"value": "SoC,Energy.Active.Import.Register,Voltage"
},
{
"key": "MeterValueSampleInterval",
Expand All @@ -24,7 +24,7 @@
{
"key": "SupportedFeatureProfiles",
"readonly": true,
"value": "Core,LocalAuthListManagement"
"value": "Core,FirmwareManagement,LocalAuthListManagement,SmartCharging,RemoteTrigger"
},
{
"key": "LocalAuthListEnabled",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{
"key": "SupportedFeatureProfiles",
"readonly": true,
"value": "Core,LocalAuthListManagement"
"value": "Core,FirmwareManagement,LocalAuthListManagement,SmartCharging,RemoteTrigger"
},
{
"key": "LocalAuthListEnabled",
Expand Down
2 changes: 1 addition & 1 deletion src/assets/station-templates/virtual.station-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
{
"key": "SupportedFeatureProfiles",
"readonly": true,
"value": "Core,LocalAuthListManagement"
"value": "Core,FirmwareManagement,LocalAuthListManagement,SmartCharging,RemoteTrigger"
},
{
"key": "LocalAuthListEnabled",
Expand Down
16 changes: 11 additions & 5 deletions src/charging-station/ChargingStation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ export default class ChargingStation {
}
if (
measurand !== MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER &&
!this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData).value.includes(
!this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData)?.value.includes(
measurand
)
) {
Expand Down Expand Up @@ -400,7 +400,7 @@ export default class ChargingStation {
phase &&
sampledValueTemplates[index]?.phase === phase &&
sampledValueTemplates[index]?.measurand === measurand &&
this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData).value.includes(
this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData)?.value.includes(
measurand
)
) {
Expand All @@ -409,7 +409,7 @@ export default class ChargingStation {
!phase &&
!sampledValueTemplates[index].phase &&
sampledValueTemplates[index]?.measurand === measurand &&
this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData).value.includes(
this.getConfigurationKey(StandardParametersKey.MeterValuesSampledData)?.value.includes(
measurand
)
) {
Expand Down Expand Up @@ -837,6 +837,12 @@ export default class ChargingStation {
this.stopMeterValues(connectorId);
}

public hasFeatureProfile(featureProfile: SupportedFeatureProfiles) {
return this.getConfigurationKey(StandardParametersKey.SupportedFeatureProfiles)?.value.includes(
featureProfile
);
}

public bufferMessage(message: string): void {
this.messageBuffer.add(message);
}
Expand Down Expand Up @@ -1230,7 +1236,7 @@ export default class ChargingStation {
if (!this.getConfigurationKey(StandardParametersKey.SupportedFeatureProfiles)) {
this.addConfigurationKey(
StandardParametersKey.SupportedFeatureProfiles,
`${SupportedFeatureProfiles.Core},${SupportedFeatureProfiles.Local_Auth_List_Management},${SupportedFeatureProfiles.Smart_Charging}`
`${SupportedFeatureProfiles.Core},${SupportedFeatureProfiles.Firmware_Management},${SupportedFeatureProfiles.Local_Auth_List_Management},${SupportedFeatureProfiles.Smart_Charging},${SupportedFeatureProfiles.Remote_Trigger}`
);
}
this.addConfigurationKey(
Expand Down Expand Up @@ -1270,7 +1276,7 @@ export default class ChargingStation {
}
if (
!this.getConfigurationKey(StandardParametersKey.LocalAuthListEnabled) &&
this.getConfigurationKey(StandardParametersKey.SupportedFeatureProfiles).value.includes(
this.getConfigurationKey(StandardParametersKey.SupportedFeatureProfiles)?.value.includes(
SupportedFeatureProfiles.Local_Auth_List_Management
)
) {
Expand Down
47 changes: 46 additions & 1 deletion src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ import {
OCPP16MeterValuesRequest,
OCPP16MeterValuesResponse,
} from '../../../types/ocpp/1.6/MeterValues';
import {
OCPP16StandardParametersKey,
OCPP16SupportedFeatureProfiles,
} from '../../../types/ocpp/1.6/Configuration';

import type ChargingStation from '../../ChargingStation';
import Constants from '../../../utils/Constants';
Expand All @@ -65,7 +69,6 @@ import { OCPP16ChargePointErrorCode } from '../../../types/ocpp/1.6/ChargePointE
import { OCPP16ChargePointStatus } from '../../../types/ocpp/1.6/ChargePointStatus';
import { OCPP16DiagnosticsStatus } from '../../../types/ocpp/1.6/DiagnosticsStatus';
import { OCPP16ServiceUtils } from './OCPP16ServiceUtils';
import { OCPP16StandardParametersKey } from '../../../types/ocpp/1.6/Configuration';
import { OCPPConfigurationKey } from '../../../types/ocpp/Configuration';
import OCPPError from '../../../exception/OCPPError';
import OCPPIncomingRequestService from '../OCPPIncomingRequestService';
Expand Down Expand Up @@ -378,6 +381,16 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
private handleRequestSetChargingProfile(
commandPayload: SetChargingProfileRequest
): SetChargingProfileResponse {
if (!this.chargingStation.hasFeatureProfile(OCPP16SupportedFeatureProfiles.Smart_Charging)) {
logger.error(
`${this.chargingStation.logPrefix()} Trying to set charging profile(s) without '${
OCPP16SupportedFeatureProfiles.Smart_Charging
}' feature enabled in ${
OCPP16StandardParametersKey.SupportedFeatureProfiles
} in configuration`
);
return Constants.OCPP_SET_CHARGING_PROFILE_RESPONSE_NOT_SUPPORTED;
}
if (!this.chargingStation.getConnectorStatus(commandPayload.connectorId)) {
logger.error(
`${this.chargingStation.logPrefix()} Trying to set charging profile(s) to a non existing connector Id ${
Expand Down Expand Up @@ -417,6 +430,16 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
private handleRequestClearChargingProfile(
commandPayload: ClearChargingProfileRequest
): ClearChargingProfileResponse {
if (!this.chargingStation.hasFeatureProfile(OCPP16SupportedFeatureProfiles.Smart_Charging)) {
logger.error(
`${this.chargingStation.logPrefix()} Trying to clear charging profile(s) without '${
OCPP16SupportedFeatureProfiles.Smart_Charging
}' feature enabled in ${
OCPP16StandardParametersKey.SupportedFeatureProfiles
} in configuration`
);
return Constants.OCPP_CLEAR_CHARGING_PROFILE_RESPONSE_UNKNOWN;
}
const connectorStatus = this.chargingStation.getConnectorStatus(commandPayload.connectorId);
if (!connectorStatus) {
logger.error(
Expand Down Expand Up @@ -804,6 +827,18 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
private async handleRequestGetDiagnostics(
commandPayload: GetDiagnosticsRequest
): Promise<GetDiagnosticsResponse> {
if (
!this.chargingStation.hasFeatureProfile(OCPP16SupportedFeatureProfiles.Firmware_Management)
) {
logger.error(
`${this.chargingStation.logPrefix()} Trying to get diagnostics without '${
OCPP16SupportedFeatureProfiles.Firmware_Management
}' feature enabled in ${
OCPP16StandardParametersKey.SupportedFeatureProfiles
} in configuration`
);
return Constants.OCPP_RESPONSE_EMPTY;
}
logger.debug(
this.chargingStation.logPrefix() +
' ' +
Expand Down Expand Up @@ -911,6 +946,16 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
private handleRequestTriggerMessage(
commandPayload: OCPP16TriggerMessageRequest
): OCPP16TriggerMessageResponse {
if (!this.chargingStation.hasFeatureProfile(OCPP16SupportedFeatureProfiles.Remote_Trigger)) {
logger.error(
`${this.chargingStation.logPrefix()} Trying to remote trigger message without '${
OCPP16SupportedFeatureProfiles.Remote_Trigger
}' feature enabled in ${
OCPP16StandardParametersKey.SupportedFeatureProfiles
} in configuration`
);
return Constants.OCPP_TRIGGER_MESSAGE_RESPONSE_NOT_IMPLEMENTED;
}
try {
switch (commandPayload.requestedMessage) {
case MessageTrigger.BootNotification:
Expand Down

0 comments on commit 68cb8b9

Please sign in to comment.