NMEA: changed type of talker id from 'std::string' to its own type.
[marnav.git] / src / marnav / nmea / glc.cpp
blob6459706ac4e54bff231a301cbaaf26490cd38faa
1 #include "glc.hpp"
2 #include <marnav/nmea/io.hpp>
4 namespace marnav
6 namespace nmea
8 MARNAV_NMEA_DEFINE_SENTENCE_PARSE_FUNC(glc)
10 constexpr const char * glc::TAG;
12 glc::glc()
13 : sentence(ID, TAG, talker_id::global_positioning_system)
14 , master({0, nmea::status::warning})
18 glc::glc(talker talk, fields::const_iterator first, fields::const_iterator last)
19 : sentence(ID, TAG, talk)
21 if (std::distance(first, last) != 13)
22 throw std::invalid_argument{"invalid number of fields in glc"};
24 read(*(first + 0), gri);
25 read(*(first + 1), master.diff);
26 read(*(first + 2), master.status);
27 for (int i = 0; i < max_differences; ++i) {
28 utils::optional<double> diff;
29 utils::optional<nmea::status> status;
30 read(*(first + (i * 2) + 3 + 0), diff);
31 read(*(first + (i * 2) + 3 + 1), status);
32 if (diff && status) {
33 time_diffs[i] = utils::make_optional<time_difference>(*diff, *status);
38 void glc::check_index(int index) const
40 if ((index < 0) || (index >= max_differences)) {
41 throw std::out_of_range{"time difference index out of range"};
45 utils::optional<glc::time_difference> glc::get_time_diff(int index) const
47 check_index(index);
48 return time_diffs[index];
51 void glc::set_time_diff(int index, time_difference t)
53 check_index(index);
54 time_diffs[index] = t;
57 std::vector<std::string> glc::get_data() const
59 std::vector<std::string> result;
60 result.reserve(13);
61 result.push_back(to_string(gri));
62 result.push_back(to_string(master.diff));
63 result.push_back(to_string(master.status));
64 for (int i = 0; i < max_differences; ++i) {
65 auto const & t = time_diffs[i];
66 if (t) {
67 result.push_back(to_string(t->diff));
68 result.push_back(to_string(t->status));
69 } else {
70 result.push_back("");
71 result.push_back("");
74 return result;