Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle GPGSV log with 0 satellites correctly (ROS2) #77

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions novatel_gps_driver/src/parsers/gpgsv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ novatel_gps_driver::GpgsvParser::MessageType novatel_gps_driver::GpgsvParser::Pa
{
n_sats_in_sentence = msg->n_satellites % static_cast<uint8_t>(4);
}
// Check that the sentence is the right length for the number of satellites
size_t expected_length = MIN_LENGTH + 4 * n_sats_in_sentence;
if (n_sats_in_sentence == 0)
{
n_sats_in_sentence = 4;
// Even if the number of sats is 0, the message will still have enough
// blank fields for 1 satellite.
expected_length += 4;
}
// Check that the sentence is the right length for the number of satellites
size_t expected_length = MIN_LENGTH + 4 * n_sats_in_sentence;
if (sentence.body.size() != expected_length && sentence.body.size() != expected_length -1)
{
std::stringstream ss;
Expand Down
10 changes: 8 additions & 2 deletions novatel_gps_driver/test/parser_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ TEST(ParserTestSuite, testCorrimudataAsciiParsing)
TEST(ParserTestSuite, testGpgsvParsing)
{
novatel_gps_driver::GpgsvParser parser;
std::string sentence_str = "$GPGSV,3,3,11,12,07,00.,32,13,03,227,36,22,0.,041,*4A\r\n";
std::string sentence_str = "$GPGSV,3,3,11,12,07,00.,32,13,03,227,36,22,0.,041,*4A\r\n"
"$GPGSV,1,1,00,,,,*79\r\n";
std::string extracted_str;

novatel_gps_driver::NovatelMessageExtractor extractor(logger);
Expand All @@ -197,7 +198,7 @@ TEST(ParserTestSuite, testGpgsvParsing)
extractor.ExtractCompleteMessages(sentence_str, nmea_sentences, novatel_sentences,
binary_messages, remaining);

ASSERT_EQ(1, nmea_sentences.size());
ASSERT_EQ(2, nmea_sentences.size());
ASSERT_EQ(0, binary_messages.size());
ASSERT_EQ(0, novatel_sentences.size());

Expand Down Expand Up @@ -226,6 +227,11 @@ TEST(ParserTestSuite, testGpgsvParsing)
ASSERT_EQ(0, msg->satellites[2].elevation);
ASSERT_EQ(41, msg->satellites[2].azimuth);
ASSERT_EQ(-1, msg->satellites[2].snr);

msg = parser.ParseAscii(nmea_sentences.at(1));

ASSERT_NE(msg.get(), nullptr);
ASSERT_EQ(0, msg->satellites.size());
}

TEST(ParserTestSuite, testGphdtParsing)
Expand Down