NMEA: changed signature of nmea::make_sentence to make it more robust.
[marnav.git] / examples / create_nmea_from_ais.cpp
blob42fbef7b8dab364d314b07888f9fc415ccf4acd6
1 #include <iostream>
2 #include <marnav/ais/message_01.hpp>
3 #include <marnav/ais/ais.hpp>
4 #include <marnav/nmea/vdm.hpp>
6 int main(int, char **)
8 using namespace marnav;
10 // prepare AIS data
11 ais::message_01 pos_report;
12 pos_report.set_sog(82);
13 // ... most data not shown here
15 // create payload
16 auto payload = ais::encode_message(pos_report);
18 // create NMEA sentences
19 for (uint32_t fragment = 0; fragment < payload.size(); ++fragment) {
20 nmea::vdm vdm;
21 vdm.set_n_fragments(payload.size());
22 vdm.set_fragment(fragment + 1);
23 vdm.set_radio_channel(nmea::ais_channel::B);
24 vdm.set_payload(payload[fragment]);
26 // collect, send or do something with the sentence...
27 std::string s = nmea::to_string(vdm);
28 std::cout << s << "\n";