3 \page page_examples Examples
7 \section sec_examples_nmea NMEA-0183
9 \subsection subsec_examples_nmea_parse Parse a NMEA sentence
11 auto sentence = nmea::make_sentence(
12 "$GPRMC,201034,A,4702.4040,N,00818.3281,E,0.0,328.4,260807,0.6,E,A*17");
13 std::cout << sentence->tag() << "\n";
14 auto rmc = nmea::sentence_cast<nmea::rmc>(sentence);
15 std::cout << "latitude : " << nmea::to_string(rmc->get_latitude()) << "\n";
16 std::cout << "longitude: " << nmea::to_string(rmc->get_longitude()) << "\n";
19 Create a specific sentence directly:
22 using namespace marnav;
24 auto rmc = nmea::create_sentence<nmea::rmc>(
25 "$GPRMC,201034,A,4702.4040,N,00818.3281,E,0.0,328.4,260807,0.6,E,A*17");
26 std::cout << "latitude : " << nmea::to_string(rmc.get_latitude()) << "\n";
27 std::cout << "longitude: " << nmea::to_string(rmc.get_longitude()) << "\n";
31 \subsection subsec_examples_nmea_write Write a NMEA sentence
34 mtw.set_temperature(units::celsius{22.5});
35 std::string data = nmea::to_string(mtw);
38 \section sec_examples_ais AIS
40 \subsection subsec_examples_ais_read Process AIS related NMEA messages
43 // collect NMEA data of all fragments, from whatever source
44 std::vector<std::unique_ptr<nmea::sentence>> v;
45 v.push_back(nmea::make_sentence("!AIVDM,1,1,,B,177KQJ5000G?tO`K>RA1wUbN0TKH,0*5C"));
47 // collect payload from all fragments
48 auto payload = nmea::collect_payload(v.begin(), v.end());
50 // make AIS message from payload
51 auto msg = ais::make_message(payload);
53 // process concrete AIS message
54 auto pos_report = ais::message_cast<ais::message_01>(msg);
55 auto mmsi = pos_report->get_mmsi();
60 using namespace marnav;
63 const std::vector<std::string> received_strings
64 = {"!AIVDM,2,1,3,B,55P5TL01VIaAL@7WKO@mBplU@<PDhh000000001S;AJ::4A80?4i@E53,0*3E",
65 "!AIVDM,2,2,3,B,1@0000000000000,2*55"};
67 // parse NMEA sentences
68 std::vector<std::unique_ptr<nmea::sentence>> sentences;
69 for (auto const & txt : received_strings) {
70 auto sentence = nmea::make_sentence(txt);
71 if (sentence->id() == nmea::sentence_id::VDM) {
72 sentences.push_back(std::move(sentence));
76 // parse and and process AIS messags
77 auto payload = nmea::collect_payload(sentences.begin(), sentences.end());
78 auto message = ais::make_message(payload);
79 if (message->type() == ais::message_id::static_and_voyage_related_data) {
80 auto report = ais::message_cast<ais::message_05>(message);
81 std::cout << "shipname: " << report->get_shipname() << "\n";
82 std::cout << "callsign: " << report->get_callsign() << "\n";
86 \subsection subsec_examples_ais_create Create NMEA sentences from AIS data
87 \includelineno examples/create_nmea_from_ais.cpp
89 \subsection subsec_examples_ais_create_2 Create NMEA sentences from AIS data using make_vdms
90 \includelineno examples/create_nmea_from_ais_2.cpp
92 \section sec_examples_utils Utils
94 \subsection subsec_examples_utils_bitset_iterate Iterate through a bitset
95 \includelineno examples/bitset_iterate.cpp
97 \section sec_examples_complete Complete examples
98 All those examples are to be found in the directory `examples`.
100 \subsection subsec_examples_file_parse_nmea Parse NMEA from a string
101 \includelineno examples/parse_nmea.cpp
103 \subsection subsec_examples_file_read_nmea Read NMEA from serial port
104 \includelineno examples/read_nmea.cpp
106 \subsection subsec_examples_file_read_nmea_boostasio Read NMEA from serial port using Boost.ASIO
107 \includelineno examples/read_nmea_boostasio.cpp
109 \subsection subsec_examples_file_read_seatalk Read SeaTalk from serial port
110 \includelineno examples/read_seatalk.cpp
112 \subsection subsec_examples_file_read_ais Read AIS data from string
113 \includelineno examples/read_ais.cpp
115 \subsection subsec_examples_file_nmea_multiplexer Run a NMEA multiplexer
116 \includelineno examples/nmea_multiplexer.cpp
118 \subsection subsec_examples_file_select Using select with marnav::io::device
119 \includelineno examples/select.cpp
121 \subsection subsec_examples_file_seatalk_to_nmea Simple SeaTalk to NMEA converter
122 \includelineno examples/simple_seatalk_nmea_converter.cpp
124 \subsection subsec_examples_file_qt5 Qt5 GUI application reading NMEA
125 \includelineno examples/qtnmeadiag/main.cpp
126 \includelineno examples/qtnmeadiag/MainWindow.hpp
127 \includelineno examples/qtnmeadiag/MainWindow.cpp
129 \subsection subsec_examples_file_tcp_forward Simple NMEA receiver and forward to a TCP server
130 \includelineno examples/serial_to_tcp.cpp