From a9dbe63dde5286e1acf95ca8b52915171300eb07 Mon Sep 17 00:00:00 2001 From: Marc Emmers Date: Fri, 22 Nov 2024 15:02:28 +0100 Subject: [PATCH] Fix review comments, allow interface to be nullopt Signed-off-by: Marc Emmers --- include/ocpp/v201/connectivity_manager.hpp | 9 +++--- lib/ocpp/v201/charge_point.cpp | 2 +- lib/ocpp/v201/connectivity_manager.cpp | 35 ++++++++-------------- 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/include/ocpp/v201/connectivity_manager.hpp b/include/ocpp/v201/connectivity_manager.hpp index 80c055a10..93b7f4924 100644 --- a/include/ocpp/v201/connectivity_manager.hpp +++ b/include/ocpp/v201/connectivity_manager.hpp @@ -135,7 +135,7 @@ class ConnectivityManager { /// \brief Called when the charging station certificate is changed /// - void on_reconfiguration_of_security_parameters(); + void on_charging_station_certificate_changed(); /// \brief Confirms the connection is successful so the security profile requirements can be handled void confirm_successful_connection(); @@ -154,9 +154,10 @@ class ConnectivityManager { /// \param slot The configuration slot to get the interface for /// \param profile The network connection profile to get the interface for /// - /// \return A string containing the network interface to use, nullptr if the request failed or the callback is not - /// configured - std::optional get_network_configuration_interface(int slot, const NetworkConnectionProfile& profile); + /// \return The network configuration containing the network interface to use, nullptr if the request failed or the + /// callback is not configured + std::optional + handle_configure_network_connection_profile_callback(int slot, const NetworkConnectionProfile& profile); /// \brief Function invoked when the web socket connected with the \p security_profile /// diff --git a/lib/ocpp/v201/charge_point.cpp b/lib/ocpp/v201/charge_point.cpp index 3af2b7dbf..a1852bc65 100644 --- a/lib/ocpp/v201/charge_point.cpp +++ b/lib/ocpp/v201/charge_point.cpp @@ -2323,7 +2323,7 @@ void ChargePoint::handle_certificate_signed_req(Call c if (response.status == CertificateSignedStatusEnum::Accepted and cert_signing_use == ocpp::CertificateSigningUseEnum::ChargingStationCertificate and this->device_model->get_value(ControllerComponentVariables::SecurityProfile) == 3) { - this->connectivity_manager->on_reconfiguration_of_security_parameters(); + this->connectivity_manager->on_charging_station_certificate_changed(); const auto& security_event = ocpp::security_events::RECONFIGURATIONOFSECURITYPARAMETERS; std::string tech_info = "Changed charging station certificate"; diff --git a/lib/ocpp/v201/connectivity_manager.cpp b/lib/ocpp/v201/connectivity_manager.cpp index 82e39a227..d06c2de14 100644 --- a/lib/ocpp/v201/connectivity_manager.cpp +++ b/lib/ocpp/v201/connectivity_manager.cpp @@ -185,11 +185,12 @@ void ConnectivityManager::try_connect_websocket() { EVLOG_warning << "Connection profile configured for " << configuration_slot_to_set << " failed: not valid URL"; can_use_connection_profile = false; } else if (this->configure_network_connection_profile_callback.has_value()) { - if (std::optional interface_address = - get_network_configuration_interface(configuration_slot_to_set, network_connection_profile.value()); - interface_address.has_value()) { - connection_options->iface = interface_address; + std::optional config = handle_configure_network_connection_profile_callback( + configuration_slot_to_set, network_connection_profile.value()); + if (config.has_value() && config->success) { + connection_options->iface = config->interface_address; } else { + EVLOG_warning << "Could not use config slot " << configuration_slot_to_set; can_use_connection_profile = false; } } @@ -244,34 +245,24 @@ void ConnectivityManager::try_connect_websocket() { this->websocket->connect(); } -std::optional -ConnectivityManager::get_network_configuration_interface(int slot, const NetworkConnectionProfile& profile) { +std::optional +ConnectivityManager::handle_configure_network_connection_profile_callback(int slot, + const NetworkConnectionProfile& profile) { if (!this->configure_network_connection_profile_callback.has_value()) { return std::nullopt; } - EVLOG_debug << "Request to configure network connection profile " << slot; - std::future config_status = this->configure_network_connection_profile_callback.value()(slot, profile); const int32_t config_timeout = this->device_model.get_optional_value(ControllerComponentVariables::NetworkConfigTimeout) .value_or(default_network_config_timeout_seconds); - switch (config_status.wait_for(std::chrono::seconds(config_timeout))) { - case std::future_status::deferred: - case std::future_status::timeout: - EVLOG_warning << "Timeout configuring config slot: " << slot; - return std::nullopt; - - case std::future_status::ready: - if (ConfigNetworkResult result = config_status.get(); result.success) { - EVLOG_debug << "Config slot " << slot << " is configured"; - return result.interface_address; - } - EVLOG_warning << "Could not configure config slot " << slot; - break; + if (config_status.wait_for(std::chrono::seconds(config_timeout)) == std::future_status::ready) { + return config_status.get(); } + + EVLOG_warning << "Timeout configuring config slot: " << slot; return std::nullopt; } @@ -314,7 +305,7 @@ void ConnectivityManager::on_network_disconnected(OCPPInterfaceEnum ocpp_interfa } } -void ConnectivityManager::on_reconfiguration_of_security_parameters() { +void ConnectivityManager::on_charging_station_certificate_changed() { if (this->websocket != nullptr) { // After the websocket gets closed a reconnect will be triggered this->websocket->disconnect(WebsocketCloseReason::ServiceRestart);