From b1f947e027b5b054d35a4676bd036286c747abaa Mon Sep 17 00:00:00 2001 From: WilcodenBesten Date: Mon, 4 Nov 2024 13:30:30 +0100 Subject: [PATCH] Allow empty network connection priorities. Replace throw with a clear warning message. (#855) * Allow empty network connection priorities. Replace throw with a clear warning message Signed-off-by: Wilco den Besten * Improve warning message Signed-off-by: Wilco den Besten --------- Signed-off-by: Wilco den Besten --- include/ocpp/v201/connectivity_manager.hpp | 3 ++- lib/ocpp/v201/connectivity_manager.cpp | 15 ++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/ocpp/v201/connectivity_manager.hpp b/include/ocpp/v201/connectivity_manager.hpp index e72360209..03c45bc6f 100644 --- a/include/ocpp/v201/connectivity_manager.hpp +++ b/include/ocpp/v201/connectivity_manager.hpp @@ -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 diff --git a/lib/ocpp/v201/connectivity_manager.cpp b/lib/ocpp/v201/connectivity_manager.cpp index 8dd4a1b5c..336c7c6a0 100644 --- a/lib/ocpp/v201/connectivity_manager.cpp +++ b/lib/ocpp/v201/connectivity_manager.cpp @@ -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 << "No network connection profiles configured, aborting websocket connection."; + 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 @@ -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 @@ -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