Skip to content
This repository has been archived by the owner on May 26, 2024. It is now read-only.

Add support for BDS NMEA messages #58

Merged
merged 4 commits into from
Nov 21, 2022
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
2 changes: 2 additions & 0 deletions examples/NMEA-Basic/NMEA-Basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void onRmcUpdate(nmea::RmcData const rmc)
else if (rmc.source == nmea::RmcSource::GLONASS) Serial.print("GLONASS");
else if (rmc.source == nmea::RmcSource::Galileo) Serial.print("Galileo");
else if (rmc.source == nmea::RmcSource::GNSS) Serial.print("GNSS");
else if (rmc.source == nmea::RmcSource::BDS) Serial.print("BDS");

Serial.print(" ");
Serial.print(rmc.time_utc.hour);
Expand Down Expand Up @@ -96,6 +97,7 @@ void onGgaUpdate(nmea::GgaData const gga)
else if (gga.source == nmea::GgaSource::GLONASS) Serial.print("GLONASS");
else if (gga.source == nmea::GgaSource::Galileo) Serial.print("Galileo");
else if (gga.source == nmea::GgaSource::GNSS) Serial.print("GNSS");
else if (gga.source == nmea::GgaSource::BDS) Serial.print("BDS");

Serial.print(" ");
Serial.print(gga.time_utc.hour);
Expand Down
30 changes: 16 additions & 14 deletions extras/test/src/test_ArduinoNmeaParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@ TEST_CASE("Multiple NMEA messages received", "[Parser-06]")
{
ArduinoNmeaParser parser(nullptr, nullptr);

std::vector<std::string> const GPRMC =
std::vector<std::string> const NMEA_RMC =
{
std::string("$GPRMC,052852.105,A,5230.868,N,01320.958,E,077.0,023.5,080720,000.0,W*79\r\n"),
std::string("$BDRMC,052852.105,A,5230.868,N,01320.958,E,077.0,023.5,080720,000.0,W*68\r\n"),

std::string("$GPRMC,052853.105,A,5230.888,N,01320.967,E,084.5,069.2,080720,000.0,W*7A\r\n"),
std::string("$GPRMC,052854.105,A,5230.901,N,01321.000,E,085.8,099.8,080720,000.0,W*7D\r\n"),
std::string("$GPRMC,052855.105,A,5230.894,N,01321.038,E,084.3,138.7,080720,000.0,W*75\r\n"),
Expand All @@ -152,47 +154,47 @@ TEST_CASE("Multiple NMEA messages received", "[Parser-06]")

std::vector<nmea::RmcSource> const SOURCE_EXPECTED =
{
nmea::RmcSource::GPS, nmea::RmcSource::GPS, nmea::RmcSource::GPS, nmea::RmcSource::GPS, nmea::RmcSource::GPS
nmea::RmcSource::GPS, nmea::RmcSource::BDS, nmea::RmcSource::GPS, nmea::RmcSource::GPS, nmea::RmcSource::GPS, nmea::RmcSource::GPS
};

std::vector<float> const LATITUDE_EXPECTED =
{
52.514467f, 52.514800f, 52.515017f, 52.514900f, 48.633246f
52.514467f, 52.514467f, 52.514800f, 52.515017f, 52.514900f, 48.633246f
};

std::vector<float> const LONGITUDE_EXPECTED =
{
13.349300, 13.349450, 13.350000, 13.350633f, 13.025575f
13.349300, 13.349300, 13.349450, 13.350000, 13.350633f, 13.025575f
};

std::vector<float> const SPEED_EXPECTED =
{
39.6122f, 43.47056f, 44.139333f, 43.36767f, 14.363289f
39.6122f, 39.6122f, 43.47056f, 44.139333f, 43.36767f, 14.363289f
};

std::vector<float> const COURSE_EXPECTED =
{
23.5f, 69.2f, 99.8f, 138.7f, 247.03f
23.5f, 23.5f, 69.2f, 99.8f, 138.7f, 247.03f
};

std::vector<float> const MAGNETIC_VARIATION_EXPECTED =
{
0.0f, 0.0f, 0.0f, 0.0f, NAN
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, NAN
};

std::vector<int> const DAY_EXPECTED =
{
8, 8, 8, 8, 12
8, 8, 8, 8, 8, 12
};

std::vector<int> const MONTH_EXPECTED =
{
7, 7, 7, 7, 10
7, 7, 7, 7, 7, 10
};

std::vector<int> const YEAR_EXPECTED =
{
2020, 2020, 2020, 2020, 2020
2020, 2020, 2020, 2020, 2020, 2020
};


Expand All @@ -206,11 +208,11 @@ TEST_CASE("Multiple NMEA messages received", "[Parser-06]")
auto month = MONTH_EXPECTED.begin();
auto year = YEAR_EXPECTED.begin();

std::for_each(std::begin(GPRMC),
std::end(GPRMC),
[&](std::string const & gprmc)
std::for_each(std::begin(NMEA_RMC),
std::end(NMEA_RMC),
[&](std::string const & rmc)
{
encode(parser, gprmc);
encode(parser, rmc);

REQUIRE(parser.error() == ArduinoNmeaParser::Error::None);
REQUIRE(parser.rmc().source == *source);
Expand Down
2 changes: 2 additions & 0 deletions src/nmea/GxGGA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ GxGGA::ParserState GxGGA::handle_MessageId(char const * token, GgaSource & sourc
source = GgaSource::Galileo;
else if (util::gga_isGNGGA(token))
source = GgaSource::GNSS;
else if (util::rmc_isBDGGA(token))
source = GgaSource::BDS;

return ParserState::UTCPositionFix;
}
Expand Down
2 changes: 2 additions & 0 deletions src/nmea/GxRMC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ GxRMC::ParserState GxRMC::handle_MessageId(char const * token, RmcSource & sourc
source = RmcSource::Galileo;
else if (util::rmc_isGNRMC(token))
source = RmcSource::GNSS;
else if (util::rmc_isBDRMC(token))
source = RmcSource::BDS;

return ParserState::UTCPositionFix;
}
Expand Down
2 changes: 1 addition & 1 deletion src/nmea/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ typedef struct

enum class RmcSource
{
Unknown, GPS, Galileo, GLONASS, GNSS
Unknown, GPS, Galileo, GLONASS, GNSS, BDS
};

typedef struct
Expand Down
8 changes: 7 additions & 1 deletion src/nmea/util/gga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,15 @@ bool gga_isGNGGA(char const * nmea)
return (strncmp(nmea, "$GNGGA", 6) == 0);
}

bool rmc_isBDGGA(char const * nmea)
{
return (strncmp(nmea, "$BDGGA", 6) == 0);
}


bool gga_isGxGGA(char const * nmea)
{
return (gga_isGPGGA(nmea) || gga_isGLGGA(nmea) || gga_isGAGGA(nmea) || gga_isGNGGA(nmea));
return (gga_isGPGGA(nmea) || gga_isGLGGA(nmea) || gga_isGAGGA(nmea) || gga_isGNGGA(nmea) || rmc_isBDGGA(nmea));
}

/**************************************************************************************
Expand Down
1 change: 1 addition & 0 deletions src/nmea/util/gga.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ bool gga_isGPGGA(char const * nmea);
bool gga_isGLGGA(char const * nmea);
bool gga_isGAGGA(char const * nmea);
bool gga_isGNGGA(char const * nmea);
bool rmc_isBDGGA(char const * nmea);
bool gga_isGxGGA(char const * nmea);

/**************************************************************************************
Expand Down
7 changes: 6 additions & 1 deletion src/nmea/util/rmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ bool rmc_isGNRMC(char const * nmea)
return (strncmp(nmea, "$GNRMC", 6) == 0);
}

bool rmc_isBDRMC(char const * nmea)
{
return (strncmp(nmea, "$BDRMC", 6) == 0);
}

bool rmc_isGxRMC(char const * nmea)
{
return (rmc_isGPRMC(nmea) || rmc_isGLRMC(nmea) || rmc_isGARMC(nmea) || rmc_isGNRMC(nmea));
return (rmc_isGPRMC(nmea) || rmc_isGLRMC(nmea) || rmc_isGARMC(nmea) || rmc_isGNRMC(nmea) || rmc_isBDRMC(nmea));
}

void rmc_parseDate(char const * token, Date & date)
Expand Down
1 change: 1 addition & 0 deletions src/nmea/util/rmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ bool rmc_isGPRMC (char const * nmea);
bool rmc_isGLRMC (char const * nmea);
bool rmc_isGARMC (char const * nmea);
bool rmc_isGNRMC (char const * nmea);
bool rmc_isBDRMC (char const * nmea);
bool rmc_isGxRMC (char const * nmea);
void rmc_parseDate (char const * token, Date & date);

Expand Down