Dev: improve robustness of CTags.cmake
[marnav.git] / src / marnav / nmea / wcv.cpp
blobcebc5441f817283ca9fc76d961b98a214c40b352
1 #include <marnav/nmea/wcv.hpp>
2 #include <marnav/nmea/io.hpp>
3 #include "checks.hpp"
5 namespace marnav
7 namespace nmea
9 constexpr sentence_id wcv::ID;
10 constexpr const char * wcv::TAG;
12 wcv::wcv()
13 : sentence(ID, TAG, talker::global_positioning_system)
17 wcv::wcv(talker talk, fields::const_iterator first, fields::const_iterator last)
18 : sentence(ID, TAG, talk)
20 if (std::distance(first, last) != 3)
21 throw std::invalid_argument{"invalid number of fields in wcv"};
23 utils::optional<unit::velocity> speed_unit;
25 read(*(first + 0), speed_);
26 read(*(first + 1), speed_unit);
27 read(*(first + 2), waypoint_id_);
29 check_value(speed_unit, {unit::velocity::knot}, "speed unit");
32 void wcv::set_speed(units::velocity t) noexcept
34 speed_ = t.get<units::knots>();
37 utils::optional<units::velocity> wcv::get_speed() const
39 if (!speed_)
40 return {};
41 return {*speed_};
44 void wcv::append_data_to(std::string & s) const
46 append(s, format(speed_, 1));
47 append(s, to_string_if(unit::velocity::knot, speed_));
48 append(s, to_string(waypoint_id_));