NMEA: detectio of the optional tag block in front of a sentence, ignoring it for...
[marnav.git] / src / marnav / nmea / sfi.cpp
blob7e08e4cfe26cab53834df2319641594403f65ec2
1 #include "sfi.hpp"
2 #include <marnav/nmea/io.hpp>
4 namespace marnav
6 namespace nmea
8 MARNAV_NMEA_DEFINE_SENTENCE_PARSE_FUNC(sfi)
10 constexpr const char * sfi::TAG;
12 sfi::sfi()
13 : sentence(ID, TAG, talker_id::global_positioning_system)
17 sfi::sfi(talker talk, fields::const_iterator first, fields::const_iterator last)
18 : sentence(ID, TAG, talk)
20 const auto size = std::distance(first, last);
21 if ((size < 2) || (size > 2 + max_number_of_frequencies * 2))
22 throw std::invalid_argument{"invalid number of fields in sfi"};
23 if (size % 2 != 0)
24 throw std::invalid_argument{"invalid number of fields in sfi"};
26 read(*(first + 0), number_of_messages);
27 read(*(first + 1), message_number);
29 frequencies.clear();
30 frequencies.reserve(size - 2);
31 for (auto i = 2; i < size; i += 2) {
32 uint32_t frequency;
33 char mode;
34 read(*(first + i + 0), frequency);
35 read(*(first + i + 1), mode);
36 frequencies.push_back({frequency, mode});
40 void sfi::set_frequencies(const std::vector<scanning_frequency> & v)
42 if (v.size() > max_number_of_frequencies)
43 throw std::invalid_argument{
44 "number of frequencies exceeds max entries in sfi::set_frequencies"};
46 frequencies = v;
49 std::vector<std::string> sfi::get_data() const
51 std::vector<std::string> result{to_string(number_of_messages), to_string(message_number)};
53 for (auto const & entry : frequencies) {
54 result.push_back(to_string(entry.frequency));
55 result.push_back(to_string(entry.mode));
58 return result;