Skip to content

Commit ab4b5d0

Browse files
committed
[wip] Add a future return for the configure network connection callback
Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com>
1 parent 82b904e commit ab4b5d0

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

include/ocpp/v201/charge_point.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,10 @@ struct Callbacks {
174174
std::optional<std::function<SetNetworkProfileStatusEnum(
175175
const int32_t configuration_slot, const NetworkConnectionProfile& network_connection_profile)>>
176176
validate_network_profile_callback;
177-
std::optional<std::function<bool(const NetworkConnectionProfile& network_connection_profile,
178-
std::promise<int>& network_promise)>>
177+
178+
/// @brief register a \p cllback that is called when the network connection profile is to be configured.
179+
std::optional<
180+
std::function<std::future<ConfigNetworkResult>(const NetworkConnectionProfile& network_connection_profile)>>
179181
configure_network_connection_profile_callback;
180182
};
181183

include/ocpp/v201/ocpp_types.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,10 @@ void from_json(const json& j, NetworkConnectionProfile& k);
861861
/// \returns an output stream with the NetworkConnectionProfile written to
862862
std::ostream& operator<<(std::ostream& os, const NetworkConnectionProfile& k);
863863

864+
struct ConfigNetworkResult {
865+
std::optional<CiString<32>> interface_adress;
866+
bool success;
867+
};
864868
struct SetMonitoringData {
865869
float value;
866870
MonitorEnum type;

lib/ocpp/v201/charge_point.cpp

+25-15
Original file line numberDiff line numberDiff line change
@@ -648,9 +648,6 @@ bool ChargePoint::send(CallError call_error) {
648648
}
649649

650650
void ChargePoint::init_websocket() {
651-
652-
std::promise<int> network_promise;
653-
654651
if (this->device_model->get_value<std::string>(ControllerComponentVariables::ChargePointId).find(':') !=
655652
std::string::npos) {
656653
EVLOG_AND_THROW(std::runtime_error("ChargePointId must not contain \':\'"));
@@ -663,10 +660,28 @@ void ChargePoint::init_websocket() {
663660
const auto connection_options = this->get_ws_connection_options(std::stoi(configuration_slot));
664661
const auto network_connection_profile = this->get_network_connection_profile(std::stoi(configuration_slot));
665662

666-
if (!network_connection_profile.has_value() or
667-
(this->callbacks.configure_network_connection_profile_callback.has_value() and
668-
!this->callbacks.configure_network_connection_profile_callback.value()(network_connection_profile.value(),
669-
network_promise))) {
663+
if (this->callbacks.configure_network_connection_profile_callback.has_value() and network_connection_profile) {
664+
auto config_status = this->callbacks.configure_network_connection_profile_callback.value()(
665+
network_connection_profile.value()); /* */
666+
667+
if (config_status.wait_for(5s) == std::future_status::timeout) {
668+
EVLOG_info << " timeout!!!";
669+
EVLOG_warning
670+
<< "NetworkConnectionProfile could not be retrieved or configuration of network with the given "
671+
"profile failed";
672+
this->websocket_timer.timeout(
673+
[this]() {
674+
this->next_network_configuration_priority();
675+
this->start_websocket();
676+
},
677+
WEBSOCKET_INIT_DELAY);
678+
return;
679+
} else if (config_status.wait_for(5s) == std::future_status::timeout) {
680+
; // do nothing?
681+
} else {
682+
EVLOG_info << "config status -------> : " << config_status.get().success;
683+
}
684+
} else {
670685
EVLOG_warning << "NetworkConnectionProfile could not be retrieved or configuration of network with the given "
671686
"profile failed";
672687
this->websocket_timer.timeout(
@@ -677,9 +692,6 @@ void ChargePoint::init_websocket() {
677692
WEBSOCKET_INIT_DELAY);
678693
return;
679694
}
680-
681-
EVLOG_info << "connection profile value: -> " << network_promise.get_future().get();
682-
683695
const auto& security_profile_cv = ControllerComponentVariables::SecurityProfile;
684696
if (security_profile_cv.variable.has_value()) {
685697
this->device_model->set_read_only_value(security_profile_cv.component, security_profile_cv.variable.value(),
@@ -698,8 +710,7 @@ void ChargePoint::init_websocket() {
698710
}
699711

700712
// call the registered websocket connected callback if it exists
701-
if(this->callbacks.websocket_connected_callback.has_value())
702-
{
713+
if (this->callbacks.websocket_connected_callback.has_value()) {
703714
this->callbacks.websocket_connected_callback.value()(network_connection_profile);
704715
}
705716

@@ -735,9 +746,8 @@ void ChargePoint::init_websocket() {
735746
// Get the current time point using steady_clock
736747
this->time_disconnected = std::chrono::steady_clock::now();
737748
}
738-
//call the disconnected callback if it exists
739-
if(this->callbacks.websocket_disconnected_callback.has_value())
740-
{
749+
// call the disconnected callback if it exists
750+
if (this->callbacks.websocket_disconnected_callback.has_value()) {
741751
this->callbacks.websocket_disconnected_callback.value();
742752
}
743753
this->client_certificate_expiration_check_timer.stop();

0 commit comments

Comments
 (0)