From 5d6ca64f534a26722c365736ff614f217bdf2826 Mon Sep 17 00:00:00 2001 From: klkl Date: Sun, 13 Nov 2022 11:59:56 +0800 Subject: [PATCH 1/4] feat: add BeiDou --- examples/NMEA-Basic/NMEA-Basic.ino | 2 ++ src/nmea/GxGGA.cpp | 2 ++ src/nmea/GxRMC.cpp | 2 ++ src/nmea/Types.h | 2 +- src/nmea/util/gga.cpp | 8 +++++++- src/nmea/util/gga.h | 1 + src/nmea/util/rmc.cpp | 7 ++++++- src/nmea/util/rmc.h | 1 + 8 files changed, 22 insertions(+), 3 deletions(-) diff --git a/examples/NMEA-Basic/NMEA-Basic.ino b/examples/NMEA-Basic/NMEA-Basic.ino index 326c945..51cbca7 100644 --- a/examples/NMEA-Basic/NMEA-Basic.ino +++ b/examples/NMEA-Basic/NMEA-Basic.ino @@ -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::BeiDou) Serial.print("BeiDou"); Serial.print(" "); Serial.print(rmc.time_utc.hour); @@ -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::BeiDou) Serial.print("BeiDou"); Serial.print(" "); Serial.print(gga.time_utc.hour); diff --git a/src/nmea/GxGGA.cpp b/src/nmea/GxGGA.cpp index 5a81be9..2edcdd4 100644 --- a/src/nmea/GxGGA.cpp +++ b/src/nmea/GxGGA.cpp @@ -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::BeiDou; return ParserState::UTCPositionFix; } diff --git a/src/nmea/GxRMC.cpp b/src/nmea/GxRMC.cpp index 4996934..0a201c3 100644 --- a/src/nmea/GxRMC.cpp +++ b/src/nmea/GxRMC.cpp @@ -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::BeiDou; return ParserState::UTCPositionFix; } diff --git a/src/nmea/Types.h b/src/nmea/Types.h index e700e33..c75b981 100644 --- a/src/nmea/Types.h +++ b/src/nmea/Types.h @@ -43,7 +43,7 @@ typedef struct enum class RmcSource { - Unknown, GPS, Galileo, GLONASS, GNSS + Unknown, GPS, Galileo, GLONASS, GNSS, BeiDou }; typedef struct diff --git a/src/nmea/util/gga.cpp b/src/nmea/util/gga.cpp index 8d52d2d..226d366 100644 --- a/src/nmea/util/gga.cpp +++ b/src/nmea/util/gga.cpp @@ -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)); } /************************************************************************************** diff --git a/src/nmea/util/gga.h b/src/nmea/util/gga.h index e73da9c..46a9d14 100644 --- a/src/nmea/util/gga.h +++ b/src/nmea/util/gga.h @@ -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); /************************************************************************************** diff --git a/src/nmea/util/rmc.cpp b/src/nmea/util/rmc.cpp index 9f9fe03..5911c40 100644 --- a/src/nmea/util/rmc.cpp +++ b/src/nmea/util/rmc.cpp @@ -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) diff --git a/src/nmea/util/rmc.h b/src/nmea/util/rmc.h index 86a65e7..d7f747a 100644 --- a/src/nmea/util/rmc.h +++ b/src/nmea/util/rmc.h @@ -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); From bcd9b97fcb865b3dbe06618c2d895f4a9e9e7ecd Mon Sep 17 00:00:00 2001 From: klkl Date: Sun, 20 Nov 2022 11:08:03 +0800 Subject: [PATCH 2/4] fix: BeiDou change to BDS --- examples/NMEA-Basic/NMEA-Basic.ino | 4 ++-- src/nmea/GxGGA.cpp | 2 +- src/nmea/GxRMC.cpp | 2 +- src/nmea/Types.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/NMEA-Basic/NMEA-Basic.ino b/examples/NMEA-Basic/NMEA-Basic.ino index 51cbca7..6ca0435 100644 --- a/examples/NMEA-Basic/NMEA-Basic.ino +++ b/examples/NMEA-Basic/NMEA-Basic.ino @@ -62,7 +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::BeiDou) Serial.print("BeiDou"); + else if (rmc.source == nmea::RmcSource::BDS) Serial.print("BDS"); Serial.print(" "); Serial.print(rmc.time_utc.hour); @@ -97,7 +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::BeiDou) Serial.print("BeiDou"); + else if (gga.source == nmea::GgaSource::BDS) Serial.print("BDS"); Serial.print(" "); Serial.print(gga.time_utc.hour); diff --git a/src/nmea/GxGGA.cpp b/src/nmea/GxGGA.cpp index 2edcdd4..ad6cf41 100644 --- a/src/nmea/GxGGA.cpp +++ b/src/nmea/GxGGA.cpp @@ -88,7 +88,7 @@ GxGGA::ParserState GxGGA::handle_MessageId(char const * token, GgaSource & sourc else if (util::gga_isGNGGA(token)) source = GgaSource::GNSS; else if (util::rmc_isBDGGA(token)) - source = GgaSource::BeiDou; + source = GgaSource::BDS; return ParserState::UTCPositionFix; } diff --git a/src/nmea/GxRMC.cpp b/src/nmea/GxRMC.cpp index 0a201c3..7a06b73 100644 --- a/src/nmea/GxRMC.cpp +++ b/src/nmea/GxRMC.cpp @@ -91,7 +91,7 @@ GxRMC::ParserState GxRMC::handle_MessageId(char const * token, RmcSource & sourc else if (util::rmc_isGNRMC(token)) source = RmcSource::GNSS; else if (util::rmc_isBDRMC(token)) - source = RmcSource::BeiDou; + source = RmcSource::BDS; return ParserState::UTCPositionFix; } diff --git a/src/nmea/Types.h b/src/nmea/Types.h index c75b981..3086137 100644 --- a/src/nmea/Types.h +++ b/src/nmea/Types.h @@ -43,7 +43,7 @@ typedef struct enum class RmcSource { - Unknown, GPS, Galileo, GLONASS, GNSS, BeiDou + Unknown, GPS, Galileo, GLONASS, GNSS, BDS }; typedef struct From 5ab228407ae5441542c54be9472dd1da303f1192 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 21 Nov 2022 07:19:10 +0100 Subject: [PATCH 3/4] Add missing space for aligned format. --- examples/NMEA-Basic/NMEA-Basic.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/NMEA-Basic/NMEA-Basic.ino b/examples/NMEA-Basic/NMEA-Basic.ino index 6ca0435..8d60b2a 100644 --- a/examples/NMEA-Basic/NMEA-Basic.ino +++ b/examples/NMEA-Basic/NMEA-Basic.ino @@ -62,7 +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"); + else if (rmc.source == nmea::RmcSource::BDS) Serial.print("BDS"); Serial.print(" "); Serial.print(rmc.time_utc.hour); @@ -97,7 +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"); + else if (gga.source == nmea::GgaSource::BDS) Serial.print("BDS"); Serial.print(" "); Serial.print(gga.time_utc.hour); From 44f0481e1433ab38f82c3e26c680cb07317232aa Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Mon, 21 Nov 2022 07:25:50 +0100 Subject: [PATCH 4/4] Adding test-statement for BDS RMC string. --- extras/test/src/test_ArduinoNmeaParser.cpp | 30 ++++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/extras/test/src/test_ArduinoNmeaParser.cpp b/extras/test/src/test_ArduinoNmeaParser.cpp index 9074a7c..07ee6e6 100644 --- a/extras/test/src/test_ArduinoNmeaParser.cpp +++ b/extras/test/src/test_ArduinoNmeaParser.cpp @@ -141,9 +141,11 @@ TEST_CASE("Multiple NMEA messages received", "[Parser-06]") { ArduinoNmeaParser parser(nullptr, nullptr); - std::vector const GPRMC = + std::vector 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"), @@ -152,47 +154,47 @@ TEST_CASE("Multiple NMEA messages received", "[Parser-06]") std::vector 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 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 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 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 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 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 const DAY_EXPECTED = { - 8, 8, 8, 8, 12 + 8, 8, 8, 8, 8, 12 }; std::vector const MONTH_EXPECTED = { - 7, 7, 7, 7, 10 + 7, 7, 7, 7, 7, 10 }; std::vector const YEAR_EXPECTED = { - 2020, 2020, 2020, 2020, 2020 + 2020, 2020, 2020, 2020, 2020, 2020 }; @@ -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);