2 #include <boost/asio.hpp>
3 #include <marnav/nmea/nmea.hpp>
4 #include <marnav/nmea/dpt.hpp>
5 #include <marnav/seatalk/seatalk.hpp>
6 #include <marnav/seatalk/message_00.hpp>
7 #include <marnav/io/default_seatalk_reader.hpp>
8 #include <marnav/io/default_seatalk_serial.hpp>
10 using namespace marnav
;
12 namespace marnav_example
14 static std::string
conv_depth_below_transducer(const seatalk::message
& msg
)
16 using namespace marnav::seatalk
;
18 const auto & m
= message_cast
<message_00
>(msg
);
21 dpt
.set_depth_meter(m
.get_depth_meters());
22 dpt
.set_transducer_offset(0.0);
23 return nmea::to_string(dpt
);
27 int main(int, char **)
29 using namespace marnav_example
;
30 using namespace marnav::io
;
32 // mapping of conversion functions
33 static const std::map
<seatalk::message_id
,
34 std::function
<std::string(const seatalk::message
&)>> CONV
36 {seatalk::message_id::depth_below_transducer
, conv_depth_below_transducer
},
40 boost::asio::io_service io
;
41 boost::asio::serial_port serial
{io
, "/dev/ttyUSB1"};
42 serial
.set_option(boost::asio::serial_port_base::baud_rate(4800));
44 // open input port and reader
45 default_seatalk_reader reader
{make_default_seatalk_serial("/dev/ttyUSB0")};
48 while (reader
.read_message(data
)) {
50 auto msg
= seatalk::make_message(data
);
54 // convert message to NMEA sentence, if known
56 auto func
= CONV
.find(msg
->type());
57 if (func
!= CONV
.end())
58 nmea
= func
->second(*msg
);
61 if (nmea
.size() > 0) {
63 boost::asio::write(serial
, boost::asio::buffer(nmea
.c_str(), nmea
.size()));