17#ifndef ISOBUS_HEARTBEAT_HPP
18#define ISOBUS_HEARTBEAT_HPP
23#include "isobus/utility/event_dispatcher.hpp"
66 bool request_heartbeat(std::shared_ptr<InternalControlFunction> sourceControlFunction,
67 std::shared_ptr<ControlFunction> destinationControlFunction)
const;
119 explicit Heartbeat(std::shared_ptr<ControlFunction> sendingControlFunction);
141 std::shared_ptr<ControlFunction> requestingControlFunction,
142 std::shared_ptr<ControlFunction> targetControlFunction,
143 std::uint32_t repetitionRate,
144 void *parentPointer);
An object to represent common callbacks used within this CAN stack.
A representation of an ISOBUS ECU that we can send from. Use this class when defining your own contro...
An abstraction of a CAN message, could be > 8 data bytes.
A class that represents a generic CAN message of arbitrary length.
This class is used to store information about a tracked heartbeat.
std::shared_ptr< ControlFunction > controlFunction
The CF that is sending the message.
Heartbeat(std::shared_ptr< ControlFunction > sendingControlFunction)
Constructor for a Heartbeat.
bool send(const HeartbeatInterface &parent)
Transmits a heartbeat message (for internal control functions only). Updates the sequence counter and...
std::uint32_t repetitionRate_ms
For internal control functions, this controls how often the heartbeat is sent. This should really sta...
std::uint32_t timestamp_ms
The last time the message was sent by the associated control function.
std::uint8_t sequenceCounter
The sequence counter used to validate the heartbeat. Counts from 0-250 normally.
This class is used to send and receive ISOBUS heartbeats.
EventDispatcher< std::shared_ptr< ControlFunction > > newTrackedHeartbeatEventDispatcher
Event dispatcher for when a heartbeat message from another control function becomes tracked by this i...
static bool process_request_for_heartbeat(std::uint32_t parameterGroupNumber, std::shared_ptr< ControlFunction > requestingControlFunction, std::shared_ptr< ControlFunction > targetControlFunction, std::uint32_t repetitionRate, void *parentPointer)
Processes a PGN request for a heartbeat.
void set_enabled(bool enable)
This can be used to disable or enable this heartbeat functionality. It's probably best to leave it en...
EventDispatcher< std::shared_ptr< ControlFunction > > & get_new_tracked_heartbeat_event_dispatcher()
Returns an event dispatcher which can be used to register for new tracked heartbeat events....
std::list< Heartbeat > trackedHeartbeats
Store tracked heartbeat data, per CF.
HeartBeatError
This enum is used to define the possible errors that can occur when receiving a heartbeat.
@ InvalidSequenceCounter
The sequence counter is not valid.
@ TimedOut
The heartbeat message has not been received within the repetition rate.
EventDispatcher< HeartBeatError, std::shared_ptr< ControlFunction > > & get_heartbeat_error_event_dispatcher()
Returns an event dispatcher which can be used to register for heartbeat errors. Heartbeat errors are ...
static constexpr std::uint32_t SEQUENCE_TIMEOUT_MS
If the repetition rate exceeds 300 ms an error in the communication is detected.
bool is_enabled() const
Returns if the interface is currently enabled or not.
SequenceCounterSpecialValue
This enum is used to define special values for the sequence counter.
@ Initial
The heartbeat sequence number value shall be set to 251 once upon initialization of a CF.
@ NotAvailable
This value shall be used when the transmitted CF is in a shutdown status and is gracefully disconnect...
@ Error
Sequence Number value 254 indicates an error condition.
bool enabled
Attribute that specifies if this interface is enabled. When false, the interface does nothing.
bool request_heartbeat(std::shared_ptr< InternalControlFunction > sourceControlFunction, std::shared_ptr< ControlFunction > destinationControlFunction) const
This method can be used to request that another control function on the bus start sending the heartbe...
static constexpr std::uint32_t SEQUENCE_INITIAL_RESPONSE_TIMEOUT_MS
When requesting a heartbeat from another device, If no response for the repetition rate has been rece...
void update()
Updates the interface. Called by the network manager, so there is no need for you to call it in your ...
void process_rx_message(const CANMessage &message)
Processes a CAN message, called by the network manager.
static constexpr std::uint32_t SEQUENCE_REPETITION_RATE_MS
A consuming CF shall send a Request for Repetition rate for the heart beat message with a repetition ...
EventDispatcher< HeartBeatError, std::shared_ptr< ControlFunction > > heartbeatErrorEventDispatcher
Event dispatcher for heartbeat errors.
const CANMessageFrameCallback sendCANFrameCallback
A callback for sending a CAN frame.
void on_destroyed_internal_control_function(std::shared_ptr< InternalControlFunction > destroyedControlFunction)
Called when an internal control function is deleted. Cleans up stale registrations with PGN request p...
void on_new_internal_control_function(std::shared_ptr< InternalControlFunction > newControlFunction)
Called by the internal control function class when a new internal control function is added....
HeartbeatInterface(const CANMessageFrameCallback &sendCANFrameCallback)
Constructor for a HeartbeatInterface.
This namespace encompasses all of the ISO11783 stack's functionality to reduce global namespace pollu...
std::function< bool(std::uint32_t parameterGroupNumber, CANDataSpan data, std::shared_ptr< InternalControlFunction > sourceControlFunction, std::shared_ptr< ControlFunction > destinationControlFunction, CANIdentifier::CANPriority priority)> CANMessageFrameCallback
A callback for communicating CAN message frames.