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¶ 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()
, orclose()
has been called beforeopen()
.- Return
open()
can return:ReturnCode::RETURN_CODE_OK if the port is opened correctly.
ReturnCode::RETURN_CODE_ERROR is the port could not be opened.
ReturnCode::RETURN_CODE_ILLEGAL_OPERATION if a previous call to open was performed in the same EasyNmea instance, regardless of the port.
- 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::RETURN_CODE_OK if the connection was successfully closed.
ReturnCode::RETURN_CODE_ERROR if the connection could not be closed.
ReturnCode::RETURN_CODE_ILLEGAL_OPERATION if there was not open connection.
-
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:ReturnCode::RETURN_CODE_OK if the operation succeeded.
ReturnCode::RETURN_CODE_NO_DATA if there are not any untaken
GPGGAData
samples.
- Parameters
[out] gpgga
: AGPGGAData
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:ReturnCode::RETURN_CODE_OK if a sample of any of the kinds specified in the mask has been received.
ReturnCode::RETURN_CODE_TIMEOUT if the timeout was reached without receiving any data sample of the kinds specified in the
data_mask
.ReturnCode::RETURN_CODE_ILLEGAL_OPERATION if there was not open connection.
ReturnCode::RETURN_CODE_ERROR if some other thread called
close()
on theEasyNmea
instance, which unblocks anywait_for_data()
calls.
- Parameters
[in] data_mask
: ANMEA0183DataKindMask
used to specify on which data kinds should the call return, thus unblocking the calling thread. Whenwait_for_data
returns data_mask holds the types of data that have been received. Defaults toNMEA0183DataKindMask::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).