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