Skip to content

Commit

Permalink
Merge branch 'main' into feature/327-use-case-h01-reservation
Browse files Browse the repository at this point in the history
  • Loading branch information
maaikez committed Oct 31, 2024
2 parents 706f54c + abdf54c commit dd6e6bb
Show file tree
Hide file tree
Showing 33 changed files with 2,172 additions and 2,275 deletions.
16 changes: 5 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ option(BUILD_TESTING "Build unit tests, used if standalone project" OFF)
option(CMAKE_RUN_CLANG_TIDY "Run clang-tidy" OFF)
option(LIBOCPP16_BUILD_EXAMPLES "Build charge_point binary" OFF)
option(OCPP_INSTALL "Install the library (shared data might be installed anyway)" ${EVC_MAIN_PROJECT})
option(LIBOCPP_ENABLE_DEPRECATED_WEBSOCKETPP "Usage of deprecated websocket++ instead of libwebsockets" OFF)
option(LIBOCPP_ENABLE_DEPRECATED_WEBSOCKETPP "Websocket++ has been removed from the project" OFF)

option(LIBOCPP_ENABLE_V16 "Enable OCPP 1.6 in the ocpp library" ON)
option(LIBOCPP_ENABLE_V201 "Enable OCPP 2.0.1 in the ocpp library" ON)
Expand All @@ -25,6 +25,10 @@ if((NOT LIBOCPP_ENABLE_V16) AND (NOT LIBOCPP_ENABLE_V201))
message(FATAL_ERROR "At least one of LIBOCPP_ENABLE_V16 and LIBOCPP_ENABLE_V201 needs to be ON")
endif()

if(LIBOCPP_ENABLE_DEPRECATED_WEBSOCKETPP)
message(FATAL_ERROR "Websocket++ has been removed")
endif()

if((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME} OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING)
set(LIBOCPP_BUILD_TESTING ON)
endif()
Expand All @@ -39,12 +43,6 @@ if(NOT DISABLE_EDM)

# In EDM mode, we can't install exports (because the dependencies usually do not install their exports)
set(OCPP_INSTALL OFF)

