Skip to content

Commit

Permalink
updated: moved duplicated code to method
Browse files Browse the repository at this point in the history
Signed-off-by: Coury Richards <[email protected]>
  • Loading branch information
couryrr-afs committed Oct 8, 2024
1 parent 769cc0a commit 69e604d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
3 changes: 3 additions & 0 deletions include/ocpp/v201/smart_charging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ class SmartChargingHandler : public SmartChargingHandlerInterface {
void conform_validity_periods(ChargingProfile& profile) const;
CurrentPhaseType get_current_phase_type(const std::optional<EvseInterface*> evse_opt) const;
TransactionEventRequest create_transaction_event_request(std::unique_ptr<EnhancedTransaction>& tx) const;
bool process_evses_with_active_transactions(const bool limit_change_significance_exceeded,
std::vector<TransactionEventRequest>& transaction_event_requests,
std::optional<int32_t> evse_id) const;
};

} // namespace ocpp::v201
Expand Down
53 changes: 28 additions & 25 deletions lib/ocpp/v201/smart_charging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,38 +812,16 @@ std::optional<std::pair<ClearedChargingLimitRequest, std::vector<TransactionEven
SmartChargingHandler::handle_external_limit_cleared(double percentage_delta, ChargingLimitSourceEnum source,
std::optional<int32_t> evse_id) const {

bool has_transaction = false;

std::pair<ClearedChargingLimitRequest, std::vector<TransactionEventRequest>> pair;
std::vector<TransactionEventRequest> transaction_event_requests = {};

const auto& limit_change_cv = ControllerComponentVariables::LimitChangeSignificance;
const float limit_change_significance = this->device_model->get_value<double>(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<std::pair<ClearedChargingLimitRequest, std::vector<TransactionEventRequest>>> request;

Expand Down Expand Up @@ -880,4 +858,29 @@ SmartChargingHandler::create_transaction_event_request(std::unique_ptr<EnhancedT
return tmp;
}

bool SmartChargingHandler::process_evses_with_active_transactions(
const bool limit_change_significance_exceeded, std::vector<TransactionEventRequest>& transaction_event_requests,
std::optional<int32_t> 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

0 comments on commit 69e604d

Please sign in to comment.