Skip to content

Commit

Permalink
Harden clear charging Profile if connector id is present
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Suess <[email protected]>
  • Loading branch information
Matthias-NIDEC committed Dec 20, 2024
1 parent 1d90f5b commit c72225a
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions lib/ocpp/v16/charge_point_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2386,18 +2386,28 @@ void ChargePointImpl::handleClearChargingProfileRequest(ocpp::Call<ClearCharging
ClearChargingProfileResponse response;
response.status = ClearChargingProfileStatus::Unknown;

// clear all charging profiles
if (!call.msg.id && !call.msg.connectorId && !call.msg.chargingProfilePurpose && !call.msg.stackLevel) {
this->smart_charging_handler->clear_all_profiles();
response.status = ClearChargingProfileStatus::Accepted;
} else if (call.msg.id &&
this->smart_charging_handler->clear_all_profiles_with_filter(
call.msg.id, call.msg.connectorId, call.msg.stackLevel, call.msg.chargingProfilePurpose, true)) {
response.status = ClearChargingProfileStatus::Accepted;
} else if (!call.msg.id and
this->smart_charging_handler->clear_all_profiles_with_filter(
std::nullopt, call.msg.connectorId, call.msg.stackLevel, call.msg.chargingProfilePurpose, false)) {
response.status = ClearChargingProfileStatus::Accepted;
bool connectorIdInValidRange = true;
if (call.msg.connectorId.has_value()) {
const int connector_id = call.msg.connectorId.value();
if (connector_id > this->configuration->getNumberOfConnectors() or connector_id < 0) {
connectorIdInValidRange = false;
}
}

if (connectorIdInValidRange) {
// clear all charging profiles
if (!call.msg.id && !call.msg.connectorId && !call.msg.chargingProfilePurpose && !call.msg.stackLevel) {
this->smart_charging_handler->clear_all_profiles();
response.status = ClearChargingProfileStatus::Accepted;
} else if (call.msg.id &&
this->smart_charging_handler->clear_all_profiles_with_filter(
call.msg.id, call.msg.connectorId, call.msg.stackLevel, call.msg.chargingProfilePurpose, true)) {
response.status = ClearChargingProfileStatus::Accepted;
} else if (!call.msg.id and this->smart_charging_handler->clear_all_profiles_with_filter(
std::nullopt, call.msg.connectorId, call.msg.stackLevel,
call.msg.chargingProfilePurpose, false)) {
response.status = ClearChargingProfileStatus::Accepted;
}
}

ocpp::CallResult<ClearChargingProfileResponse> call_result(response, call.uniqueId);
Expand Down

0 comments on commit c72225a

Please sign in to comment.