1 #include "nmea_reader.hpp"
3 #include <marnav/utils/unique.hpp>
9 nmea_reader::~nmea_reader()
13 /// Initializes the reader, opens the device (if valid).
15 /// @param[in] d The device to read data from, will be opened.
16 nmea_reader::nmea_reader(std::unique_ptr
<device
> && d
)
20 sentence
.reserve(nmea::sentence::max_length
+ 1);
25 void nmea_reader::close()
32 /// Reads data from the device.
34 /// @retval true Success.
35 /// @retval false End of file.
36 /// @exception std::runtime_error The device was invalid or read error.
37 bool nmea_reader::read_data()
40 throw std::runtime_error
{"device invalid"};
41 int rc
= dev
->read(&raw
, sizeof(raw
));
45 throw std::runtime_error
{"read error"};
46 if (rc
!= sizeof(raw
))
47 throw std::runtime_error
{"read error"};
51 /// Processes the data read from the device.
53 /// @exception std::length_error Too many characters read for the sentence.
54 /// Maybe the end of line was missed or left out.
55 void nmea_reader::process_nmea()
60 case '\n': // end of sentence
61 process_sentence(sentence
);
65 // ignore invalid characters. if this makes the sentence incomplete,
66 // the sentence would have been invalid anyway. the result will be
67 // an invalid sentence or a std::length_error.
68 if ((raw
<= 32) || (raw
>= 127))
71 if (sentence
.size() > nmea::sentence::max_length
)
72 throw std::length_error
{"sentence size to large. receiving NMEA data?"};
78 /// Reads data from the device and processes it. If a complete NMEA
79 /// sentence was received the method process_message will be executed.
80 /// This method automatcially synchronizes with NMEA data.
82 /// @retval true Success.
83 /// @retval false End of file.
84 /// @exception std::runtime_error Device or processing error.
85 /// @exception std::length_error Synchronization issue.
86 bool nmea_reader::read()