54 const std::string& frame_id,
bool ,
58 const size_t MIN_LENGTH = 4;
60 if (sentence.get_body().size() < MIN_LENGTH)
62 std::stringstream error;
63 error <<
"Expected GSV length is at least " << MIN_LENGTH
64 <<
". The actual length is " << sentence.get_body().size();
69 msg.message_id = sentence.get_body()[0];
77 std::stringstream error;
78 error <<
"n_msgs in GSV is too large: " << msg.n_msgs <<
".";
89 std::stringstream error;
90 error <<
"msg_number in GSV is larger than n_msgs: " << msg.msg_number
91 <<
" > " << msg.n_msgs <<
".";
99 size_t n_sats_in_sentence = 4;
100 if (msg.msg_number == msg.n_msgs)
102 n_sats_in_sentence = msg.n_satellites %
static_cast<uint8_t
>(4);
103 if (msg.n_satellites %
static_cast<uint8_t
>(4) == 0)
105 n_sats_in_sentence = 4;
107 if (msg.n_satellites == 0)
109 n_sats_in_sentence = 0;
111 if (msg.msg_number == 1)
113 n_sats_in_sentence = msg.n_satellites;
117 size_t expected_length = MIN_LENGTH + 4 * n_sats_in_sentence + 1;
120 if (n_sats_in_sentence == 0)
124 expected_length += 4;
131 if (sentence.get_body().size() != expected_length &&
132 sentence.get_body().size() != expected_length - 1)
134 std::stringstream ss;
135 for (
size_t i = 0; i < sentence.get_body().size(); ++i)
137 ss << sentence.get_body()[i];
138 if ((i + 1) < sentence.get_body().size())
143 std::stringstream error;
144 error <<
"Expected GSV length is " << expected_length <<
" for message with "
145 << n_sats_in_sentence <<
" satellites. The actual length is "
146 << sentence.get_body().size() <<
".\n"
152 msg.satellites.resize(n_sats_in_sentence);
153 for (
size_t sat = 0, index = MIN_LENGTH; sat < n_sats_in_sentence;
157 msg.satellites[sat].prn))
159 std::stringstream error;
160 error <<
"Error parsing PRN for satellite " << sat <<
" in GSV.";
167 std::stringstream error;
168 error <<
"Error parsing elevation for satellite " << sat <<
" in GSV.";
171 msg.satellites[sat].elevation =
static_cast<uint8_t
>(elevation);
176 std::stringstream error;
177 error <<
"Error parsing azimuth for satellite " << sat <<
" in GSV.";
180 msg.satellites[sat].azimuth =
static_cast<uint16_t
>(azimuth);
182 if ((index + 3) >= sentence.get_body().size() ||
183 sentence.get_body()[index + 3].empty())
185 msg.satellites[sat].snr = -1;
191 std::stringstream error;
192 error <<
"Error parsing snr for satellite " << sat <<
" in GSV.";
195 msg.satellites[sat].snr =
static_cast<int8_t
>(snr);