NMEA: Qt example extended.
[marnav.git] / src / marnav / nmea / rte.cpp
blob46a920fe03c44f8318f8d270312808e47d873f53
1 #include "rte.hpp"
2 #include <marnav/nmea/io.hpp>
4 namespace marnav
6 namespace nmea
8 MARNAV_NMEA_DEFINE_SENTENCE_PARSE_FUNC(rte)
10 constexpr const char * rte::TAG;
12 rte::rte()
13 : sentence(ID, TAG, talker_id::global_positioning_system)
17 rte::rte(const std::string & talker, fields::const_iterator first, fields::const_iterator last)
18 : sentence(ID, TAG, talker)
20 const auto size = std::distance(first, last);
21 if ((size < 3) || (size > max_waypoints + 3))
22 throw std::invalid_argument{"invalid number of fields in rte"};
24 read(*(first + 0), n_messages);
25 read(*(first + 1), message_number);
26 read(*(first + 2), message_mode);
28 for (auto i = 3; i < (max_waypoints + 3) && i < size; ++i) {
29 read(*(first + i), waypoint_id[i - 3]);
33 utils::optional<waypoint> rte::get_waypoint_id(int index) const
35 if ((index < 0) || (index >= max_waypoints))
36 throw std::out_of_range{"get_waypoint_id"};
38 return waypoint_id[index];
41 void rte::set_waypoint_id(int index, const waypoint & id)
43 if ((index < 0) || (index >= max_waypoints))
44 throw std::out_of_range{"set_waypoint_id"};
46 if (id.size() > 8)
47 throw std::invalid_argument{"string size to large, only 8 characters allowed for id"};
49 waypoint_id[index] = id;
52 std::vector<std::string> rte::get_data() const
54 std::vector<std::string> v{
55 to_string(n_messages), to_string(message_number), to_string(message_mode)};
57 if (n_messages) {
58 const auto n = n_messages.value();
59 for (uint32_t i = 0; i < n && waypoint_id[i]; ++i) {
60 v.push_back(waypoint_id[i].value());
64 return v;