Skip to content

Commit

Permalink
'Fix' some lint issues and clang format issues.
Browse files Browse the repository at this point in the history
Signed-off-by: Maaike <[email protected]>
  • Loading branch information
maaikez committed Mar 19, 2024
1 parent 8c6089f commit 84d3a3b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 83 deletions.
1 change: 0 additions & 1 deletion include/ocpp/common/websocket/websocket_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class WebsocketBase {
websocketpp::connection_hdl handle;
std::mutex reconnect_mutex;
std::mutex connection_mutex;
bool shutting_down;

/// \brief Indicates if the required callbacks are registered
/// \returns true if the websocket is properly initialized
Expand Down
1 change: 0 additions & 1 deletion include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ class ChargePoint : ocpp::ChargingStationBase {
UploadLogStatusEnum upload_log_status;
int32_t upload_log_status_id;
BootReasonEnum bootreason;
uint32_t network_configuration_priority;
bool skip_invalid_csms_certificate_notifications;

/// \brief Component responsible for maintaining and persisting the operational status of CS, EVSEs, and connectors.
Expand Down
16 changes: 6 additions & 10 deletions include/ocpp/v201/connectivity_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ class ConnectivityManager {
///
void set_websocket_connection_options(const WebsocketConnectionOptions& connection_options);

///
/// \brief Get the active network configuration slot in use.
/// \return The active slot the network is connected to or the pending slot.
///
int32_t get_active_network_configuration_slot() const;

private: // Functions
// Disable copy constructor.
ConnectivityManager(const ConnectivityManager&) = delete;
Expand All @@ -212,10 +218,6 @@ class ConnectivityManager {
/// \brief Get next network slot for next priority.
int32_t get_next_network_configuration_priority_slot(const int32_t configuration_slot);

/// @brief Removes all network connection profiles below the actual security profile and stores the new list in the
/// device model
void remove_network_connection_profiles_below_actual_security_profile();

///
/// \brief Called when the websocket is connected.
/// \param configuration_slot Configuration slot the websocket is connected to.
Expand Down Expand Up @@ -244,12 +246,6 @@ class ConnectivityManager {
const std::optional<NetworkConnectionProfile> network_connection_profile,
const WebsocketCloseReason reason);

///
/// \brief Get the active network configuration slot in use.
/// \return The active slot the network is connected to or the pending slot.
///
int32_t get_active_network_configuration_slot() const;

///
/// \brief Get the priority of the given configuration slot.
/// \param configuration_slot The configuration slot to get the priority from.
Expand Down
9 changes: 1 addition & 8 deletions lib/ocpp/common/websocket/websocket_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
namespace ocpp {

WebsocketBase::WebsocketBase() :
m_is_connected(false),
connected_callback(nullptr),
closed_callback(nullptr),
message_callback(nullptr),
shutting_down(false) {
m_is_connected(false), connected_callback(nullptr), closed_callback(nullptr), message_callback(nullptr) {

set_connection_options_base(connection_options);

Expand Down Expand Up @@ -72,9 +68,6 @@ void WebsocketBase::disconnect(WebsocketCloseReason code) {
EVLOG_error << "Cannot disconnect a websocket that was not initialized";
return;
}
if (code == WebsocketCloseReason::Normal) {
this->shutting_down = true;
}
if (this->ping_timer) {
this->ping_timer->stop();
}
Expand Down
17 changes: 5 additions & 12 deletions lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ ChargePoint::ChargePoint(const std::map<int32_t, int32_t>& evse_connector_struct
const Callbacks& callbacks) :
ocpp::ChargingStationBase(evse_security),
registration_status(RegistrationStatusEnum::Rejected),
network_configuration_priority(0),
skip_invalid_csms_certificate_notifications(false),
reset_scheduled(false),
reset_scheduled_evseids{},
Expand Down Expand Up @@ -763,16 +762,6 @@ std::optional<NetworkConnectionProfile> ChargePoint::get_network_connection_prof
return std::nullopt;
}

void ChargePoint::next_network_configuration_priority() {
const auto network_connection_priorities = ocpp::get_vector_from_csv(
this->device_model->get_value<std::string>(ControllerComponentVariables::NetworkConfigurationPriority));
if (network_connection_priorities.size() > 1) {
EVLOG_info << "Switching to next network configuration priority";
}
this->network_configuration_priority =
(this->network_configuration_priority + 1) % (network_connection_priorities.size());
}

void ChargePoint::remove_network_connection_profiles_below_actual_security_profile() {
// Remove all the profiles that are a lower security level than security_level
const auto security_level = this->device_model->get_value<int>(ControllerComponentVariables::SecurityProfile);
Expand Down Expand Up @@ -1292,10 +1281,14 @@ void ChargePoint::handle_variable_changed(const SetVariableData& set_variable_da

if (component_variable_change_requires_websocket_option_update_without_reconnect(component_variable)) {
EVLOG_debug << "Reconfigure websocket due to relevant change of ControllerComponentVariable";
uint32_t active_slot = 0;
if (connectivity_manager != nullptr) {
active_slot = static_cast<uint32_t>(connectivity_manager->get_active_network_configuration_slot());
}
const auto configuration_slot =
ocpp::get_vector_from_csv(
this->device_model->get_value<std::string>(ControllerComponentVariables::NetworkConfigurationPriority))
.at(this->network_configuration_priority);
.at(active_slot);
const auto connection_options = this->get_ws_connection_options(std::stoi(configuration_slot));
if (connectivity_manager != nullptr) {
this->connectivity_manager->set_websocket_connection_options(connection_options);
Expand Down
57 changes: 6 additions & 51 deletions lib/ocpp/v201/connectivity_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ void ConnectivityManager::set_websocket_connection_options(const WebsocketConnec
}
}

int32_t ConnectivityManager::get_active_network_configuration_slot() const {
std::unique_lock<std::recursive_mutex> lock(this->config_slot_mutex);
return (active_network_slot != 0 ? active_network_slot : pending_network_slot);
}

void ConnectivityManager::run() {
{
std::unique_lock<std::mutex> lock(reconnect_mutex);
Expand Down Expand Up @@ -320,7 +325,7 @@ bool ConnectivityManager::init_websocket(std::optional<int32_t> config_slot) {
}
case std::future_status::ready: {
ConfigNetworkResult result = config_status.get();
if (result.success) {
if (result.success && result.network_profile_slot == config_slot_int) {
EVLOG_debug << "Config slot " << config_slot_int << " is configured, try to connect";
connection_options.iface_or_ip = result.interface_address;
this->pending_network_slot = config_slot_int;
Expand Down Expand Up @@ -461,51 +466,6 @@ int32_t ConnectivityManager::get_next_network_configuration_priority_slot(const
return std::stoi(new_prio_string);
}

void ConnectivityManager::remove_network_connection_profiles_below_actual_security_profile() {
// Remove all the profiles that are a lower security level than security_level
const auto security_level = this->device_model.get_value<int>(ControllerComponentVariables::SecurityProfile);

auto network_connection_profiles =
json::parse(this->device_model.get_value<std::string>(ControllerComponentVariables::NetworkConnectionProfiles));

auto is_lower_security_level = [security_level](const SetNetworkProfileRequest& item) {
return item.connectionData.securityProfile < security_level;
};

network_connection_profiles.erase(
std::remove_if(network_connection_profiles.begin(), network_connection_profiles.end(), is_lower_security_level),
network_connection_profiles.end());

this->device_model.set_value(ControllerComponentVariables::NetworkConnectionProfiles.component,
ControllerComponentVariables::NetworkConnectionProfiles.variable.value(),
AttributeEnum::Actual, network_connection_profiles.dump());

// Update the NetworkConfigurationPriority so only remaining profiles are in there
const auto network_priority = ocpp::get_vector_from_csv(
this->device_model.get_value<std::string>(ControllerComponentVariables::NetworkConfigurationPriority));

auto in_network_profiles = [&network_connection_profiles](const std::string& item) {
auto is_same_slot = [&item](const SetNetworkProfileRequest& profile) {
return std::to_string(profile.configurationSlot) == item;
};
return std::any_of(network_connection_profiles.begin(), network_connection_profiles.end(), is_same_slot);
};

std::string new_network_priority;
for (const auto& item : network_priority) {
if (in_network_profiles(item)) {
if (!new_network_priority.empty()) {
new_network_priority += ',';
}
new_network_priority += item;
}
}

this->device_model.set_value(ControllerComponentVariables::NetworkConfigurationPriority.component,
ControllerComponentVariables::NetworkConfigurationPriority.variable.value(),
AttributeEnum::Actual, new_network_priority);
}

void ConnectivityManager::on_websocket_connected_callback(
const int configuration_slot, const std::optional<NetworkConnectionProfile> network_connection_profile) {
NetworkConnectionProfile profile;
Expand Down Expand Up @@ -589,11 +549,6 @@ void ConnectivityManager::on_websocket_failed_callback(
reconnect(configuration_slot, false);
}

int32_t ConnectivityManager::get_active_network_configuration_slot() const {
std::unique_lock<std::recursive_mutex> lock(this->config_slot_mutex);
return (active_network_slot != 0 ? active_network_slot : pending_network_slot);
}

std::optional<int32_t> ConnectivityManager::get_configuration_slot_priority(const int32_t configuration_slot) {
// Convert to string as a vector of strings is used.
const std::string configuration_slot_string = std::to_string(configuration_slot);
Expand Down

0 comments on commit 84d3a3b

Please sign in to comment.