Skip to content

Commit

Permalink
Fix review comments, allow interface to be nullopt
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Emmers <[email protected]>
  • Loading branch information
marcemmers committed Nov 22, 2024
1 parent 1c53a1d commit a9dbe63
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 27 deletions.
9 changes: 5 additions & 4 deletions include/ocpp/v201/connectivity_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<std::string> 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<ConfigNetworkResult>
handle_configure_network_connection_profile_callback(int slot, const NetworkConnectionProfile& profile);

/// \brief Function invoked when the web socket connected with the \p security_profile
///
Expand Down
2 changes: 1 addition & 1 deletion lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2323,7 +2323,7 @@ void ChargePoint::handle_certificate_signed_req(Call<CertificateSignedRequest> c
if (response.status == CertificateSignedStatusEnum::Accepted and
cert_signing_use == ocpp::CertificateSigningUseEnum::ChargingStationCertificate and
this->device_model->get_value<int>(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";
Expand Down
35 changes: 13 additions & 22 deletions lib/ocpp/v201/connectivity_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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<ConfigNetworkResult> 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;
}
}
Expand Down Expand Up @@ -244,34 +245,24 @@ void ConnectivityManager::try_connect_websocket() {
this->websocket->connect();
}

std::optional<std::string>
ConnectivityManager::get_network_configuration_interface(int slot, const NetworkConnectionProfile& profile) {
std::optional<ConfigNetworkResult>
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<ConfigNetworkResult> config_status =
this->configure_network_connection_profile_callback.value()(slot, profile);
const int32_t config_timeout =
this->device_model.get_optional_value<int>(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;
}

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a9dbe63

Please sign in to comment.