1 #include <marnav/nmea/nmea.hpp>
2 #include <marnav/nmea/dpt.hpp>
3 #include <marnav/seatalk/seatalk.hpp>
4 #include <marnav/seatalk/message_00.hpp>
5 #include <marnav-io/default_seatalk_reader.hpp>
6 #include <marnav-io/default_seatalk_serial.hpp>
7 #include <boost/asio.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 // TODO: explicit type unnecessary once seatalk is also using units
22 dpt
.set_depth_meter(units::meters
{m
.get_depth_meters()});
23 dpt
.set_transducer_offset(units::meters
{0.0});
24 return nmea::to_string(dpt
);
28 int main(int, char **)
30 using namespace marnav_example
;
31 using namespace marnav::io
;
33 // mapping of conversion functions
34 static const std::map
<seatalk::message_id
,
35 std::function
<std::string(const seatalk::message
&)>>
37 {seatalk::message_id::depth_below_transducer
, conv_depth_below_transducer
},
41 boost::asio::io_service io
;
42 boost::asio::serial_port serial
{io
, "/dev/ttyUSB1"};
43 serial
.set_option(boost::asio::serial_port_base::baud_rate(4800));
45 // open input port and reader
46 default_seatalk_reader reader
{make_default_seatalk_serial("/dev/ttyUSB0")};
49 while (reader
.read_message(data
)) {
51 auto msg
= seatalk::make_message(data
);
55 // convert message to NMEA sentence, if known
57 auto func
= CONV
.find(msg
->type());
58 if (func
!= CONV
.end())
59 nmea
= func
->second(*msg
);
62 if (nmea
.size() > 0) {
64 boost::asio::write(serial
, boost::asio::buffer(nmea
.c_str(), nmea
.size()));