Skip to content

Commit debd995

Browse files
committed
[wip] experiment with promise and future
Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com> [wip] fixed bug in print statement Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com>
1 parent 787dbb4 commit debd995

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

config/v201/config.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@
263263
"SupportedCriteria": {
264264
"variable_name": "SupportedCriteria",
265265
"attributes": {
266-
"Actual": "Enabled,Active,Available,Problem"
266+
"Actual": "Enabled,Active,Available"
267267
}
268268
},
269269
"UpdateCertificateSymlinks": {

include/ocpp/v201/charge_point.hpp

+10-6
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,7 @@ struct Callbacks {
125125
std::function<UpdateFirmwareResponse(const UpdateFirmwareRequest& request)> update_firmware_request_callback;
126126
// callback to be called when a variable has been changed by the CSMS
127127
std::optional<std::function<void(const SetVariableData& set_variable_data)>> variable_changed_callback;
128-
// callback is called when receiving a SetNetworkProfile.req from the CSMS
129-
std::optional<std::function<SetNetworkProfileStatusEnum(
130-
const int32_t configuration_slot, const NetworkConnectionProfile& network_connection_profile)>>
131-
validate_network_profile_callback;
132-
std::optional<std::function<bool(const NetworkConnectionProfile& network_connection_profile)>>
133-
configure_network_connection_profile_callback;
128+
134129
std::optional<std::function<void(const ocpp::DateTime& currentTime)>> time_sync_callback;
135130

136131
/// \brief callback to be called to congfigure ocpp message logging
@@ -167,11 +162,20 @@ struct Callbacks {
167162
/// messageId
168163
std::optional<std::function<DataTransferResponse(const DataTransferRequest& request)>> data_transfer_callback;
169164

165+
/* Callbacks for networking */
170166
/// \brief register a \p callback that is called when the websocket is connected successfully
171167
std::function < void(std::optional<NetworkConnectionProfile> network_profile)> websocket_connected_callback;
172168

173169
/// \brief register a \p callback that is called when the websocket connection is disconnected
174170
std::function<void()>websocket_disconnected_callback;
171+
172+
// callback is called when receiving a SetNetworkProfile.req from the CSMS
173+
std::optional<std::function<SetNetworkProfileStatusEnum(
174+
const int32_t configuration_slot, const NetworkConnectionProfile& network_connection_profile)>>
175+
validate_network_profile_callback;
176+
std::optional<std::function<bool(const NetworkConnectionProfile& network_connection_profile,
177+
std::promise<int>& network_promise)>>
178+
configure_network_connection_profile_callback;
175179
};
176180

177181
/// \brief Combines ChangeAvailabilityRequest with persist flag for scheduled Availability changes

lib/ocpp/v201/charge_point.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include <stdexcept>
1313
#include <string>
14-
14+
#include <future>
1515
using namespace std::chrono_literals;
1616

1717
const auto DEFAULT_MAX_CUSTOMER_INFORMATION_DATA_LENGTH = 51200;
@@ -649,6 +649,8 @@ bool ChargePoint::send(CallError call_error) {
649649

650650
void ChargePoint::init_websocket() {
651651

652+
std::promise<int> network_promise;
653+
652654
if (this->device_model->get_value<std::string>(ControllerComponentVariables::ChargePointId).find(':') !=
653655
std::string::npos) {
654656
EVLOG_AND_THROW(std::runtime_error("ChargePointId must not contain \':\'"));
@@ -663,7 +665,8 @@ void ChargePoint::init_websocket() {
663665

664666
if (!network_connection_profile.has_value() or
665667
(this->callbacks.configure_network_connection_profile_callback.has_value() and
666-
!this->callbacks.configure_network_connection_profile_callback.value()(network_connection_profile.value()))) {
668+
!this->callbacks.configure_network_connection_profile_callback.value()(network_connection_profile.value(),
669+
network_promise))) {
667670
EVLOG_warning << "NetworkConnectionProfile could not be retrieved or configuration of network with the given "
668671
"profile failed";
669672
this->websocket_timer.timeout(
@@ -675,6 +678,8 @@ void ChargePoint::init_websocket() {
675678
return;
676679
}
677680

681+
EVLOG_info << "connection profile value: -> " << network_promise.get_future().get();
682+
678683
const auto& security_profile_cv = ControllerComponentVariables::SecurityProfile;
679684
if (security_profile_cv.variable.has_value()) {
680685
this->device_model->set_read_only_value(security_profile_cv.component, security_profile_cv.variable.value(),

0 commit comments

Comments
 (0)