Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(EvseManager): use std::optional instead of pair #881

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions modules/EvseManager/ErrorHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ void ErrorHandling::clear_overcurrent_error() {
// Find out if the current error set is fatal to charging or not
void ErrorHandling::process_error() {
const auto fatal = errors_prevent_charging();
if (std::get<bool>(fatal)) {
if (fatal) {
// signal to charger a new error has been set that prevents charging
raise_inoperative_error(std::get<std::string>(fatal));
raise_inoperative_error(*fatal);
} else {
// signal an error that does not prevent charging
clear_inoperative_error();
Expand Down Expand Up @@ -110,56 +110,56 @@ void ErrorHandling::process_error() {
}

// Check all errors from p_evse and all requirements to see if they block charging
std::pair<bool, std::string> ErrorHandling::errors_prevent_charging() {
std::optional<std::string> ErrorHandling::errors_prevent_charging() {

auto is_fatal = [](auto errors, auto ignore_list) -> std::pair<bool, std::string> {
auto is_fatal = [](auto errors, auto ignore_list) -> std::optional<std::string> {
for (const auto e : errors) {
if (std::none_of(ignore_list.begin(), ignore_list.end(), [e](const auto& ign) { return e->type == ign; })) {
return {true, e->type};
return e->type;
}
}
return {false, ""};
return std::nullopt;
};

auto fatal = is_fatal(p_evse->error_state_monitor->get_active_errors(), ignore_errors.evse);
if (std::get<bool>(fatal)) {
if (fatal) {
return fatal;
}

fatal = is_fatal(r_bsp->error_state_monitor->get_active_errors(), ignore_errors.bsp);
if (std::get<bool>(fatal)) {
if (fatal) {
return fatal;
}

if (r_connector_lock.size() > 0) {
fatal = is_fatal(r_connector_lock[0]->error_state_monitor->get_active_errors(), ignore_errors.connector_lock);
if (std::get<bool>(fatal)) {
if (fatal) {
return fatal;
}
}

if (r_ac_rcd.size() > 0) {
fatal = is_fatal(r_ac_rcd[0]->error_state_monitor->get_active_errors(), ignore_errors.ac_rcd);
if (std::get<bool>(fatal)) {
if (fatal) {
return fatal;
}
}

if (r_imd.size() > 0) {
fatal = is_fatal(r_imd[0]->error_state_monitor->get_active_errors(), ignore_errors.imd);
if (std::get<bool>(fatal)) {
if (fatal) {
return fatal;
}
}

if (r_powersupply.size() > 0) {
fatal = is_fatal(r_powersupply[0]->error_state_monitor->get_active_errors(), ignore_errors.powersupply);
if (std::get<bool>(fatal)) {
if (fatal) {
return fatal;
}
}

return {false, ""};
return std::nullopt;
}

void ErrorHandling::raise_inoperative_error(const std::string& caused_by) {
Expand Down
3 changes: 2 additions & 1 deletion modules/EvseManager/ErrorHandling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <chrono>
#include <mutex>
#include <optional>
#include <queue>

#include <generated/interfaces/ISO15118_charger/Interface.hpp>
Expand Down Expand Up @@ -68,7 +69,7 @@ class ErrorHandling {
void process_error();
void raise_inoperative_error(const std::string& caused_by);
void clear_inoperative_error();
std::pair<bool, std::string> errors_prevent_charging();
std::optional<std::string> errors_prevent_charging();

const std::unique_ptr<evse_board_supportIntf>& r_bsp;
const std::vector<std::unique_ptr<ISO15118_chargerIntf>>& r_hlc;
Expand Down
Loading