1 /// This example demonstrates how to do a very basic NMEA multiplexer.
2 /// It does not implement any error handling and other (normally necessary)
3 /// stuff (configurability, error handling, etc.).
6 #include <marnav/nmea/nmea.hpp>
7 #include <marnav/nmea/checksum.hpp>
8 #include <marnav/io/default_nmea_reader.hpp>
9 #include <marnav/io/serial.hpp>
10 #include <marnav/utils/unique.hpp>
12 int main(int, char **)
14 using namespace marnav
;
15 using namespace marnav::io
;
17 // prepare destinations
18 std::vector
<std::unique_ptr
<serial
>> destinations
;
19 destinations
.push_back(utils::make_unique
<serial
>("dev/ttyUSB1", serial::baud::baud_4800
,
20 serial::databits::bit_8
, serial::stopbits::bit_1
, serial::parity::none
));
21 destinations
.push_back(utils::make_unique
<serial
>("dev/ttyUSB2", serial::baud::baud_4800
,
22 serial::databits::bit_8
, serial::stopbits::bit_1
, serial::parity::none
));
25 default_nmea_reader source
{
26 utils::make_unique
<serial
>("/dev/ttyUSB0", serial::baud::baud_4800
,
27 serial::databits::bit_8
, serial::stopbits::bit_1
, serial::parity::none
)};
30 while (source
.read_sentence(data
)) {
32 // this is used only to check the received data, e.g. if the checksum is correct.
33 auto sentence
= nmea::make_sentence(data
);
35 // send valid NMEA sentences to destinations
36 for (auto & destination
: destinations
) {
37 destination
->write(data
.c_str(), data
.size());
39 } catch (nmea::checksum_error
) {
40 // let's just ignore them