Dev: improve robustness of CTags.cmake
[marnav.git] / src / marnav / nmea / rpm.cpp
blob56c16d45ded9b1184b27c73c879381b318cac8b7
1 #include <marnav/nmea/rpm.hpp>
2 #include <marnav/nmea/io.hpp>
3 #include <stdexcept>
5 namespace marnav
7 namespace nmea
9 namespace
11 /// Converts data read from the NMEA string to the corresponding
12 /// enumerator.
13 ///
14 /// @param[in] value The numerical value to convert.
15 /// @return The corresponding enumerator.
16 /// @exception std::invalid_argument The specified value to convert is unknown.
17 ///
18 static rpm::source_id source_id_mapping(
19 typename std::underlying_type<rpm::source_id>::type value)
21 switch (value) {
22 case 'S':
23 return rpm::source_id::shaft;
24 case 'E':
25 return rpm::source_id::engine;
27 throw std::invalid_argument{"invaild value for conversion to rpm::source_id"};
31 std::string to_string(rpm::source_id value)
33 switch (value) {
34 case rpm::source_id::shaft:
35 return "S";
36 case rpm::source_id::engine:
37 return "E";
39 throw std::invalid_argument{"invaild value for conversion of rpm::source_id"};
42 constexpr sentence_id rpm::ID;
43 constexpr const char * rpm::TAG;
45 rpm::rpm()
46 : sentence(ID, TAG, talker::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 void rpm::append_data_to(std::string & s) const
71 append(s, to_string(source_));
72 append(s, to_string(source_number_));
73 append(s, format(revolutions_, 1));
74 append(s, format(propeller_pitch_, 1));
75 append(s, to_string(data_valid_));