1 #include <marnav/nmea/rpm.hpp>
2 #include <marnav/nmea/io.hpp>
11 /// Converts data read from the NMEA string to the corresponding
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.
18 static rpm::source_id
source_id_mapping(
19 typename
std::underlying_type
<rpm::source_id
>::type value
)
23 return rpm::source_id::shaft
;
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
)
34 case rpm::source_id::shaft
:
36 case rpm::source_id::engine
:
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
;
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
)
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_
));