NMEA: detectio of the optional tag block in front of a sentence, ignoring it for...
[marnav.git] / src / marnav / nmea / gsa.cpp
blob47a33db53cae68f8b0f1817829a9b4bc170986f5
1 #include "gsa.hpp"
2 #include <limits>
3 #include <marnav/nmea/io.hpp>
5 namespace marnav
7 namespace nmea
9 MARNAV_NMEA_DEFINE_SENTENCE_PARSE_FUNC(gsa)
11 constexpr const char * gsa::TAG;
13 gsa::gsa()
14 : sentence(ID, TAG, talker_id::global_positioning_system)
18 gsa::gsa(talker talk, fields::const_iterator first, fields::const_iterator last)
19 : sentence(ID, TAG, talk)
21 if (std::distance(first, last) != 17)
22 throw std::invalid_argument{"invalid number of fields in gsa"};
24 read(*(first + 0), sel_mode);
25 read(*(first + 1), mode);
27 constexpr uint32_t init_val = std::numeric_limits<uint32_t>::max();
29 int index = 2;
30 for (auto i = 0; i < max_satellite_ids; ++i, ++index) {
31 uint32_t id = init_val;
32 read(*(first + index), id);
33 if (id != init_val)
34 set_satellite_id(i, id);
36 read(*(first + 14), pdop);
37 read(*(first + 15), hdop);
38 read(*(first + 16), vdop);
41 void gsa::check_index(int index) const
43 if ((index < 0) || (index >= max_satellite_ids)) {
44 throw std::out_of_range{"satellite id out of range"};
48 void gsa::set_satellite_id(int index, uint32_t t)
50 check_index(index);
51 satellite_id[index] = t;
54 utils::optional<uint32_t> gsa::get_satellite_id(int index) const
56 check_index(index);
57 return satellite_id[index];
60 std::vector<std::string> gsa::get_data() const
62 return {to_string(sel_mode), to_string(mode), format(satellite_id[0], 2),
63 format(satellite_id[1], 2), format(satellite_id[2], 2), format(satellite_id[3], 2),
64 format(satellite_id[4], 2), format(satellite_id[5], 2), format(satellite_id[6], 2),
65 format(satellite_id[7], 2), format(satellite_id[8], 2), format(satellite_id[9], 2),
66 format(satellite_id[10], 2), format(satellite_id[11], 2), to_string(pdop),
67 to_string(hdop), to_string(vdop)};