Skip to content

Commit 787dbb4

Browse files
committed
[wip] add a websocked connected and disconnected callback
Signed-off-by: Soumya Subramanya <s.subramanya@alfen.com>
1 parent 84b604a commit 787dbb4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

include/ocpp/v201/charge_point.hpp

+6
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ struct Callbacks {
166166
/// \brief Callback function that can be used to handle arbitrary data transfers for all vendorId and
167167
/// messageId
168168
std::optional<std::function<DataTransferResponse(const DataTransferRequest& request)>> data_transfer_callback;
169+
170+
/// \brief register a \p callback that is called when the websocket is connected successfully
171+
std::function < void(std::optional<NetworkConnectionProfile> network_profile)> websocket_connected_callback;
172+
173+
/// \brief register a \p callback that is called when the websocket connection is disconnected
174+
std::function<void()>websocket_disconnected_callback;
169175
};
170176

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

lib/ocpp/v201/charge_point.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ const auto DEFAULT_MAX_MESSAGE_SIZE = 65000;
2727
bool Callbacks::all_callbacks_valid() const {
2828
return this->is_reset_allowed_callback != nullptr and this->reset_callback != nullptr and
2929
this->stop_transaction_callback != nullptr and this->pause_charging_callback != nullptr and
30-
this->connector_effective_operative_status_changed_callback != nullptr and
30+
// this->connector_effective_operative_status_changed_callback != nullptr and
3131
this->get_log_request_callback != nullptr and this->unlock_connector_callback != nullptr and
3232
this->remote_start_transaction_callback != nullptr and this->is_reservation_for_token_callback != nullptr and
33-
this->update_firmware_request_callback != nullptr and
33+
this->update_firmware_request_callback != nullptr and this->websocket_connected_callback != nullptr and
34+
this->websocket_disconnected_callback != nullptr and
3435
(!this->variable_changed_callback.has_value() or this->variable_changed_callback.value() != nullptr) and
3536
(!this->validate_network_profile_callback.has_value() or
3637
this->validate_network_profile_callback.value() != nullptr) and
@@ -682,7 +683,7 @@ void ChargePoint::init_websocket() {
682683
}
683684

684685
this->websocket = std::make_unique<Websocket>(connection_options, this->evse_security, this->logging);
685-
this->websocket->register_connected_callback([this](const int security_profile) {
686+
this->websocket->register_connected_callback([this, network_connection_profile](const int security_profile) {
686687
this->message_queue->resume(this->message_queue_resume_delay);
687688

688689
const auto& security_profile_cv = ControllerComponentVariables::SecurityProfile;
@@ -691,6 +692,9 @@ void ChargePoint::init_websocket() {
691692
AttributeEnum::Actual, std::to_string(security_profile));
692693
}
693694

695+
// call the registered websocket connected callback
696+
this->callbacks.websocket_connected_callback(network_connection_profile);
697+
694698
if (this->registration_status == RegistrationStatusEnum::Accepted and
695699
this->time_disconnected.time_since_epoch() != 0s) {
696700
// handle offline threshold
@@ -723,7 +727,7 @@ void ChargePoint::init_websocket() {
723727
// Get the current time point using steady_clock
724728
this->time_disconnected = std::chrono::steady_clock::now();
725729
}
726-
730+
this->callbacks.websocket_disconnected_callback();
727731
this->client_certificate_expiration_check_timer.stop();
728732
this->v2g_certificate_expiration_check_timer.stop();
729733
});

0 commit comments

Comments
 (0)