Skip to content

Commit

Permalink
[wip] experiment with promise and future
Browse files Browse the repository at this point in the history
Signed-off-by: Soumya Subramanya <[email protected]>

[wip] fixed bug in print statement

Signed-off-by: Soumya Subramanya <[email protected]>
  • Loading branch information
SNSubramanya committed Jan 22, 2024
1 parent cc972b8 commit 16146bc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config/v201/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@
"SupportedCriteria": {
"variable_name": "SupportedCriteria",
"attributes": {
"Actual": "Enabled,Active,Available,Problem"
"Actual": "Enabled,Active,Available"
}
}
}
Expand Down
16 changes: 10 additions & 6 deletions include/ocpp/v201/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,7 @@ struct Callbacks {
std::function<UpdateFirmwareResponse(const UpdateFirmwareRequest& request)> update_firmware_request_callback;
// callback to be called when a variable has been changed by the CSMS
std::optional<std::function<void(const SetVariableData& set_variable_data)>> variable_changed_callback;
// callback is called when receiving a SetNetworkProfile.req from the CSMS
std::optional<std::function<SetNetworkProfileStatusEnum(
const int32_t configuration_slot, const NetworkConnectionProfile& network_connection_profile)>>
validate_network_profile_callback;
std::optional<std::function<bool(const NetworkConnectionProfile& network_connection_profile)>>
configure_network_connection_profile_callback;

std::optional<std::function<void(const ocpp::DateTime& currentTime)>> time_sync_callback;

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

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

/// \brief register a \p callback that is called when the websocket connection is disconnected
std::function<void()>websocket_disconnected_callback;

// callback is called when receiving a SetNetworkProfile.req from the CSMS
std::optional<std::function<SetNetworkProfileStatusEnum(
const int32_t configuration_slot, const NetworkConnectionProfile& network_connection_profile)>>
validate_network_profile_callback;
std::optional<std::function<bool(const NetworkConnectionProfile& network_connection_profile,
std::promise<int>& network_promise)>>
configure_network_connection_profile_callback;
};

/// \brief Combines ChangeAvailabilityRequest with persist flag for scheduled Availability changes
Expand Down
9 changes: 7 additions & 2 deletions lib/ocpp/v201/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <stdexcept>
#include <string>

#include <future>
using namespace std::chrono_literals;

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

void ChargePoint::init_websocket() {

std::promise<int> network_promise;

if (this->device_model->get_value<std::string>(ControllerComponentVariables::ChargePointId).find(':') !=
std::string::npos) {
EVLOG_AND_THROW(std::runtime_error("ChargePointId must not contain \':\'"));
Expand All @@ -663,7 +665,8 @@ void ChargePoint::init_websocket() {

if (!network_connection_profile.has_value() or
(this->callbacks.configure_network_connection_profile_callback.has_value() and
!this->callbacks.configure_network_connection_profile_callback.value()(network_connection_profile.value()))) {
!this->callbacks.configure_network_connection_profile_callback.value()(network_connection_profile.value(),
network_promise))) {
EVLOG_warning << "NetworkConnectionProfile could not be retrieved or configuration of network with the given "
"profile failed";
this->websocket_timer.timeout(
Expand All @@ -675,6 +678,8 @@ void ChargePoint::init_websocket() {
return;
}

EVLOG_info << "connection profile value: -> " << network_promise.get_future().get();

const auto& security_profile_cv = ControllerComponentVariables::SecurityProfile;
if (security_profile_cv.variable.has_value()) {
this->device_model->set_read_only_value(security_profile_cv.component, security_profile_cv.variable.value(),
Expand Down

0 comments on commit 16146bc

Please sign in to comment.