From 69e604dd458d1d0836f5c81a589210ef31985436 Mon Sep 17 00:00:00 2001 From: Coury Richards <146002925+couryrr-afs@users.noreply.github.com> Date: Tue, 8 Oct 2024 18:50:10 +0000 Subject: [PATCH] updated: moved duplicated code to method Signed-off-by: Coury Richards <146002925+couryrr-afs@users.noreply.github.com> --- include/ocpp/v201/smart_charging.hpp | 3 ++ lib/ocpp/v201/smart_charging.cpp | 53 +++++++++++++++------------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/include/ocpp/v201/smart_charging.hpp b/include/ocpp/v201/smart_charging.hpp index 4c75fccc4a..226026d1c1 100644 --- a/include/ocpp/v201/smart_charging.hpp +++ b/include/ocpp/v201/smart_charging.hpp @@ -274,6 +274,9 @@ class SmartChargingHandler : public SmartChargingHandlerInterface { void conform_validity_periods(ChargingProfile& profile) const; CurrentPhaseType get_current_phase_type(const std::optional evse_opt) const; TransactionEventRequest create_transaction_event_request(std::unique_ptr& tx) const; + bool process_evses_with_active_transactions(const bool limit_change_significance_exceeded, + std::vector& transaction_event_requests, + std::optional evse_id) const; }; } // namespace ocpp::v201 diff --git a/lib/ocpp/v201/smart_charging.cpp b/lib/ocpp/v201/smart_charging.cpp index 5dbb74a0b8..87e7a2e6de 100644 --- a/lib/ocpp/v201/smart_charging.cpp +++ b/lib/ocpp/v201/smart_charging.cpp @@ -812,38 +812,16 @@ std::optional evse_id) const { - bool has_transaction = false; - std::pair> pair; std::vector transaction_event_requests = {}; const auto& limit_change_cv = ControllerComponentVariables::LimitChangeSignificance; const float limit_change_significance = this->device_model->get_value(limit_change_cv); - if (evse_id.has_value()) { - auto evse = &this->evse_manager.get_evse(evse_id.value()); - if (evse->has_active_transaction()) { - has_transaction = true; - // K13.FR.03 - if (percentage_delta > limit_change_significance) { - auto& tx = evse->get_transaction(); - transaction_event_requests.push_back(this->create_transaction_event_request(tx)); - } - } - } else { - for (auto& evse : this->evse_manager) { - if (evse.has_active_transaction()) { - has_transaction = true; - - // K13.FR.03 - if (percentage_delta > limit_change_significance) { + const bool limit_change_significance_exceeded = percentage_delta > limit_change_significance; - auto& tx = evse.get_transaction(); - transaction_event_requests.push_back(this->create_transaction_event_request(tx)); - } - } - } - } + bool has_transaction = this->process_evses_with_active_transactions(limit_change_significance_exceeded, + transaction_event_requests, evse_id); std::optional>> request; @@ -880,4 +858,29 @@ SmartChargingHandler::create_transaction_event_request(std::unique_ptr& transaction_event_requests, + std::optional evse_id) const { + bool has_transaction = false; + if (evse_id.has_value()) { + auto evse = &this->evse_manager.get_evse(evse_id.value()); + if (evse->has_active_transaction()) { + has_transaction = true; + // K13.FR.03 + if (limit_change_significance_exceeded) { + auto& tx = evse->get_transaction(); + transaction_event_requests.push_back(this->create_transaction_event_request(tx)); + } + } + } else { + for (auto& evse : this->evse_manager) { + has_transaction = (process_evses_with_active_transactions(limit_change_significance_exceeded, + transaction_event_requests, evse.get_id()) || + has_transaction); + } + } + + return has_transaction; +} + } // namespace ocpp::v201