AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
nmea2000_message_interface.hpp
Go to the documentation of this file.
1//================================================================================================
18//================================================================================================
19#ifndef NMEA2000_MESSAGE_INTERFACE_HPP
20#define NMEA2000_MESSAGE_INTERFACE_HPP
21
23#include "isobus/utility/event_dispatcher.hpp"
24#include "isobus/utility/processing_flags.hpp"
25
26namespace isobus
27{
30 {
31 public:
41 NMEA2000MessageInterface(std::shared_ptr<InternalControlFunction> sendingControlFunction,
42 bool enableSendingCogSogCyclically,
43 bool enableSendingDatumCyclically,
44 bool enableSendingGNSSPositionDataCyclically,
45 bool enableSendingPositionDeltaHighPrecisionRapidUpdateCyclically,
46 bool enableSendingPositionRapidUpdateCyclically,
47 bool enableSendingRateOfTurnCyclically,
48 bool enableSendingVesselHeadingCyclically);
49
52
57
62
67
72
77
82
87
91
95
99
103
107
111
115
123 std::shared_ptr<NMEA2000Messages::CourseOverGroundSpeedOverGroundRapidUpdate> get_received_course_speed_over_ground_message(std::size_t index) const;
124
132 std::shared_ptr<NMEA2000Messages::Datum> get_received_datum_message(std::size_t index) const;
133
141 std::shared_ptr<NMEA2000Messages::GNSSPositionData> get_received_gnss_position_data_message(std::size_t index) const;
142
150 std::shared_ptr<NMEA2000Messages::PositionDeltaHighPrecisionRapidUpdate> get_received_position_delta_high_precision_rapid_update_message(std::size_t index) const;
151
159 std::shared_ptr<NMEA2000Messages::PositionRapidUpdate> get_received_position_rapid_update_message(std::size_t index) const;
160
168 std::shared_ptr<NMEA2000Messages::RateOfTurn> get_received_rate_of_turn_message(std::size_t index) const;
169
177 std::shared_ptr<NMEA2000Messages::VesselHeading> get_received_vessel_heading_message(std::size_t index) const;
178
181 EventDispatcher<const std::shared_ptr<NMEA2000Messages::CourseOverGroundSpeedOverGroundRapidUpdate>, bool> &get_course_speed_over_ground_rapid_update_event_publisher();
182
185 EventDispatcher<const std::shared_ptr<NMEA2000Messages::Datum>, bool> &get_datum_event_publisher();
186
189 EventDispatcher<const std::shared_ptr<NMEA2000Messages::GNSSPositionData>, bool> &get_gnss_position_data_event_publisher();
190
193 EventDispatcher<const std::shared_ptr<NMEA2000Messages::PositionDeltaHighPrecisionRapidUpdate>, bool> &get_position_delta_high_precision_rapid_update_event_publisher();
194
197 EventDispatcher<const std::shared_ptr<NMEA2000Messages::PositionRapidUpdate>, bool> &get_position_rapid_update_event_publisher();
198
201 EventDispatcher<const std::shared_ptr<NMEA2000Messages::RateOfTurn>, bool> &get_rate_of_turn_event_publisher();
202
205 EventDispatcher<const std::shared_ptr<NMEA2000Messages::VesselHeading>, bool> &get_vessel_heading_event_publisher();
206
210
214
218
221 void set_enable_sending_datum_cyclically(bool enable);
222
226
230
234
238
242
246
250
254
258
262
264 void initialize();
265
268 bool get_initialized() const;
269
271 void terminate();
272
274 void update();
275
276 private:
278 enum class TransmitFlags : std::uint32_t
279 {
281 Datum,
287
288 NumberOfFlags
289 };
290
294 static void process_flags(std::uint32_t flag, void *parentPointer);
295
299 static void process_rx_message(const CANMessage &message, void *parentPointer);
300
303
306
307 ProcessingFlags txFlags;
315 std::vector<std::shared_ptr<NMEA2000Messages::CourseOverGroundSpeedOverGroundRapidUpdate>> receivedCogSogMessages;
316 std::vector<std::shared_ptr<NMEA2000Messages::Datum>> receivedDatumMessages;
317 std::vector<std::shared_ptr<NMEA2000Messages::GNSSPositionData>> receivedGNSSPositionDataMessages;
318 std::vector<std::shared_ptr<NMEA2000Messages::PositionDeltaHighPrecisionRapidUpdate>> receivedPositionDeltaHighPrecisionRapidUpdateMessages;
319 std::vector<std::shared_ptr<NMEA2000Messages::PositionRapidUpdate>> receivedPositionRapidUpdateMessages;
320 std::vector<std::shared_ptr<NMEA2000Messages::RateOfTurn>> receivedRateOfTurnMessages;
321 std::vector<std::shared_ptr<NMEA2000Messages::VesselHeading>> receivedVesselHeadingMessages;
322 EventDispatcher<const std::shared_ptr<NMEA2000Messages::CourseOverGroundSpeedOverGroundRapidUpdate>, bool> cogSogEventPublisher;
323 EventDispatcher<const std::shared_ptr<NMEA2000Messages::Datum>, bool> datumEventPublisher;
324 EventDispatcher<const std::shared_ptr<NMEA2000Messages::GNSSPositionData>, bool> gnssPositionDataEventPublisher;
325 EventDispatcher<const std::shared_ptr<NMEA2000Messages::PositionDeltaHighPrecisionRapidUpdate>, bool> positionDeltaHighPrecisionRapidUpdateEventPublisher;
326 EventDispatcher<const std::shared_ptr<NMEA2000Messages::PositionRapidUpdate>, bool> positionRapidUpdateEventPublisher;
327 EventDispatcher<const std::shared_ptr<NMEA2000Messages::RateOfTurn>, bool> rateOfTurnEventPublisher;
328 EventDispatcher<const std::shared_ptr<NMEA2000Messages::VesselHeading>, bool> vesselHeadingEventPublisher;
336 bool initialized = false;
337 };
338} // namespace isobus
339#endif // NMEA2000_MESSAGE_INTERFACE_HPP
A class that represents a generic CAN message of arbitrary length.
An interface for sending and receiving common NMEA2000 messages on an ISO11783 network.
void check_transmit_timeouts()
Checks to see if any transmit flags need to be set based on the last time the message was sent,...
NMEA2000Messages::GNSSPositionData gnssPositionDataTransmitMessage
Stores a set of data specifically for transmitting the PGN 129029 (0x1F805) if enabled.
EventDispatcher< const std::shared_ptr< NMEA2000Messages::Datum >, bool > datumEventPublisher
An event dispatcher for notifying when new guidance machine info messages are received.
std::vector< std::shared_ptr< NMEA2000Messages::PositionRapidUpdate > > receivedPositionRapidUpdateMessages
Stores all received (and not timed out) sources of the position rapid update message.
std::shared_ptr< NMEA2000Messages::RateOfTurn > get_received_rate_of_turn_message(std::size_t index) const
Returns the content of the rate of turn message based on the index of the sender. Use this to read th...
EventDispatcher< const std::shared_ptr< NMEA2000Messages::GNSSPositionData >, bool > & get_gnss_position_data_event_publisher()
Returns an event dispatcher which you can use to get callbacks when new/updated GNSS position data me...
bool get_enable_sending_cog_sog_cyclically() const
Returns if the interface has cyclic sending of the course/speed over ground message enabled.
EventDispatcher< const std::shared_ptr< NMEA2000Messages::PositionDeltaHighPrecisionRapidUpdate >, bool > positionDeltaHighPrecisionRapidUpdateEventPublisher
An event dispatcher for notifying when new guidance machine info messages are received.
void set_enable_sending_vessel_heading_cyclically(bool enable)
Instructs the interface to enable or disable sending the vessel heading message cyclically.
std::vector< std::shared_ptr< NMEA2000Messages::VesselHeading > > receivedVesselHeadingMessages
Stores all received (and not timed out) sources of the vessel heading message.
std::shared_ptr< NMEA2000Messages::Datum > get_received_datum_message(std::size_t index) const
Returns the content of the Datum message based on the index of the sender. Use this to read the recei...
NMEA2000Messages::VesselHeading vesselHeadingTransmitMessage
Stores a set of data specifically for transmitting the PGN 127250 (0x1F112) if enabled.
EventDispatcher< const std::shared_ptr< NMEA2000Messages::VesselHeading >, bool > vesselHeadingEventPublisher
An event dispatcher for notifying when new guidance machine info messages are received.
bool get_enable_sending_rate_of_turn_cyclically() const
Returns if the interface has cyclic sending of the rate of turn message enabled.
void set_enable_sending_datum_cyclically(bool enable)
Instructs the interface to enable or disable sending the datum data message cyclically.
NMEA2000Messages::RateOfTurn rateOfTurnTransmitMessage
Stores a set of data specifically for transmitting the PGN 127251 (0x1F113) if enabled.
bool sendGNSSPositionDataCyclically
Determines if the interface will try to send the GNSS position data message cyclically.
static void process_flags(std::uint32_t flag, void *parentPointer)
A generic callback for a the class to process flags from the ProcessingFlags
NMEA2000Messages::RateOfTurn & get_rate_of_turn_transmit_message()
Returns a RateOfTurn object that you can use to set the message's individual signal values,...
std::vector< std::shared_ptr< NMEA2000Messages::Datum > > receivedDatumMessages
Stores all received (and not timed out) sources of the Datum message.
ProcessingFlags txFlags
A set of flags used to track what messages need to be transmitted or retried.
void set_enable_sending_position_rapid_update_cyclically(bool enable)
Instructs the interface to enable or disable sending the position rapid update message cyclically.
NMEA2000MessageInterface(std::shared_ptr< InternalControlFunction > sendingControlFunction, bool enableSendingCogSogCyclically, bool enableSendingDatumCyclically, bool enableSendingGNSSPositionDataCyclically, bool enableSendingPositionDeltaHighPrecisionRapidUpdateCyclically, bool enableSendingPositionRapidUpdateCyclically, bool enableSendingRateOfTurnCyclically, bool enableSendingVesselHeadingCyclically)
Constructor for a NMEA2000MessageInterface.
bool get_enable_sending_datum_cyclically() const
Returns if the interface has cyclic sending of the datum message enabled.
void update()
Updates the diagnostic protocol. Must be called periodically. 50ms Is a good minimum interval for thi...
EventDispatcher< const std::shared_ptr< NMEA2000Messages::PositionRapidUpdate >, bool > positionRapidUpdateEventPublisher
An event dispatcher for notifying when new guidance machine info messages are received.
void check_receive_timeouts()
Checks to see if any received messages are timed out and prunes them if needed.
void set_enable_sending_gnss_position_data_cyclically(bool enable)
Instructs the interface to enable or disable sending the GNSS position data message cyclically.
bool get_enable_sending_position_rapid_update_cyclically() const
Returns if the interface has cyclic sending of the position rapid update message enabled.
bool sendVesselHeadingCyclically
Determines if the interface will try to send the vessel heading message cyclically.
EventDispatcher< const std::shared_ptr< NMEA2000Messages::CourseOverGroundSpeedOverGroundRapidUpdate >, bool > & get_course_speed_over_ground_rapid_update_event_publisher()
Returns an event dispatcher which you can use to get callbacks when new/updated COG & SOG messages ar...
bool sendDatumCyclically
Determines if the interface will try to send the Datum message cyclically.
NMEA2000Messages::GNSSPositionData & get_gnss_position_data_transmit_message()
Returns a GNSSPositionData object that you can use to set the message's individual signal values,...
NMEA2000Messages::PositionDeltaHighPrecisionRapidUpdate positionDeltaHighPrecisionRapidUpdateTransmitMessage
Stores a set of data specifically for transmitting the PGN 129027 (0x1F803) if enabled.
NMEA2000Messages::Datum & get_datum_transmit_message()
Returns a Datum object that you can use to set the message's individual signal values,...
bool get_enable_sending_vessel_heading_cyclically() const
Returns if the interface has cyclic sending of the vessel heading message enabled.
std::size_t get_number_received_rate_of_turn_message_sources() const
Returns the number of unique rate of turn message senders.
EventDispatcher< const std::shared_ptr< NMEA2000Messages::GNSSPositionData >, bool > gnssPositionDataEventPublisher
An event dispatcher for notifying when new guidance machine info messages are received.
NMEA2000Messages::Datum datumTransmitMessage
Stores a set of data specifically for transmitting the PGN 129044 (0x1F814) if enabled.
bool sendPositionRapidUpdateCyclically
Determines if the interface will try to send the position rapid update message cyclically.
std::shared_ptr< NMEA2000Messages::GNSSPositionData > get_received_gnss_position_data_message(std::size_t index) const
Returns the content of the GNSS position data message based on the index of the sender....
std::size_t get_number_received_datum_message_sources() const
Returns the number of unique datum message senders.
std::size_t get_number_received_vessel_heading_message_sources() const
Returns the number of unique vessel heading message senders.
bool get_initialized() const
Returns if initialize has been called.
static void process_rx_message(const CANMessage &message, void *parentPointer)
Processes a CAN message destined for an instance of this interface.
NMEA2000Messages::PositionDeltaHighPrecisionRapidUpdate & get_position_delta_high_precision_rapid_update_transmit_message()
Returns a PositionDeltaHighPrecisionRapidUpdate object that you can use to set the message's individu...
std::size_t get_number_received_gnss_position_data_message_sources() const
Returns the number of unique GNSS position data message senders.
EventDispatcher< const std::shared_ptr< NMEA2000Messages::CourseOverGroundSpeedOverGroundRapidUpdate >, bool > cogSogEventPublisher
An event dispatcher for notifying when new guidance machine info messages are received.
void initialize()
Initializes the interface. Registers it with the network manager. Must be called before the interface...
std::shared_ptr< NMEA2000Messages::PositionDeltaHighPrecisionRapidUpdate > get_received_position_delta_high_precision_rapid_update_message(std::size_t index) const
Returns the content of the position delta high precision rapid update message based on the index of t...
std::shared_ptr< NMEA2000Messages::CourseOverGroundSpeedOverGroundRapidUpdate > get_received_course_speed_over_ground_message(std::size_t index) const
Returns the content of the COG & SOG message based on the index of the sender. Use this to read the r...
void set_enable_sending_position_delta_high_precision_rapid_update_cyclically(bool enable)
Instructs the interface to enable or disable sending the position delta high precision rapid update m...
EventDispatcher< const std::shared_ptr< NMEA2000Messages::VesselHeading >, bool > & get_vessel_heading_event_publisher()
Returns an event dispatcher which you can use to get callbacks when new/updated vessel heading messag...
EventDispatcher< const std::shared_ptr< NMEA2000Messages::RateOfTurn >, bool > rateOfTurnEventPublisher
An event dispatcher for notifying when new guidance machine info messages are received.
EventDispatcher< const std::shared_ptr< NMEA2000Messages::PositionRapidUpdate >, bool > & get_position_rapid_update_event_publisher()
Returns an event dispatcher which you can use to get callbacks when new/updated position rapid update...
bool get_enable_sending_position_delta_high_precision_rapid_update_cyclically() const
Returns if the interface has cyclic sending of the position delta high precision rapid update message...
std::shared_ptr< NMEA2000Messages::PositionRapidUpdate > get_received_position_rapid_update_message(std::size_t index) const
Returns the content of the position rapid update message based on the index of the sender....
std::size_t get_number_received_position_rapid_update_message_sources() const
Returns the number of unique position rapid update message senders.
NMEA2000Messages::CourseOverGroundSpeedOverGroundRapidUpdate cogSogTransmitMessage
Stores a set of data specifically for transmitting the PGN 129026 (0x1F802) if enabled.
EventDispatcher< const std::shared_ptr< NMEA2000Messages::RateOfTurn >, bool > & get_rate_of_turn_event_publisher()
Returns an event dispatcher which you can use to get callbacks when new/updated rate of turn messages...
NMEA2000Messages::PositionRapidUpdate positionRapidUpdateTransmitMessage
Stores a set of data specifically for transmitting the PGN 129025 (0x1F801) if enabled.
void set_enable_sending_cog_sog_cyclically(bool enable)
Instructs the interface to enable or disable sending the course/speed over ground message cyclically.
void set_enable_sending_rate_of_turn_cyclically(bool enable)
Instructs the interface to enable or disable sending the rate of turn message cyclically.
EventDispatcher< const std::shared_ptr< NMEA2000Messages::Datum >, bool > & get_datum_event_publisher()
Returns an event dispatcher which you can use to get callbacks when new/updated datum messages are re...
std::size_t get_number_received_position_delta_high_precision_rapid_update_message_sources() const
Returns the number of unique delta position message senders.
bool sendCogSogCyclically
Determines if the interface will try to send the COG & SOG message cyclically.
NMEA2000Messages::VesselHeading & get_vessel_heading_transmit_message()
Returns a VesselHeading object that you can use to set the message's individual signal values,...
void terminate()
Unregisters the interface from the network manager.
std::shared_ptr< NMEA2000Messages::VesselHeading > get_received_vessel_heading_message(std::size_t index) const
Returns the content of the vessel heading message based on the index of the sender....
bool get_enable_sending_gnss_position_data_cyclically() const
Returns if the interface has cyclic sending of the GNSS position data message enabled.
NMEA2000Messages::CourseOverGroundSpeedOverGroundRapidUpdate & get_cog_sog_transmit_message()
Returns a CourseOverGroundSpeedOverGroundRapidUpdate object that you can use to set the message's ind...
EventDispatcher< const std::shared_ptr< NMEA2000Messages::PositionDeltaHighPrecisionRapidUpdate >, bool > & get_position_delta_high_precision_rapid_update_event_publisher()
Returns an event dispatcher which you can use to get callbacks when new/updated position delta high p...
NMEA2000Messages::PositionRapidUpdate & get_position_rapid_update_transmit_message()
Returns a PositionRapidUpdate object that you can use to set the message's individual signal values,...
std::vector< std::shared_ptr< NMEA2000Messages::PositionDeltaHighPrecisionRapidUpdate > > receivedPositionDeltaHighPrecisionRapidUpdateMessages
Stores all received (and not timed out) sources of the position delta message.
std::vector< std::shared_ptr< NMEA2000Messages::RateOfTurn > > receivedRateOfTurnMessages
Stores all received (and not timed out) sources of the rate of turn message.
~NMEA2000MessageInterface()
Destructor for a NMEA2000MessageInterface.
std::vector< std::shared_ptr< NMEA2000Messages::GNSSPositionData > > receivedGNSSPositionDataMessages
Stores all received (and not timed out) sources of the GNSS position data message.
TransmitFlags
Enumerates a set of flags to manage sending various NMEA2000 messages from this interface.
bool sendRateOfTurnCyclically
Determines if the interface will try to send the rate of turn message cyclically.
std::vector< std::shared_ptr< NMEA2000Messages::CourseOverGroundSpeedOverGroundRapidUpdate > > receivedCogSogMessages
Stores all received (and not timed out) sources of the COG & SOG message.
bool sendPositionDeltaHighPrecisionRapidUpdateCyclically
Determines if the interface will try to send the position delta high precision rapid update message m...
std::size_t get_number_received_course_speed_over_ground_message_sources() const
Returns the number of unique senders of the COG & SOG message.
bool initialized
Tracks if initialize has been called.
Represents the data sent in the NMEA2K PGN 129026 (0x1F802)
A NMEA2000 message that describes datum (reference frame) information. PGN 129044 (0x1F814) A common ...
Represents the data sent in the NMEA2K PGN 129029 (0x1F805)
This message is a way for a GNSS receiver to provide a current position without using fast packet bas...
Represents the data sent in the NMEA2K PGN 129025 (0x1F801)
Represents the data sent in the NMEA2K PGN 127251 (0x1F113)
Represents the data sent in the NMEA2K PGN 127250 (0x1F112)
This namespace encompasses all of the ISO11783 stack's functionality to reduce global namespace pollu...
This file contains class definitions that will comprise the individual components of the NMEA2000 mes...