AIS: binary payload 001/11 separated to its own files.
[marnav.git] / examples / read_nmea.cpp
blob7636171fa05d82988fa14d21a68a5951f9eb7e47
1 #include <iostream>
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>
9 int main(int, char **)
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")};
17 std::string data;
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
23 // bus at any time.
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";