Skip to content

Commit

Permalink
Fix some review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Emmers <[email protected]>
  • Loading branch information
marcemmers committed Jan 24, 2025
1 parent 10c1b5e commit cc52536
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
13 changes: 9 additions & 4 deletions lib/ocpp/v201/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ IntermediateProfile generate_profile_from_periods(std::vector<period_entry_t>& p
return combined;
}

namespace {

using period_iterator = IntermediateProfile::const_iterator;
using period_pair_vector = std::vector<std::pair<period_iterator, period_iterator>>;
using IntermediateProfileRef = std::reference_wrapper<const IntermediateProfile>;
Expand All @@ -381,11 +383,12 @@ inline std::vector<IntermediateProfileRef> convert_to_ref_vector(const std::vect
return references;
}

static IntermediateProfile
combine_list_of_profiles(const std::vector<IntermediateProfileRef>& profiles,
std::function<IntermediatePeriod(const period_pair_vector&)> combinator) {
IntermediateProfile combine_list_of_profiles(const std::vector<IntermediateProfileRef>& profiles,
std::function<IntermediatePeriod(const period_pair_vector&)> combinator) {
if (profiles.empty()) {
throw std::out_of_range("There should always be profiles here");
// We should never get here as there are always profiles, otherwise there is a mistake in the calling function
// Return an empty profile to be safe
return {{0, NO_LIMIT_SPECIFIED, NO_LIMIT_SPECIFIED, std::nullopt, std::nullopt}};
}

IntermediateProfile combined{};
Expand Down Expand Up @@ -443,6 +446,8 @@ combine_list_of_profiles(const std::vector<IntermediateProfileRef>& profiles,
return combined;
}

} // namespace

IntermediateProfile merge_tx_profile_with_tx_default_profile(const IntermediateProfile& tx_profile,
const IntermediateProfile& tx_default_profile) {

Expand Down
22 changes: 11 additions & 11 deletions lib/ocpp/v201/smart_charging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ CurrentPhaseType SmartChargingHandler::get_current_phase_type(const std::optiona

SmartChargingHandler::SmartChargingHandler(EvseManagerInterface& evse_manager,
std::shared_ptr<DeviceModel>& device_model,
ocpp::v201::DatabaseHandlerInterface& database_handler) :
DatabaseHandlerInterface& database_handler) :
evse_manager(evse_manager), device_model(device_model), database_handler(database_handler) {
}

Expand Down Expand Up @@ -625,7 +625,7 @@ std::vector<IntermediateProfile> generate_evse_intermediates(std::vector<Chargin
ChargingProfilePurposeEnum::ChargingStationExternalConstraints);

std::vector<IntermediateProfile> output;
output.push_back(ocpp::v201::generate_profile_from_periods(external_constraints_periods, start_time, end_time));
output.push_back(generate_profile_from_periods(external_constraints_periods, start_time, end_time));

// If there is a session active or we want to simulate, add the combined tx and tx_default to the output
if (session_start.has_value() || simulate_transaction_active) {
Expand All @@ -634,12 +634,12 @@ std::vector<IntermediateProfile> generate_evse_intermediates(std::vector<Chargin
auto tx_periods = calculate_all_profiles(start_time, end_time, session_start, evse_profiles,
ChargingProfilePurposeEnum::TxProfile);

auto tx_default = ocpp::v201::generate_profile_from_periods(tx_default_periods, start_time, end_time);
auto tx = ocpp::v201::generate_profile_from_periods(tx_periods, start_time, end_time);
auto tx_default = generate_profile_from_periods(tx_default_periods, start_time, end_time);
auto tx = generate_profile_from_periods(tx_periods, start_time, end_time);

// Merges the TxProfile with the TxDefaultProfile, for every period preferring a tx period over a tx_default
// period
output.push_back(ocpp::v201::merge_tx_profile_with_tx_default_profile(tx, tx_default));
output.push_back(merge_tx_profile_with_tx_default_profile(tx, tx_default));
}

return output;
Expand Down Expand Up @@ -676,13 +676,13 @@ SmartChargingHandler::calculate_composite_schedule(const ocpp::DateTime& start_t
end_time, session_start, simulate_transaction_active);

// Determine the lowest limits per evse
evse_schedules.push_back(ocpp::v201::merge_profiles_by_lowest_limit(intermediates));
evse_schedules.push_back(merge_profiles_by_lowest_limit(intermediates));
}

// Add all the limits of all the evse's together since that will be the max the whole charging station can
// consume at any point in time
combined_profiles.push_back(
ocpp::v201::merge_profiles_by_summing_limits(evse_schedules, config.current_limit, config.power_limit));
merge_profiles_by_summing_limits(evse_schedules, config.current_limit, config.power_limit));

} else {
combined_profiles = generate_evse_intermediates(get_valid_profiles_for_evse(evse_id, config.purposes_to_ignore),
Expand All @@ -693,19 +693,19 @@ SmartChargingHandler::calculate_composite_schedule(const ocpp::DateTime& start_t
// ChargingStationMaxProfile is always station wide
auto charge_point_max_periods = calculate_all_profiles(start_time, end_time, session_start, station_wide_profiles,
ChargingProfilePurposeEnum::ChargingStationMaxProfile);
auto charge_point_max = ocpp::v201::generate_profile_from_periods(charge_point_max_periods, start_time, end_time);
auto charge_point_max = generate_profile_from_periods(charge_point_max_periods, start_time, end_time);

// Add the ChargingStationMaxProfile limits to the other profiles
combined_profiles.push_back(std::move(charge_point_max));

// Calculate the final limit of all the combined profiles
auto retval = ocpp::v201::merge_profiles_by_lowest_limit(combined_profiles);
auto retval = merge_profiles_by_lowest_limit(combined_profiles);

CompositeSchedule composite{};
composite.evseId = evse_id;
composite.scheduleStart = ocpp::v201::floor_seconds(start_time);
composite.scheduleStart = floor_seconds(start_time);
composite.duration =
ocpp::v201::elapsed_seconds(ocpp::v201::floor_seconds(end_time), ocpp::v201::floor_seconds(start_time));
elapsed_seconds(floor_seconds(end_time), floor_seconds(start_time));
composite.chargingRateUnit = charging_rate_unit;

// Convert the intermediate result into a proper schedule. Will fill in the periods with no limits with the default
Expand Down

0 comments on commit cc52536

Please sign in to comment.