Heartbeating#

constellation::heartbeat Namespace#

class HeartbeatManager : public constellation::heartbeat::HeartbeatRecv#
#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

inline void allowDeparture(bool allow)#

Configure whether regular departures are allows.

If set to true, departing satellites which send a proper DEPART CHIRP message are not considered erroneous but are removed from the list of monitored heartbeats. If set to false, any missing heartbeat, even after a regular departure, is considered erroneous and the interruption callback is activated

Parameters:

allow – Boolean flag whether regular departures are allowed or not

inline utils::Port getPort() const#

Get ephemeral port to which the CHP socket is bound.

Returns:

Port number

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()

Subclassed by constellation::heartbeat::HeartbeatManager

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 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.