1 #include <marnav/nmea/tfi.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 tfi::state
state_mapping(typename
std::underlying_type
<tfi::state
>::type value
)
22 return tfi::state::off
;
24 return tfi::state::on
;
26 return tfi::state::no_answer
;
28 throw std::invalid_argument
{"invaild value for conversion to tfi::state"};
32 std::string
to_string(tfi::state value
)
39 case tfi::state::no_answer
:
42 throw std::invalid_argument
{"invaild value for conversion of tfi::state"};
45 constexpr sentence_id
tfi::ID
;
46 constexpr const char * tfi::TAG
;
47 constexpr const int tfi::num_sensors
;
50 : sentence(ID
, TAG
, talker::global_positioning_system
)
52 for (auto & t
: sensors_
)
56 tfi::tfi(talker talk
, fields::const_iterator first
, fields::const_iterator last
)
57 : sentence(ID
, TAG
, talk
)
59 if (std::distance(first
, last
) != 3)
60 throw std::invalid_argument
{"invalid number of fields in tfi"};
62 for (size_t i
= 0; i
< num_sensors
; ++i
)
63 read(*(first
+ i
), sensors_
[i
], state_mapping
);
66 void tfi::check_index(int index
) const
68 if ((index
< 0) || (index
>= num_sensors
)) {
69 throw std::out_of_range
{"sensor index out of range"};
73 tfi::state
tfi::get_sensor(int index
) const
76 return sensors_
[index
];
79 void tfi::set_sensor(int index
, state t
)
85 void tfi::append_data_to(std::string
& s
) const
87 for (auto const & t
: sensors_
)
88 append(s
, to_string(t
));