Build: add VC++ support
[marnav.git] / examples / read_nmea.cpp
blob8ed3d43ad0a1700cfc59c0ba73262f881da514e5
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>
6 #include <iostream>
8 int main(int, char **)
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")};
16 std::string data;
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
22 // bus at any time.
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";