Heartbeating#

constellation::heartbeat Namespace#

class HeartbeatManager#
#include <constellation/core/heartbeat/HeartbeatManager.hpp>

Manager for CHP publishing and receiving.

This manager holds a heartbeat sender and receiver as well as the logic for calling FSM interrupts based on received heartbeats. It keeps track of received heartbeats from remote heartbeat senders, counts their lives and takes action either upon missing heartbeats or a remote ERROR state of the FSM.

Public Functions

HeartbeatManager(std::string sender, std::function<protocol::CSCP::State()> state_callback, std::function<void(std::string_view)> interrupt_callback)#

Construct a heartbeat manager.

The constructor directly starts sender and receiver as well as the manager’s watchdog thread which keeps track of remote heartbeat rates and states

Parameters:
  • sender – Canonical name of the heartbeat sender

  • state_callback – Function that return the current state

  • interrupt_callback – Interrupt callback which is invoked when a remote heartbeat sender reports an ERROR state or stopped sending heartbeats

virtual ~HeartbeatManager()#

Deconstruct the manager. This stops the watchdog thread

void sendExtrasystole()#

Send an extrasystole.

std::optional<protocol::CSCP::State> getRemoteState(std::string_view remote)#

Obtain the current state registered from a given remote.

Parameters:

remote – Canonical name of the remote in question

Returns:

Currently registered state of the remote if remote is present, empty optional otherwise

inline void updateInterval(std::chrono::milliseconds interval)#

Update the maximum heartbeat interval to a new value.

Note

Heartbeats are send roughly twice as often as the maximum heartbeat interval

Parameters:

interval – New maximum heartbeat interval

class HeartbeatRecv : public constellation::pools::SubscriberPool<message::CHP1Message, chirp::HEARTBEAT>#
#include <constellation/core/heartbeat/HeartbeatRecv.hpp>

Receiver class for distributed heartbeats in a constellation.

This class registers a CHIRP callback for heartbeat services, subscribes automatically to all available and appearing services in the constellation and listens for heartbeat and extrasystole messages from remote satellites and forwards them to a callback registered upon creation of the receiver.

Note

Needs to be started with start() and stopped with stop()

Public Functions

inline HeartbeatRecv(std::function<void(message::CHP1Message&&)> callback)#

Construct heartbeat receiver.

Parameters:

callback – Callback function pointer for received heartbeat messages

class HeartbeatSend#
#include <constellation/core/heartbeat/HeartbeatSend.hpp>

Sender class which emits heartbeat messages in regular intervals as well as extrasystoles at state changes

Public Functions

HeartbeatSend(std::string sender, std::function<protocol::CSCP::State()> state_callback, std::chrono::milliseconds interval)#

Construct a heartbeat sender.

This directly opens a socket, binds to an ephemeral port and starts emission of heartbeats. It also registers a CHIRP heartbeat service.

Parameters:
  • sender – Canonical name of the sender

  • state_callback – Function that return the current state

  • interval – Interval at which the heartbeats are sent

~HeartbeatSend()#

Destructor which unregisters the CHIRP heartbeat service and stops the heartbeat thread

inline constexpr utils::Port getPort() const#

Get ephemeral port to which the CHP socket is bound.

Returns:

Port number

inline void updateInterval(std::chrono::milliseconds interval)#

Update the maximum heartbeat interval to a new value.

Note

Heartbeats are send roughly twice as often as the maximum heartbeat interval

Parameters:

interval – New maximum heartbeat interval

void sendExtrasystole()#

Send an extrasystole.