Skip to content

Commit 3005b80

Browse files
authored
Handle GPGSV log with 0 satellites correctly (#76)
If a GPGSV log has 0 satellites, it still has enough empty fields in it for 1 satellite. The size of the message was being calculated incorrectly and ended up throwing an error.
1 parent 8fbdbbb commit 3005b80

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

novatel_gps_driver/src/parsers/gpgsv.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,14 @@ novatel_gps_msgs::GpgsvPtr novatel_gps_driver::GpgsvParser::ParseAscii(const nov
8888
{
8989
n_sats_in_sentence = msg->n_satellites % static_cast<uint8_t>(4);
9090
}
91+
// Check that the sentence is the right length for the number of satellites
92+
size_t expected_length = MIN_LENGTH + 4 * n_sats_in_sentence;
9193
if (n_sats_in_sentence == 0)
9294
{
93-
n_sats_in_sentence = 4;
95+
// Even if the number of sats is 0, the message will still have enough
96+
// blank fields for 1 satellite.
97+
expected_length += 4;
9498
}
95-
// Check that the sentence is the right length for the number of satellites
96-
size_t expected_length = MIN_LENGTH + 4 * n_sats_in_sentence;
9799
if (sentence.body.size() != expected_length && sentence.body.size() != expected_length -1)
98100
{
99101
std::stringstream ss;

novatel_gps_driver/test/parser_tests.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,8 @@ TEST(ParserTestSuite, testCorrimudataAsciiParsing)
180180
TEST(ParserTestSuite, testGpgsvParsing)
181181
{
182182
novatel_gps_driver::GpgsvParser parser;
183-
std::string sentence_str = "$GPGSV,3,3,11,12,07,00.,32,13,03,227,36,22,0.,041,*4A\r\n";
183+
std::string sentence_str = "$GPGSV,3,3,11,12,07,00.,32,13,03,227,36,22,0.,041,*4A\r\n"
184+
"$GPGSV,1,1,00,,,,*79\r\n";
184185
std::string extracted_str;
185186

186187
novatel_gps_driver::NovatelMessageExtractor extractor;
@@ -193,7 +194,7 @@ TEST(ParserTestSuite, testGpgsvParsing)
193194
extractor.ExtractCompleteMessages(sentence_str, nmea_sentences, novatel_sentences,
194195
binary_messages, remaining);
195196

196-
ASSERT_EQ(1, nmea_sentences.size());
197+
ASSERT_EQ(2, nmea_sentences.size());
197198
ASSERT_EQ(0, binary_messages.size());
198199
ASSERT_EQ(0, novatel_sentences.size());
199200

@@ -222,6 +223,11 @@ TEST(ParserTestSuite, testGpgsvParsing)
222223
ASSERT_EQ(0, msg->satellites[2].elevation);
223224
ASSERT_EQ(41, msg->satellites[2].azimuth);
224225
ASSERT_EQ(-1, msg->satellites[2].snr);
226+
227+
msg = parser.ParseAscii(nmea_sentences.at(1));
228+
229+
ASSERT_NE(msg.get(), nullptr);
230+
ASSERT_EQ(0, msg->satellites.size());
225231
}
226232

227233
TEST(ParserTestSuite, testGphdtParsing)

0 commit comments

Comments
 (0)