EasyNmea

class eduponz::easynmea::EasyNmea

This class provides an interface with NMEA modules using NMEA 0183 protocol over serial connections.

It can be used to:

  • Open and close serial connection with the modules.

  • Wait for specific NMEA sentences to be received.

  • Read incoming NMEA data in a parsed and understandable manner.

Public Functions

EasyNmea() noexcept

Default constructor. Constructs a EasyNmea.

~EasyNmea() noexcept

Virtual default destructor.

ReturnCode open(const char *serial_port, long baudrate) noexcept

Open a serial connection.

It opens a serial connection on a given port with a given baudrate; given that the connection was not previously opened.

Pre

The EasyNmea does not have any serial port opened. That is, either it is the first call to open(), or close() has been called before open().

Return

open() can return:

Parameters
  • [in] serial_port: A string containing the serial port name.

  • [in] baudrate: The communication baudrate.

bool is_open() noexcept

Check whether a serial connection is opened

Return

true if there is an opened serial connection; false otherwise.

ReturnCode close() noexcept

Close a serial connection

Pre

A successful call to open() has been performed.

Return

close() can return:

ReturnCode take_next(GPGGAData &gpgga) noexcept

Take the next untaken GPGGA data sample available.

EasyNmea stores up to the last 10 reported GPGGA data samples. take_next() is used to retrieve the oldest untaken GPGGA sample.

Return

take_next() can return:

Parameters
  • [out] gpgga: A GPGGAData instance which will be populated with the sample.

ReturnCode wait_for_data(NMEA0183DataKindMask data_mask = NMEA0183DataKindMask::all(), std::chrono::milliseconds timeout = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::hours(8760))) noexcept

Block the calling thread until there is data available.

Block the calling thread until data of the specified kind or kinds is available for the taking, or the timeout expires.

Return

wait_for_data() can return:

Parameters
  • [in] data_mask: A NMEA0183DataKindMask used to specify on which data kinds should the call return, thus unblocking the calling thread. When wait_for_data returns data_mask holds the types of data that have been received. Defaults to NMEA0183DataKindMask::all().

  • [in] timeout: The time in millisecond after which the function must return even when no data was received. Defaults to 8760 hours (1 year).