Skip to content

Commit

Permalink
Allow empty network connection priorities. Replace throw with a clear…
Browse files Browse the repository at this point in the history
… warning message

Signed-off-by: Wilco den Besten <[email protected]>
  • Loading branch information
WilcodenBesten committed Nov 1, 2024
1 parent abdf54c commit 2df673d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion include/ocpp/v201/connectivity_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ class ConnectivityManager {
void next_network_configuration_priority();

/// @brief Cache all the network connection profiles. Must be called once during initialization
void cache_network_connection_profiles();
/// \return True if the network connection profiles could be cached, else False.
bool cache_network_connection_profiles();
};

} // namespace v201
Expand Down
15 changes: 8 additions & 7 deletions lib/ocpp/v201/connectivity_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,12 @@ void ConnectivityManager::init_websocket() {
}

// cache the network profiles on initialization
cache_network_connection_profiles();
if (!cache_network_connection_profiles()) {
EVLOG_warning << "Network connection profiles could not be cached, aborting websocket init";
return;
}

const int config_slot_int = this->network_connection_priorities.at(this->network_configuration_priority);
const int config_slot_int = this->get_active_network_configuration_slot();

const auto network_connection_profile = this->get_network_connection_profile(config_slot_int);
// Not const as the iface member can be set by the configure network connection profile callback
Expand Down Expand Up @@ -424,11 +427,11 @@ void ConnectivityManager::next_network_configuration_priority() {
(this->network_configuration_priority + 1) % (this->network_connection_priorities.size());
}

void ConnectivityManager::cache_network_connection_profiles() {
bool ConnectivityManager::cache_network_connection_profiles() {

if (!this->network_connection_profiles.empty()) {
EVLOG_debug << " Network connection profiles already cached";
return;
return true;
}

// get all the network connection profiles from the device model and cache them
Expand All @@ -442,9 +445,7 @@ void ConnectivityManager::cache_network_connection_profiles() {
this->network_connection_priorities.push_back(num);
}

if (this->network_connection_priorities.empty()) {
EVLOG_AND_THROW(std::runtime_error("NetworkConfigurationPriority must not be empty"));
}
return !this->network_connection_priorities.empty();
}
} // namespace v201
} // namespace ocpp

0 comments on commit 2df673d

Please sign in to comment.