Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

network connection profiles #410

Closed
wants to merge 36 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f5eae6b
[wip] add a websocked connected and disconnected callback
SNSubramanya Jan 19, 2024
b94f03c
[wip] experiment with promise and future
SNSubramanya Jan 19, 2024
5f03834
make websocket callbacks optional
SNSubramanya Jan 22, 2024
cc6d0a3
[wip] Add a future return for the configure network connection callback
SNSubramanya Jan 23, 2024
9169440
[wip] Add a variable to configure the timeout duration
SNSubramanya Jan 24, 2024
0658697
[wip] Add a check for the timeout value and deferred status
SNSubramanya Jan 24, 2024
aeb45d2
[wip] Added an on_try_switch function to switch to a specific network…
SNSubramanya Jan 26, 2024
5436951
[wip] Add definition for on_try_switch_network_profile
SNSubramanya Jan 29, 2024
2a71918
[wip] some more PR changes
SNSubramanya Feb 1, 2024
b6d22c8
websocket_(dis)connected_callback: Connected callback: NetworkConnect…
Feb 12, 2024
f365eb0
Add network profile slot to config network result.
Feb 14, 2024
00362ff
Change callback interface and add extra function for when network int…
Feb 15, 2024
b6e08cd
Changes on websocket interface to use a new defined enum.
maaikez Feb 19, 2024
9e81cb8
Fixed compiling for new interface
AssemblyJohn Feb 20, 2024
2eee3ed
Change configuration slot to be an int32_t instead of string. Add doc…
maaikez Feb 21, 2024
0dcf551
Implement a bit more of on_try_switch_network_connection_profile.
maaikez Feb 21, 2024
677c2d0
Add connectivity manager.
maaikez Feb 22, 2024
39269f4
Add some callbacks in connectivity manager
maaikez Mar 1, 2024
6cc22b3
Add main thread to connectivity manager.
maaikez Mar 2, 2024
8a5353f
Remove things from ChargePoint that are moved to the ConnectivityMana…
maaikez Mar 4, 2024
6230d9f
Change charge_point so it does not use websocket member anymore. Late…
maaikez Mar 5, 2024
5d5e7ef
On network disconnect: only disconnect if the network that should be …
maaikez Mar 5, 2024
1fa3d07
Fix bug where disconnected network slot was always disconnecting the …
maaikez Mar 7, 2024
28b242d
Add logging for testing and try to fix some bugs.
maaikez Mar 8, 2024
1dad026
Move reconnect timer to connectivity manager. formatting.
maaikez Mar 13, 2024
f47488e
Add websocket failed callback. Add functionality in connectivity mana…
maaikez Mar 14, 2024
42fb35a
Strip websocket classes. Add (a lot of!) logging for debugging purposes.
maaikez Mar 15, 2024
062367b
Add documentation. Fix some crashes when websocket is reconnecting.
maaikez Mar 18, 2024
fe28ee8
Cleanup. Introduce new mutex to prevent pending, active and requested…
maaikez Mar 19, 2024
65e4f34
Fix after rebase
maaikez Mar 19, 2024
e005b18
Removed include for websocket_plain and websocket_tls .hpp from webso…
maaikez Mar 19, 2024
83383e8
Formatting.
maaikez Mar 19, 2024
25c301a
'Fix' some lint issues and clang format issues.
maaikez Mar 19, 2024
10b5ff5
Add some removed code (oops). Move (duplicate) code from chargepoint …
maaikez Mar 25, 2024
9d2e723
Make libwebsockets also work with security profile 1 (so that the url…
maaikez Mar 27, 2024
c2f8e29
Add some documentation.
maaikez Mar 29, 2024
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
Prev Previous commit
Next Next commit
On network disconnect: only disconnect if the network that should be …
…disconnected is indeed connected. Init function: try next configuration priority if the current is not found. Remove some TODO's that are already implemented.

Signed-off-by: Maaike <maaike@iolar.nl>
maaikez committed Mar 27, 2024

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 5d5e7ef30589d71adcddad611aee767d0540a6b2
63 changes: 39 additions & 24 deletions lib/ocpp/v201/connectivity_manager.cpp
Original file line number Diff line number Diff line change
@@ -80,7 +80,6 @@ void ConnectivityManager::connect_websocket(std::optional<int32_t> config_slot)
// TODO check if websocket is connected???
if (!this->websocket->is_connected()) {
this->init_websocket(config_slot);
// TODO this should be removed?? It should connect when the future is filled and returned
this->websocket->connect();
}
}
@@ -97,7 +96,6 @@ void ConnectivityManager::disconnect_websocket(WebsocketCloseReason code) {
}

