Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/everest/ocpp/doc/networkconnectivity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ be activated before it is possible to connect to this interface. To do this, you

In the implementation of this callback, you have to create a promise and return the future to the promise:
```cpp
std::promise<ocpp::v2::ConfigNetworkResult> promise();
std::future<ocpp::v2::ConfigNetworkResult> future = promise.get_future();
std::promise<ocpp::ConfigNetworkResult> promise();
std::future<ocpp::ConfigNetworkResult> future = promise.get_future();
return future;
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <optional>
namespace ocpp {
namespace v2 {

class DeviceModel;
}

/// \brief The result of a configuration of a network profile.
struct ConfigNetworkResult {
Expand All @@ -22,15 +22,24 @@
};

using WebsocketConnectionCallback =
std::function<void(int configuration_slot, const NetworkConnectionProfile& network_connection_profile,
std::function<void(int configuration_slot, const ocpp::v2::NetworkConnectionProfile& network_connection_profile,
const OcppProtocolVersion version)>;
using WebsocketConnectionFailedCallback = std::function<void(ConnectionFailedReason reason)>;
using ConfigureNetworkConnectionProfileCallback = std::function<std::future<ConfigNetworkResult>(
const std::int32_t configuration_slot, const NetworkConnectionProfile& network_connection_profile)>;
const std::int32_t configuration_slot, const ocpp::v2::NetworkConnectionProfile& network_connection_profile)>;

class ConnectivityManagerInterface {
public:
virtual ~ConnectivityManagerInterface() = default;

/// \brief Set the \p callback that is called when a message is received from the websocket
///
virtual void set_message_callback(const std::function<void(const std::string& message)>& callback) = 0;

/// \brief Set the logger \p logging
///
virtual void set_logging(std::shared_ptr<MessageLogging> logging) = 0;

/// \brief Set the websocket \p authorization_key
///
virtual void set_websocket_authorization_key(const std::string& authorization_key) = 0;
Expand Down Expand Up @@ -63,7 +72,7 @@
/// \brief Gets the cached NetworkConnectionProfile based on the given \p configuration_slot.
/// This returns the value from the cached network connection profiles.
/// \return Returns a profile if the slot is found
virtual std::optional<NetworkConnectionProfile>
virtual std::optional<ocpp::v2::NetworkConnectionProfile>
get_network_connection_profile(const std::int32_t configuration_slot) const = 0;

/// \brief Get the priority of the given configuration slot.
Expand Down Expand Up @@ -107,7 +116,7 @@
///
/// \param ocpp_interface The interface that is disconnected.
///
virtual void on_network_disconnected(OCPPInterfaceEnum ocpp_interface) = 0;
virtual void on_network_disconnected(ocpp::v2::OCPPInterfaceEnum ocpp_interface) = 0;

/// \brief Called when the charging station certificate is changed
///
Expand All @@ -120,7 +129,7 @@
class ConnectivityManager : public ConnectivityManagerInterface {
private:
/// \brief Reference to the device model
DeviceModel& device_model;
ocpp::v2::DeviceModel& device_model;
/// \brief Pointer to the evse security class
std::shared_ptr<EvseSecurity> evse_security;
/// \brief Pointer to the logger
Expand All @@ -144,32 +153,33 @@
std::int32_t active_network_configuration_priority;
int last_known_security_level;
/// @brief Local cached network connection profiles
std::vector<SetNetworkProfileRequest> cached_network_connection_profiles;
std::vector<ocpp::v2::SetNetworkProfileRequest> cached_network_connection_profiles;

Check warning on line 156 in lib/everest/ocpp/include/ocpp/common/connectivity_manager.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/everest/ocpp/include/ocpp/common/connectivity_manager.hpp#L156

class member 'ConnectivityManager::cached_network_connection_profiles' is never used.
/// @brief local cached network connection priorities
std::vector<std::int32_t> network_connection_slots;
OcppProtocolVersion connected_ocpp_version;

public:
ConnectivityManager(DeviceModel& device_model, std::shared_ptr<EvseSecurity> evse_security,
std::shared_ptr<MessageLogging> logging,
const std::function<void(const std::string& message)>& message_callback);
ConnectivityManager(ocpp::v2::DeviceModel& device_model, std::shared_ptr<EvseSecurity> evse_security);

void set_message_callback(const std::function<void(const std::string& message)>& callback) override;
void set_logging(std::shared_ptr<MessageLogging> logging) override;
void set_websocket_authorization_key(const std::string& authorization_key) override;
void set_websocket_connection_options(const WebsocketConnectionOptions& connection_options) override;
void set_websocket_connection_options_without_reconnect() override;
void set_websocket_connected_callback(WebsocketConnectionCallback callback) override;
void set_websocket_disconnected_callback(WebsocketConnectionCallback callback) override;
void set_websocket_connection_failed_callback(WebsocketConnectionFailedCallback callback) override;
void set_configure_network_connection_profile_callback(ConfigureNetworkConnectionProfileCallback callback) override;
std::optional<NetworkConnectionProfile>
std::optional<ocpp::v2::NetworkConnectionProfile>
get_network_connection_profile(const std::int32_t configuration_slot) const override;
std::optional<std::int32_t> get_priority_from_configuration_slot(const int configuration_slot) const override;
std::optional<std::int32_t>
get_priority_from_configuration_slot(const std::int32_t configuration_slot) const override;
const std::vector<int>& get_network_connection_slots() const override;
bool is_websocket_connected() override;
void connect(std::optional<std::int32_t> network_profile_slot = std::nullopt) override;
void disconnect() override;
bool send_to_websocket(const std::string& message) override;
void on_network_disconnected(OCPPInterfaceEnum ocpp_interface) override;
void on_network_disconnected(ocpp::v2::OCPPInterfaceEnum ocpp_interface) override;
void on_charging_station_certificate_changed() override;
void confirm_successful_connection() override;

Expand All @@ -190,7 +200,7 @@
/// \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);
handle_configure_network_connection_profile_callback(int slot, const ocpp::v2::NetworkConnectionProfile& profile);

/// \brief Function invoked when the web socket connected with the \p security_profile
///
Expand Down Expand Up @@ -237,5 +247,4 @@
void remove_network_connection_profiles_below_actual_security_profile();
};

} // namespace v2
} // namespace ocpp
52 changes: 45 additions & 7 deletions lib/everest/ocpp/include/ocpp/v2/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,28 @@ class ChargePointInterface {
/// The handlers
/// @{

///
/// \brief Shall be called when a websocket connection has been established in case the connectivity_handler is
/// provided exernally.
/// \param configuration_slot The network profile slot used for the connection.
/// \param network_connection_profile The network connection profile used for the connection.
virtual void on_websocket_connected(const int configuration_slot,
const NetworkConnectionProfile& network_connection_profile,
const OcppProtocolVersion ocpp_version) = 0;

///
/// \brief Shall be called when a websocket connection has been disconnected in case the connectivity_handler is
/// provided externally.
/// \param configuration_slot The network profile slot used for the connection.
/// \param network_connection_profile The network connection profile used for the connection.
virtual void on_websocket_disconnected(const int configuration_slot,
const NetworkConnectionProfile& network_connection_profile) = 0;

/// \brief Shall be called when a websocket connection attempt has failed in case the connectivity_handler is
/// provided externally.
/// \param reason The reason why the connection failed.
virtual void on_websocket_connection_failed(ConnectionFailedReason reason) = 0;

///
/// \brief Can be called when a network is disconnected, for example when an ethernet cable is removed.
///
Expand Down Expand Up @@ -345,7 +367,7 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
private:
std::shared_ptr<DeviceModel> device_model;
std::unique_ptr<EvseManager> evse_manager;
std::unique_ptr<ConnectivityManager> connectivity_manager;
std::shared_ptr<ConnectivityManagerInterface> connectivity_manager;

std::unique_ptr<MessageDispatcherInterface<MessageType>> message_dispatcher;

Expand Down Expand Up @@ -412,12 +434,7 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
// internal helper functions
void initialize(const std::map<std::int32_t, std::int32_t>& evse_connector_structure,
const std::string& message_log_path);
void websocket_connected_callback(const int configuration_slot,
const NetworkConnectionProfile& network_connection_profile,
const OcppProtocolVersion ocpp_version);
void websocket_disconnected_callback(const int configuration_slot,
const NetworkConnectionProfile& network_connection_profile);
void websocket_connection_failed(ConnectionFailedReason reason);
OcspUpdater make_ocsp_updater();
void update_dm_availability_state(const std::int32_t evse_id, const std::int32_t connector_id,
const ConnectorStatusEnum status);

Expand Down Expand Up @@ -463,6 +480,21 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
/// @name Constructors for 2.0.1
/// @{

/// \brief Construct a new ChargePoint object
/// \param evse_connector_structure Map that defines the structure of EVSE and connectors of the chargepoint. The
/// key represents the id of the EVSE and the value represents the number of connectors for this EVSE. The ids of
/// the EVSEs have to increment starting with 1.
/// \param device_model device model instance
/// \param database_handler database handler instance
/// \param evse_security Pointer to evse_security that manages security related operations
/// \param connectivity_manager connectivity manager instance
/// \param message_log_path Path to where logfiles are written to
/// \param callbacks Callbacks that will be registered for ChargePoint
ChargePoint(const std::map<int32_t, int32_t>& evse_connector_structure, std::shared_ptr<DeviceModel> device_model,
std::shared_ptr<DatabaseHandler> database_handler, const std::shared_ptr<EvseSecurity> evse_security,
const std::shared_ptr<ConnectivityManagerInterface> connectivity_manager,
const std::string& message_log_path, const Callbacks& callbacks);

/// \brief Construct a new ChargePoint object
/// \param evse_connector_structure Map that defines the structure of EVSE and connectors of the chargepoint. The
/// key represents the id of the EVSE and the value represents the number of connectors for this EVSE. The ids of
Expand Down Expand Up @@ -527,6 +559,12 @@ class ChargePoint : public ChargePointInterface, private ocpp::ChargingStationBa
void connect_websocket(std::optional<std::int32_t> network_profile_slot = std::nullopt) override;
void disconnect_websocket() override;

void on_websocket_connected(const int configuration_slot,
const NetworkConnectionProfile& network_connection_profile,
const OcppProtocolVersion ocpp_version) override;
void on_websocket_disconnected(const int configuration_slot,
const NetworkConnectionProfile& network_connection_profile) override;
void on_websocket_connection_failed(ConnectionFailedReason reason) override;
void on_network_disconnected(OCPPInterfaceEnum ocpp_interface) override;

void on_firmware_update_status_notification(std::int32_t request_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <cstdint>
#include <memory>

#include <ocpp/v2/connectivity_manager.hpp>
#include <ocpp/common/connectivity_manager.hpp>
#include <ocpp/v2/device_model.hpp>

#include <ocpp/v2/messages/BootNotification.hpp>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

namespace ocpp {
class EvseSecurity;
class ConnectivityManagerInterface;

namespace v2 {
class DeviceModel;
class ConnectivityManagerInterface;
class EvseManagerInterface;
class DatabaseHandlerInterface;
class ComponentStateManagerInterface;
Expand Down
2 changes: 1 addition & 1 deletion lib/everest/ocpp/include/ocpp/v2/message_dispatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#pragma once

#include <ocpp/common/connectivity_manager.hpp>

Check warning on line 6 in lib/everest/ocpp/include/ocpp/v2/message_dispatcher.hpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/everest/ocpp/include/ocpp/v2/message_dispatcher.hpp#L6

Include file: <ocpp/common/connectivity_manager.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <ocpp/common/message_dispatcher.hpp>
#include <ocpp/v2/connectivity_manager.hpp>
#include <ocpp/v2/device_model.hpp>

namespace ocpp {
Expand Down
2 changes: 1 addition & 1 deletion lib/everest/ocpp/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ target_sources(ocpp
PRIVATE
ocpp/common/call_types.cpp
ocpp/common/charging_station_base.cpp
ocpp/common/connectivity_manager.cpp
ocpp/common/ocpp_logging.cpp
ocpp/common/schemas.cpp
ocpp/common/types.cpp
Expand Down Expand Up @@ -89,7 +90,6 @@ if(LIBOCPP_ENABLE_V2)
ocpp/v2/types.cpp
ocpp/v2/utils.cpp
ocpp/v2/component_state_manager.cpp
ocpp/v2/connectivity_manager.cpp
ocpp/v2/message_dispatcher.cpp
ocpp/v2/functional_blocks/authorization.cpp
ocpp/v2/functional_blocks/availability.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2020 - 2024 Pionix GmbH and Contributors to EVerest

#include <ocpp/v2/connectivity_manager.hpp>
#include <ocpp/common/connectivity_manager.hpp>

Check warning on line 4 in lib/everest/ocpp/lib/ocpp/common/connectivity_manager.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

lib/everest/ocpp/lib/ocpp/common/connectivity_manager.cpp#L4

Include file: <ocpp/common/connectivity_manager.hpp> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <everest/logging.hpp>
#include <ocpp/v2/ctrlr_component_variables.hpp>
Expand All @@ -17,23 +17,36 @@
} // namespace

namespace ocpp {
namespace v2 {

ConnectivityManager::ConnectivityManager(DeviceModel& device_model, std::shared_ptr<EvseSecurity> evse_security,
std::shared_ptr<MessageLogging> logging,
const std::function<void(const std::string& message)>& message_callback) :
using NetworkConnectionProfile = ocpp::v2::NetworkConnectionProfile;
using AttributeEnum = ocpp::v2::AttributeEnum;
using DeviceModel = ocpp::v2::DeviceModel;
using OCPPInterfaceEnum = ocpp::v2::OCPPInterfaceEnum;
using SetNetworkProfileRequest = ocpp::v2::SetNetworkProfileRequest;
namespace ControllerComponentVariables = ocpp::v2::ControllerComponentVariables;

ConnectivityManager::ConnectivityManager(DeviceModel& device_model, std::shared_ptr<EvseSecurity> evse_security) :
device_model{device_model},
evse_security{evse_security},
logging{logging},
message_callback([](const std::string& message) {
EVLOG_warning << "No message callback set in ConnectivityManager. Dropping message: " << message;
}),
websocket{nullptr},
message_callback{message_callback},
wants_to_be_connected{false},
active_network_configuration_priority{0},
last_known_security_level{0},
connected_ocpp_version{OcppProtocolVersion::Unknown} {
cache_network_connection_profiles();
}

void ConnectivityManager::set_message_callback(const std::function<void(const std::string& message)>& callback) {
this->message_callback = callback;
}

void ConnectivityManager::set_logging(std::shared_ptr<MessageLogging> logging) {
this->logging = logging;
}

void ConnectivityManager::set_websocket_authorization_key(const std::string& authorization_key) {
if (this->websocket != nullptr) {
this->websocket->set_authorization_key(authorization_key);
Expand Down Expand Up @@ -338,7 +351,7 @@
this->device_model.get_value<std::string>(ControllerComponentVariables::SecurityCtrlrIdentity),
network_connection_profile.securityProfile);

const auto ocpp_versions = utils::get_ocpp_protocol_versions(
const auto ocpp_versions = ocpp::v2::utils::get_ocpp_protocol_versions(
this->device_model.get_value<std::string>(ControllerComponentVariables::SupportedOcppVersions));

WebsocketConnectionOptions connection_options{
Expand Down Expand Up @@ -525,5 +538,4 @@
AttributeEnum::Actual, new_network_priority, VARIABLE_ATTRIBUTE_VALUE_SOURCE_INTERNAL);
}

} // namespace v2
} // namespace ocpp
5 changes: 5 additions & 0 deletions lib/everest/ocpp/lib/ocpp/common/websocket/websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ namespace ocpp {
Websocket::Websocket(const WebsocketConnectionOptions& connection_options, std::shared_ptr<EvseSecurity> evse_security,
std::shared_ptr<MessageLogging> logging) :
logging(logging) {

if (logging == nullptr) {
throw std::runtime_error("Websocket requires a valid MessageLogging instance");
}

this->websocket = std::make_unique<WebsocketLibwebsockets>(connection_options, evse_security);
}

Expand Down
Loading
Loading