Skip to content

Commit

Permalink
added connection_state_changed_callback which will be called on webso…
Browse files Browse the repository at this point in the history
…cket connect or disconnect

Signed-off-by: pietfried <[email protected]>
  • Loading branch information
Pietfried committed Dec 12, 2022
1 parent ed433da commit 8572810
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/ocpp1_6/charge_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class ChargePoint {
std::function<void(const ResetType& reset_type)> reset_callback;
std::function<void(const std::string& system_time)> set_system_time_callback;
std::function<void()> signal_set_charging_profiles_callback;
std::function<void(bool is_connected)> connection_state_changed_callback;

std::function<ocpp1_6::GetLogResponse(const ocpp1_6::GetDiagnosticsRequest& request)> upload_diagnostics_callback;
std::function<void(const ocpp1_6::UpdateFirmwareRequest msg)> update_firmware_callback;
Expand Down Expand Up @@ -432,6 +433,8 @@ class ChargePoint {
/// \brief registers a \p callback function that can be used to signal that the chargepoint received a
/// SetChargingProfile.req
void register_signal_set_charging_profiles_callback(const std::function<void()>& callback);

void register_connection_state_changed_callback(const std::function<void(bool is_connected)>& callback);
};

} // namespace ocpp1_6
10 changes: 10 additions & 0 deletions lib/ocpp1_6/charge_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,16 @@ ChargePoint::ChargePoint(std::shared_ptr<ChargePointConfiguration> configuration
void ChargePoint::init_websocket(int32_t security_profile) {
this->websocket = std::make_unique<Websocket>(this->configuration, security_profile, this->logging);
this->websocket->register_connected_callback([this]() {
if (this->connection_state_changed_callback != nullptr) {
this->connection_state_changed_callback(true);
}
this->message_queue->resume(); //
this->connected_callback(); //
});
this->websocket->register_disconnected_callback([this]() {
if (this->connection_state_changed_callback != nullptr) {
this->connection_state_changed_callback(false);
}
this->message_queue->pause(); //
if (this->switch_security_profile_callback != nullptr) {
this->switch_security_profile_callback();
Expand Down Expand Up @@ -2734,6 +2740,10 @@ void ChargePoint::register_set_connection_timeout_callback(
this->set_connection_timeout_callback = callback;
}

void ChargePoint::register_connection_state_changed_callback(const std::function<void(bool is_connected)>& callback) {
this->connection_state_changed_callback = callback;
}

void ChargePoint::on_reservation_start(int32_t connector) {
this->status->submit_event(connector, Event_ReserveConnector());
}
Expand Down

0 comments on commit 8572810

Please sign in to comment.