General: separation of marav-io as a library
[marnav.git] / src / marnav-io / default_seatalk_reader.cpp
blob2c7e0221cb6cda76424773816b4d06f3dce667dd
1 #include <marnav-io/default_seatalk_reader.hpp>
3 /// @example simple_seatalk_nmea_converter.cpp
4 /// This is a very simplistic conversion from SeaTalk messages to NMEA sentences.
5 ///
6 /// SeaTalk message are being read from a serial port, converted to a corresponding
7 /// NMEA message, which is sent on another serial port.
8 ///
9 /// This example uses the marnav::io::default_seatalk_reader to read SeaTalk
10 /// messages and \c boost.asio to send NMEA sentences.
12 namespace marnav
14 namespace io
16 default_seatalk_reader::default_seatalk_reader(std::unique_ptr<device> && dv)
17 : seatalk_reader(std::move(dv))
18 , message_received_(false)
22 /// Reads synchronously messages from the device.
23 ///
24 /// @param[out] data The received message.
25 /// @retval true Success.
26 /// @retval false End of file.
27 /// @exception std::runtime_error
28 bool default_seatalk_reader::read_message(seatalk::raw & data)
30 // reads as long as the message is not complete.
31 while (read()) {
32 // the message was received, return it and reset the 'semaphore'.
33 // please note: this works only in single threaded environment,
34 // since the 'semaphore' isn't really one.
35 if (message_received_) {
36 data = message_;
37 message_received_ = false;
38 return true;
41 return false;
44 /// Processes the received message. Uses the data member 'message_received'
45 /// as poor-mans semaphore to signal the receipt.
46 ///
47 /// After the reception, the message will be stored temporarily.
48 void default_seatalk_reader::process_message(const seatalk::raw & msg)
50 message_ = msg;
51 message_received_ = true;