UsageΒΆ
EasyNMEA provides the EasyNmea
class, which uses
NMEA 0183 sentences to extract NMEA information from
the NMEA devices.
It provides an easy-to-use API with which applications can open a serial communication channel with the NMEA device,
wait until some data from one or more NMEA 0183
sentences arrives, retrieve it and digest it in an understandable manner, and close the connection.
The following snippet shows how to use EasyNmea::open()
, EasyNmea::wait_for_data()
,
EasyNmea::take_next()
, and EasyNmea::close()
APIs to wait until GPGGAData
data is received,
using a NMEA0183DataKindMask
set to NMEA0183DataKind::GPGGA
. For more information about the supported
NMEA 0183 sentences and their meaning, please refer to
NMEA 0183 Data Types.
using namespace eduponz::easynmea;
// Create an EasyNmea object
EasyNmea easynmea;
// Open the serial port
if (easynmea.open("/dev/ttyACM0", 9600) == ReturnCode::RETURN_CODE_OK)
{
// Create a mask to only wait on data from specific NMEA 0183 sentences
NMEA0183DataKindMask data_kind_mask = NMEA0183DataKind::GPGGA;
// This call will block until some data of any of the kinds specified in the mask is
// available.
while (easynmea.wait_for_data(data_kind_mask) == ReturnCode::RETURN_CODE_OK)
{
// Take all the available data samples of type GPGGA
GPGGAData gpgga_data;
while (easynmea.take_next(gpgga_data) == ReturnCode::RETURN_CODE_OK)
{
// Do something with the GNSS data
std::cout << "GNSS position: (" << gpgga_data.latitude << "; "
<< gpgga_data.longitude << ")" << std::endl;
}
}
}
// Close the serial connection
easynmea.close();