if(LIBOCPP_ENABLE_DEPRECATED_WEBSOCKETPP)
# FIXME (aw): websocketpp doesn't play well with EDM/CPM
add_library(websocketpp::websocketpp INTERFACE IMPORTED)
set_target_properties(websocketpp::websocketpp PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${websocketpp_SOURCE_DIR}")
endif()
else()
find_package(date REQUIRED)
find_package(nlohmann_json REQUIRED)
Expand All @@ -54,10 +52,6 @@ else()
find_package(everest-timer REQUIRED)
find_package(everest-log REQUIRED)
find_package(everest-evse_security REQUIRED)

if(LIBOCPP_ENABLE_DEPRECATED_WEBSOCKETPP)
find_package(websocketpp REQUIRED)
endif()
endif()

# config and auxillary files
Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -553,11 +553,7 @@ In order to use the TPM keys, it is mandatory to use the default libwebsocket im
## Support for websocket++
The old websocket++ implementation has been deprecated. For enabling websocket++ support use the following cmake option:
```bash
cmake .. -DLIBOCPP_ENABLE_DEPRECATED_WEBSOCKETPP=ON
```
The old websocket++ implementation has been removed. Enabling websocket++ will prevent compilation from starting.
### Support for iface
Expand Down
18 changes: 18 additions & 0 deletions config/v201/component_config/standardized/InternalCtrlr.json
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,24 @@
"description": "If enabled the transactions that were active before shutdown will be resumed, if possible",
"default": false,
"type": "boolean"
},
"NetworkConfigTimeout": {
"variable_name": "NetworkConfigTimeout",
"characteristics": {
"supportsMonitoring": true,
"dataType": "integer",
"minLimit": 1
},
"attributes": [
{
"type": "Actual",
"mutability": "ReadWrite"
}
],
"description": "Timeout value in seconds to wait for a response from a network configuration request",
"minimum": 1,
"default": "60",
"type": "integer"
}
},
"required": [
Expand Down
4 changes: 0 additions & 4 deletions dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ date:
git: https://github.com/HowardHinnant/date.git
git_tag: v3.0.1
options: ["BUILD_TZ_LIB ON", "HAS_REMOTE_API 0", "USE_AUTOLOAD 0", "USE_SYSTEM_TZ_DB ON"]
websocketpp:
git: https://github.com/zaphoyd/websocketpp.git
git_tag: 0.8.2
cmake_condition: "LIBOCPP_ENABLE_DEPRECATED_WEBSOCKETPP"
libevse-security:
git: https://github.com/EVerest/libevse-security.git
git_tag: v0.8.0
Expand Down
103 changes: 103 additions & 0 deletions doc/networkconnectivity/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Network connection profile interface

libocpp automatically tries to connect using the given network connection profiles.
However, if you want more control, you can use the callbacks provided for the network connection.

libocpp will automatically connect to the network profile with the highest priority.
If this fails, it will network profile with the second highest priority, and so on.

## Set up interface (optional)

A callback can be implemented to set up the interface. For example, if the interface is a modem, it must first be
be activated before it is possible to connect to this interface. To do this, you can implement the callback
`std::future<ConfigNetworkResult>(configure_network_connection_profile_callback(configuration_slot, NetworkConnectionProfile))`

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

If the network was setup successfully, you can set the values in the promise with
```cpp
promise.set_value(configNetworkResult);
```
This way, libocpp knows that it can connect to the given interface and will try to do so.
A timeout can be configured using `NetworkConfigTimeout' to wait longer or shorter than the default 60 seconds.

### Bind to a specific interface

In some cases there are multiple network interfaces available and you may want to connect to a specific one.
In `ConfigNetworkResult` you can specify which interface you want the websocket to bind to.
Sometimes an interface has more than one IP address (in the case of a local/auto link for example).
In this case you want the websocket to bind to a specific IP address. The `interface_address` in ConfigNetworkResult supports both.
It will bind to the given network interface (a string containing the name of the interface) or the given ip address (a string containing the ip address in human readable format).

## Connect to higher network connection profile priority (optional)

Normally, when libocpp is connected with a network connection profile, it will not disconnect.
However, there may be a situation where libocpp is connected to a profile with priority 2 or lower, and you find out at system level that an interface (with a higher priority) has changed and is now up.
A call is added so that you can suggest that libocpp switch to this profile: `bool on_try_switch_network_connection_profile(const int32_t configuration_slot)`.
libocpp will inform the caller by the return value if it tries to switch to this profile.

## Disconnected / connected callbacks

libocpp provides two callbacks for when the websocket is connected and disconnected. It will provide the network slot
in these callbacks, so you can keep the network connection in use (e.g. not disable the modem), or disable the network connection (example again: disable the modem).

## Sequence diagram

'core' can be read as any application that implements libocpp

For step 9, ping is one way to check if a CSMS is up, but you of course can implement a way to check this yourself.

```mermaid
sequenceDiagram
participant csms
participant libocpp
participant core
autonumber
note over csms,libocpp: libocpp wants to connect to network connection profile
libocpp ->>+ core: std::future<ConfigNetworkResult>(configure_network_connection_profile_callback(<br>configuration_slot, NetworkConnectionProfile))
note over core: ... possible delay ...
core ->> core: Setup network, e.g. setup modem
core ->>- libocpp: promise.set_value(status,<br>ip_address, etc)
alt within timeout
%% core ->> libocpp: on_network_update (ip address)
libocpp ->> csms: connect websocket (ip address)
csms ->> libocpp: ACK
libocpp ->> core: websocket_connected_callback(configuration_slot, NetworkConnectionProfile)
core ->> core: disable unneeded interfaces, <br>e.g. disable modem
else timeout reached, next network connection profile selected
libocpp -->> core: std::future<ConfigNetworkResult>(configure_network_connection_profile_callback(<br>configuration_slot, NetworkConnectionProfile)) (see 1)
end
note over libocpp: CSMS is connected via connection profile prio 2 (for example modem) but prio 1 (for example eth0) comes up
loop until prio 1 csms is found
core ->> csms: ping
end
core ->> libocpp: on_try_switch_networkconnectionprofile(configuration_slot)
libocpp -->> core: std::future<ConfigNetworkResult>(configure_network_connection_profile_callback(<br>configuration_slot, NetworkConnectionProfile)) (see 1)
note over csms,libocpp: Network is disconnected (for example networkcable removed)
core ->> libocpp: disconnect csms (on_network_disconnected(configuration_slot, OCPPInterfaceEnum)
libocpp ->> core: websocket_disconnected_callback(configuration_slot, NetworkConnectionProfile)
libocpp -->> core: std::future<ConfigNetworkResult>(configure_network_connection_profile_callback(<br>configuration_slot, NetworkConnectionProfile)) (see 1)
note over csms,libocpp: Network is disconnected (websocket timeout)
libocpp ->> libocpp: disconnect csms
libocpp ->> core: websocket_disconnected_callback(configuration_slot, NetworkConnectionProfile)
libocpp -->> core: std::future<ConfigNetworkResult>(configure_network_connection_profile_callback(<br>configuration_slot, NetworkConnectionProfile)) (see 1)
```
8 changes: 4 additions & 4 deletions include/ocpp/common/websocket/websocket_libwebsockets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ struct ConnectionData;
struct WebsocketMessage;

/// \brief Experimental libwebsockets TLS connection
class WebsocketTlsTPM final : public WebsocketBase {
class WebsocketLibwebsockets final : public WebsocketBase {
public:
/// \brief Creates a new Websocket object with the providede \p connection_options
explicit WebsocketTlsTPM(const WebsocketConnectionOptions& connection_options,
std::shared_ptr<EvseSecurity> evse_security);
explicit WebsocketLibwebsockets(const WebsocketConnectionOptions& connection_options,
std::shared_ptr<EvseSecurity> evse_security);

~WebsocketTlsTPM();
~WebsocketLibwebsockets();

void set_connection_options(const WebsocketConnectionOptions& connection_options) override;

Expand Down
77 changes: 0 additions & 77 deletions include/ocpp/common/websocket/websocket_plain.hpp

This file was deleted.

87 changes: 0 additions & 87 deletions include/ocpp/common/websocket/websocket_tls.hpp

This file was deleted.

Loading

0 comments on commit dd6e6bb

Please sign in to comment.