Skip to content

Commit 60226e9

Browse files
author
Coury Richards
committed
updated: moved duplicated code to method
Signed-off-by: Coury Richards <146002925+couryrr-afs@users.noreply.github.com>
1 parent c102e2e commit 60226e9

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed

include/ocpp/v201/smart_charging.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ class SmartChargingHandler : public SmartChargingHandlerInterface {
274274
void conform_validity_periods(ChargingProfile& profile) const;
275275
CurrentPhaseType get_current_phase_type(const std::optional<EvseInterface*> evse_opt) const;
276276
TransactionEventRequest create_transaction_event_request(std::unique_ptr<EnhancedTransaction>& tx) const;
277+
bool process_evses_with_active_transactions(const bool limit_change_significance_exceeded,
278+
std::vector<TransactionEventRequest>& transaction_event_requests,
279+
std::optional<int32_t> evse_id) const;
277280
};
278281

279282
} // namespace ocpp::v201

lib/ocpp/v201/smart_charging.cpp

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -812,38 +812,16 @@ std::optional<std::pair<ClearedChargingLimitRequest, std::vector<TransactionEven
812812
SmartChargingHandler::handle_external_limit_cleared(double percentage_delta, ChargingLimitSourceEnum source,
813813
std::optional<int32_t> evse_id) const {
814814

815-
bool has_transaction = false;
816-
817815
std::pair<ClearedChargingLimitRequest, std::vector<TransactionEventRequest>> pair;
818816
std::vector<TransactionEventRequest> transaction_event_requests = {};
819817

820818
const auto& limit_change_cv = ControllerComponentVariables::LimitChangeSignificance;
821819
const float limit_change_significance = this->device_model->get_value<double>(limit_change_cv);
822820

823-
if (evse_id.has_value()) {
824-
auto evse = &this->evse_manager.get_evse(evse_id.value());
825-
if (evse->has_active_transaction()) {
826-
has_transaction = true;
827-
// K13.FR.03
828-
if (percentage_delta > limit_change_significance) {
829-
auto& tx = evse->get_transaction();
830-
transaction_event_requests.push_back(this->create_transaction_event_request(tx));
831-
}
832-
}
833-
} else {
834-
for (auto& evse : this->evse_manager) {
835-
if (evse.has_active_transaction()) {
836-
has_transaction = true;
837-
838-
// K13.FR.03
839-
if (percentage_delta > limit_change_significance) {
821+
const bool limit_change_significance_exceeded = percentage_delta > limit_change_significance;
840822

841-
auto& tx = evse.get_transaction();
842-
transaction_event_requests.push_back(this->create_transaction_event_request(tx));
843-
}
844-
}
845-
}
846-
}
823+
bool has_transaction = this->process_evses_with_active_transactions(limit_change_significance_exceeded,
824+
transaction_event_requests, evse_id);
847825

848826
std::optional<std::pair<ClearedChargingLimitRequest, std::vector<TransactionEventRequest>>> request;
849827

@@ -880,4 +858,29 @@ SmartChargingHandler::create_transaction_event_request(std::unique_ptr<EnhancedT
880858
return tmp;
881859
}
882860

861+
bool SmartChargingHandler::process_evses_with_active_transactions(
862+
const bool limit_change_significance_exceeded, std::vector<TransactionEventRequest>& transaction_event_requests,
863+
std::optional<int32_t> evse_id) const {
864+
bool has_transaction = false;
865+
if (evse_id.has_value()) {
866+
auto evse = &this->evse_manager.get_evse(evse_id.value());
867+
if (evse->has_active_transaction()) {
868+
has_transaction = true;
869+
// K13.FR.03
870+
if (limit_change_significance_exceeded) {
871+
auto& tx = evse->get_transaction();
872+
transaction_event_requests.push_back(this->create_transaction_event_request(tx));
873+
}
874+
}
875+
} else {
876+
for (auto& evse : this->evse_manager) {
877+
has_transaction = (process_evses_with_active_transactions(limit_change_significance_exceeded,
878+
transaction_event_requests, evse.get_id()) ||
879+
has_transaction);
880+
}
881+
}
882+
883+
return has_transaction;
884+
}
885+
883886
} // namespace ocpp::v201

0 commit comments

Comments
 (0)