2 #include <marnav/io/default_nmea_reader.hpp>
3 #include <marnav/io/default_nmea_serial.hpp>
4 #include <marnav/nmea/nmea.hpp>
5 #include <marnav/nmea/rmc.hpp>
6 #include <marnav/nmea/io.hpp>
7 #include <marnav/utils/unique.hpp>
11 using namespace marnav
;
12 using namespace marnav::io
;
14 // create and open the device for reading.
15 default_nmea_reader reader
{make_default_nmea_serial("/dev/ttyUSB0")};
19 // read and process NMEA sentences, bus synchronization is done automatically.
20 while (reader
.read_sentence(data
)) {
21 // data was successfully read from the NMEA bus, inclusive synchronization
22 // of NMEA sentences. This means it is possible to begin to listen on the
24 auto sentence
= nmea::make_sentence(data
);
26 // do something with the sentence, for example dump the position
27 if (sentence
->id() == nmea::sentence_id::RMC
) {
28 auto rmc
= nmea::sentence_cast
<nmea::rmc
>(sentence
.get());
29 std::cout
<< "latitude : " << nmea::to_string(rmc
->get_latitude()) << "\n";
30 std::cout
<< "longitude: " << nmea::to_string(rmc
->get_longitude()) << "\n";