Skip to content

Commit

Permalink
charge_point: Reject ChargingStationExternalConstraints profiles in S…
Browse files Browse the repository at this point in the history
…etChargingProfileRequest

Implements K01.FR.22

Signed-off-by: Christopher Davis <150722105+christopher-davis-afs@users.noreply.github.com>
  • Loading branch information
christopher-davis-afs committed Jul 29, 2024
1 parent 87fd4f6 commit f95e552
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3161,6 +3161,19 @@ void ChargePoint::handle_set_charging_profile_req(Call<SetChargingProfileRequest
SetChargingProfileResponse response;
response.status = ChargingProfileStatusEnum::Rejected;

if (msg.chargingProfile.chargingProfilePurpose == ChargingProfilePurposeEnum::ChargingStationExternalConstraints) {
response.statusInfo = StatusInfo();
response.statusInfo->reasonCode = "InvalidValue";
response.statusInfo->additionalInfo = "ChargingStationExternalConstraintsInSetChargingProfileRequest";
EVLOG_debug << "Rejecting SetChargingProfileRequest:\n reasonCode: " << response.statusInfo->reasonCode.get()
<< "\nadditionalInfo: " << response.statusInfo->additionalInfo->get();

ocpp::CallResult<SetChargingProfileResponse> call_result(response, call.uniqueId);
this->send<SetChargingProfileResponse>(call_result);

return;
}

auto res = this->smart_charging_handler->validate_profile(msg.chargingProfile, msg.evseId);
if (res == ProfileValidationResultEnum::Valid) {
EVLOG_debug << "Accepting SetChargingProfileRequest";
Expand Down Expand Up @@ -3854,10 +3867,9 @@ void ChargePoint::load_charging_profiles() {
try {
auto evses = this->database_handler->get_all_charging_profiles_by_evse();
EVLOG_info << "Found " << evses.size() << " evse in the database";
for (auto& profiles : evses) {
for (const auto& [evse_id, profiles] : evses) {
try {
auto evse_id = profiles.first;
for (auto profile : profiles.second) {
for (auto profile : profiles) {
if (this->smart_charging_handler->validate_profile(profile, evse_id) ==
ProfileValidationResultEnum::Valid) {
this->smart_charging_handler->add_profile(profile, evse_id);
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/ocpp/v201/test_charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,4 +660,24 @@ TEST_P(ChargePointFixture_InvalidProfiles, K01FR07_SetChargingProfileRequest_Doe
charge_point->handle_message(set_charging_profile_req);
}

TEST_F(ChargePointFixture, K01FR22_SetChargingProfileRequest_RejectsChargingStationExternalConstraints) {
auto periods = create_charging_schedule_periods({0, 1, 2});

auto profile = create_charging_profile(
DEFAULT_PROFILE_ID, ChargingProfilePurposeEnum::ChargingStationExternalConstraints,
create_charge_schedule(ChargingRateUnitEnum::A, periods, ocpp::DateTime("2024-01-17T17:00:00")), DEFAULT_TX_ID);

SetChargingProfileRequest req;
req.evseId = DEFAULT_EVSE_ID;
req.chargingProfile = profile;

auto set_charging_profile_req =
request_to_enhanced_message<SetChargingProfileRequest, MessageType::SetChargingProfile>(req);

EXPECT_CALL(*smart_charging_handler, validate_profile).Times(0);
EXPECT_CALL(*smart_charging_handler, add_profile).Times(0);

charge_point->handle_message(set_charging_profile_req);
}

} // namespace ocpp::v201

0 comments on commit f95e552

Please sign in to comment.