bool ConnectivityManager::on_try_switch_network_connection_profile(const int32_t configuration_slot) {
// TODO remove and check priority via index.
if (is_higher_priority_profile(configuration_slot)) {
// Priority is indeed higher
EVLOG_debug
@@ -137,8 +135,25 @@ void ConnectivityManager::on_network_disconnected(const std::optional<int32_t> c
return;
}

// TODO in this if: check if network slot is up as well!??
if (active_network_slot == configuration_slot || pending_network_slot == configuration_slot) {
int32_t disconnected_network_slot = 0;

if (configuration_slot.has_value()) {
disconnected_network_slot = configuration_slot.value();
} else {
// Find slot belonging to ocpp interface. That's only interesting if it is an active or pending network slot.
const int32_t current_network_slot =
this->active_network_slot != 0 ? this->active_network_slot : this->pending_network_slot;
if (current_network_slot != 0) {
std::optional<NetworkConnectionProfile> profile =
this->get_network_connection_profile(current_network_slot);
if (profile.has_value() && profile.value().ocppInterface == ocpp_interface) {
disconnected_network_slot = current_network_slot;
}
}
}

if (this->active_network_slot == disconnected_network_slot ||
this->pending_network_slot == disconnected_network_slot) {
// Websocket is indeed connecting with the given slot or already connected.
std::unique_lock<std::mutex> lock(this->config_slot_mutex);
this->disconnect_websocket(); // normal close
@@ -215,15 +230,12 @@ void ConnectivityManager::init_websocket(std::optional<int32_t> config_slot) {
config_slot_int = config_slot.value();
} else {
// Get first available config slot.
const std::vector<std::string> config_slot_vector = ocpp::get_vector_from_csv(this->device_model.get_value<std::string>(
ControllerComponentVariables::NetworkConfigurationPriority));
if (config_slot_vector.size() > 0)
{
const std::vector<std::string> config_slot_vector = ocpp::get_vector_from_csv(
this->device_model.get_value<std::string>(ControllerComponentVariables::NetworkConfigurationPriority));
if (config_slot_vector.size() > 0) {
configuration_slot = config_slot_vector.at(0);
config_slot_int = std::stoi(configuration_slot);
}
else
{
} else {
// No network connection profile. Retry connecting after some time, maybe it is set manually.
sleep(default_retry_network_connection_profile_seconds);
return;
@@ -233,7 +245,17 @@ void ConnectivityManager::init_websocket(std::optional<int32_t> config_slot) {
WebsocketConnectionOptions connection_options = this->get_ws_connection_options(config_slot_int);
const std::optional<NetworkConnectionProfile> network_connection_profile =
this->get_network_connection_profile(config_slot_int);
if (this->configure_network_connection_profile_callback.has_value() and network_connection_profile) {

if (!network_connection_profile.has_value()) {
// No network connection profile found, what to connect to then? So get next profile and try to connect with
// that one.
this->requested_network_slot = this->get_next_network_configuration_priority_slot(config_slot_int);
this->try_reconnect.store(true);
this->reconnect_condition_variable.notify_all();
return;
}

if (this->configure_network_connection_profile_callback.has_value()) {
this->requested_network_slot = config_slot_int;
std::future<ConfigNetworkResult> config_status = this->configure_network_connection_profile_callback.value()(
config_slot_int, network_connection_profile.value());
@@ -284,8 +306,6 @@ void ConnectivityManager::init_websocket(std::optional<int32_t> config_slot) {
}
} else {
// No callback configured, just connect to this profile.

// TODO what if there is no network connection profile at all???
}

this->websocket = std::make_unique<Websocket>(connection_options, this->evse_security, this->logging);
@@ -567,34 +587,29 @@ std::optional<int32_t> ConnectivityManager::get_configuration_slot_priority(cons
bool ConnectivityManager::is_higher_priority_profile(const int32_t new_configuration_slot) {

const int32_t current_slot = get_active_network_configuration_slot();
if (current_slot == 0)
{
if (current_slot == 0) {
// No slot in use, new is always higher priority.
return true;
}

if (current_slot == new_configuration_slot)
{
if (current_slot == new_configuration_slot) {
// Slot is the same, probably already connected
return false;
}

const std::optional<int32_t> new_priority = get_configuration_slot_priority(new_configuration_slot);
if (!new_priority.has_value())
{
if (!new_priority.has_value()) {
// Slot not found.
return false;
}

const std::optional<int32_t> current_priority = get_configuration_slot_priority(current_slot);
if (!current_priority.has_value())
{
if (!current_priority.has_value()) {
// Slot not found.
return false;
}

if (new_configuration_slot < current_slot)
{
if (new_configuration_slot < current_slot) {
// Priority is indeed higher (lower index means higher priority)
return true;
}