NMEA: detectio of the optional tag block in front of a sentence, ignoring it for...
[marnav.git] / src / marnav / nmea / rpm.cpp
blobe0977606484ced78fd67c6e99b9b674ee48e0b3d
1 #include "rpm.hpp"
2 #include <marnav/nmea/io.hpp>
4 namespace marnav
6 namespace nmea
8 MARNAV_NMEA_DEFINE_SENTENCE_PARSE_FUNC(rpm)
10 namespace
12 /// Converts data read from the NMEA string to the corresponding
13 /// enumerator.
14 ///
15 /// @param[in] value The numerical value to convert.
16 /// @return The corresponding enumerator.
17 /// @exception std::invalid_argument The specified value to convert is unknown.
18 ///
19 static rpm::source_id source_id_mapping(
20 typename std::underlying_type<rpm::source_id>::type value)
22 switch (value) {
23 case 'S':
24 return rpm::source_id::shaft;
25 case 'E':
26 return rpm::source_id::engine;
28 throw std::invalid_argument{"invaild value for conversion to rpm::source_id"};
32 std::string to_string(rpm::source_id value)
34 switch (value) {
35 case rpm::source_id::shaft:
36 return "S";
37 case rpm::source_id::engine:
38 return "E";
40 throw std::invalid_argument{"invaild value for conversion of rpm::source_id"};
43 constexpr const char * rpm::TAG;
45 rpm::rpm()
46 : sentence(ID, TAG, talker_id::integrated_instrumentation)
50 rpm::rpm(talker talk, fields::const_iterator first, fields::const_iterator last)
51 : sentence(ID, TAG, talk)
53 if (std::distance(first, last) != 5)
54 throw std::invalid_argument{"invalid number of fields in rpm"};
56 read(*(first + 0), source, source_id_mapping);
57 read(*(first + 1), source_number);
58 read(*(first + 2), revolutions);
59 read(*(first + 3), propeller_pitch);
60 read(*(first + 4), data_valid);
63 void rpm::set_source(source_id id, uint32_t num)
65 source = id;
66 source_number = num;
69 std::vector<std::string> rpm::get_data() const
71 return {to_string(source), to_string(source_number), format(revolutions, 1),
72 format(propeller_pitch, 1), to_string(data_valid)};