From 87925e4afe6c0fe1d62c07405807f9ba21891a69 Mon Sep 17 00:00:00 2001 From: Bert Wijnants Date: Thu, 4 Feb 2021 22:46:26 +0100 Subject: [PATCH 1/5] #131 Add parse for antenna stats --- src/Adafruit_GPS.cpp | 2 +- src/Adafruit_GPS.h | 14 ++++++++------ src/NMEA_parse.cpp | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/Adafruit_GPS.cpp b/src/Adafruit_GPS.cpp index ff44207..58ff307 100644 --- a/src/Adafruit_GPS.cpp +++ b/src/Adafruit_GPS.cpp @@ -255,7 +255,7 @@ void Adafruit_GPS::common_init(void) { lastline = line2; hour = minute = seconds = year = month = day = fixquality = fixquality_3d = - satellites = 0; // uint8_t + satellites = antenna = 0; // uint8_t lat = lon = mag = 0; // char fix = false; // bool milliseconds = 0; // uint16_t diff --git a/src/Adafruit_GPS.h b/src/Adafruit_GPS.h index bf190b4..987f91b 100644 --- a/src/Adafruit_GPS.h +++ b/src/Adafruit_GPS.h @@ -197,6 +197,7 @@ public: uint8_t fixquality; ///< Fix quality (0, 1, 2 = Invalid, GPS, DGPS) uint8_t fixquality_3d; ///< 3D fix quality (1, 3, 3 = Nofix, 2D fix, 3D fix) uint8_t satellites; ///< Number of satellites in use + uint8_t antenna; ///< Antenna that is used (from PGTOP) uint16_t LOCUS_serial; ///< Log serial number uint16_t LOCUS_records; ///< Log number of data record @@ -245,24 +246,25 @@ private: char *parseStr(char *buff, char *p, int n); bool parseTime(char *); bool parseFix(char *); + bool parseAntenna(char *); bool isEmpty(char *pStart); // used by check() for validity tests, room for future expansion - const char *sources[6] = {"II", "WI", "GP", + const char *sources[7] = {"II", "WI", "GP", "PG", "GN", "P", "ZZZ"}; ///< valid source ids #ifdef NMEA_EXTENSIONS const char - *sentences_parsed[20] = + *sentences_parsed[21] = { "GGA", "GLL", "GSA", "RMC", "DBT", "HDM", "HDT", - "MDA", "MTW", "MWV", "RMB", "TXT", "VHW", "VLW", - "VPW", "VWR", "WCV", "XTE", "ZZZ"}; ///< parseable sentence ids + "MDA", "MTW", "MWV", "RMB", "TOP", "TXT", "VHW", + "VLW", "VPW", "VWR", "WCV", "XTE", "ZZZ"}; ///< parseable sentence ids const char *sentences_known[15] = { "APB", "DPT", "GSV", "HDG", "MWD", "ROT", "RPM", "RSA", "VDR", "VTG", "ZDA", "ZZZ"}; ///< known, but not parseable #else // make the lists short to save memory - const char *sentences_parsed[5] = {"GGA", "GLL", "GSA", "RMC", - "ZZZ"}; ///< parseable sentence ids + const char *sentences_parsed[6] = {"GGA", "GLL", "GSA", "RMC", + "TOP", "ZZZ"}; ///< parseable sentence ids const char *sentences_known[4] = {"DBT", "HDM", "HDT", "ZZZ"}; ///< known, but not parseable #endif diff --git a/src/NMEA_parse.cpp b/src/NMEA_parse.cpp index ddf59eb..cc8e082 100644 --- a/src/NMEA_parse.cpp +++ b/src/NMEA_parse.cpp @@ -173,7 +173,17 @@ bool Adafruit_GPS::parse(char *nmea) { if (!isEmpty(p)) VDOP = atof(p); // last before checksum + } else if (!strcmp(thisSentence, "TOP")) { //*****************************TOP + // See: https://learn.adafruit.com/adafruit-ultimate-gps-featherwing/antenna-options + // There is an output sentence that will tell you the status of the + // antenna. $PGTOP,11,x where x is the status number. If x is 3 that means + // it is using the external antenna. If x is 2 it's using the internal + // antenna and if x is 1 there was an antenna short or problem. + p = strchr(p, ',') + 1; + parseAntenna(p); } + + #ifdef NMEA_EXTENSIONS // Sentences not required for basic GPS functionality else if (!strcmp(thisSentence, "APB")) { //*******************************APB // from Actisense NGW-1 from SH CP150C @@ -815,6 +825,30 @@ bool Adafruit_GPS::parseFix(char *p) { return false; } +/**************************************************************************/ +/*! + @brief Parse a part of an NMEA string for antenna that is used + @param p Pointer to the location of the token in the NMEA string + @return 3: external antenna + 2: internal antenna + 1: there was an antenna short or problem +*/ +/**************************************************************************/ +bool Adafruit_GPS::parseAntenna(char *p) { + if (!isEmpty(p)) { + if (p[0] == '3') { + antenna = 3; + } else if (p[0] == '2') { + antenna = 2; + } else if (p[0] == '1') { + antenna = 1; + } else + return false; + return true; + } + return false; +} + /**************************************************************************/ /*! @brief Is the field empty, or should we try conversion? Won't work From 6abd6f35483f04cc52dcf7d04541ecd2ecc31d6e Mon Sep 17 00:00:00 2001 From: Bert Wijnants Date: Thu, 4 Feb 2021 22:49:50 +0100 Subject: [PATCH 2/5] #131 add antenna status to parsing example --- .../GPS_HardwareSerial_Parsing/GPS_HardwareSerial_Parsing.ino | 1 + .../GPS_SoftwareSerial_Parsing/GPS_SoftwareSerial_Parsing.ino | 1 + 2 files changed, 2 insertions(+) diff --git a/examples/GPS_HardwareSerial_Parsing/GPS_HardwareSerial_Parsing.ino b/examples/GPS_HardwareSerial_Parsing/GPS_HardwareSerial_Parsing.ino index 2d03491..40163d9 100644 --- a/examples/GPS_HardwareSerial_Parsing/GPS_HardwareSerial_Parsing.ino +++ b/examples/GPS_HardwareSerial_Parsing/GPS_HardwareSerial_Parsing.ino @@ -108,6 +108,7 @@ void loop() // run over and over again Serial.print("Angle: "); Serial.println(GPS.angle); Serial.print("Altitude: "); Serial.println(GPS.altitude); Serial.print("Satellites: "); Serial.println((int)GPS.satellites); + Serial.print("Antenna status: "); Serial.println((int)GPS.antenna); } } } diff --git a/examples/GPS_SoftwareSerial_Parsing/GPS_SoftwareSerial_Parsing.ino b/examples/GPS_SoftwareSerial_Parsing/GPS_SoftwareSerial_Parsing.ino index b4ebc85..0c9e991 100644 --- a/examples/GPS_SoftwareSerial_Parsing/GPS_SoftwareSerial_Parsing.ino +++ b/examples/GPS_SoftwareSerial_Parsing/GPS_SoftwareSerial_Parsing.ino @@ -111,6 +111,7 @@ void loop() // run over and over again Serial.print("Angle: "); Serial.println(GPS.angle); Serial.print("Altitude: "); Serial.println(GPS.altitude); Serial.print("Satellites: "); Serial.println((int)GPS.satellites); + Serial.print("Antenna status: "); Serial.println((int)GPS.antenna); } } } From 9714164079c43e4d8072cd2f13969a700eb458bc Mon Sep 17 00:00:00 2001 From: Bert Wijnants Date: Fri, 5 Feb 2021 00:45:56 +0100 Subject: [PATCH 3/5] #131 Try to fix clang formatting --- src/NMEA_parse.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/NMEA_parse.cpp b/src/NMEA_parse.cpp index cc8e082..68a8633 100644 --- a/src/NMEA_parse.cpp +++ b/src/NMEA_parse.cpp @@ -829,9 +829,7 @@ bool Adafruit_GPS::parseFix(char *p) { /*! @brief Parse a part of an NMEA string for antenna that is used @param p Pointer to the location of the token in the NMEA string - @return 3: external antenna - 2: internal antenna - 1: there was an antenna short or problem + @return 3=external 2=internal 1=there was an antenna short or problem */ /**************************************************************************/ bool Adafruit_GPS::parseAntenna(char *p) { From ab1e7d315a011cc177ca79b00440a5173da1b746 Mon Sep 17 00:00:00 2001 From: Bert Wijnants Date: Fri, 5 Feb 2021 01:00:00 +0100 Subject: [PATCH 4/5] #131 More to fix clang formatting --- src/Adafruit_GPS.h | 10 ++++------ src/NMEA_parse.cpp | 11 +++++------ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/Adafruit_GPS.h b/src/Adafruit_GPS.h index 987f91b..080c49d 100644 --- a/src/Adafruit_GPS.h +++ b/src/Adafruit_GPS.h @@ -253,12 +253,10 @@ private: const char *sources[7] = {"II", "WI", "GP", "PG", "GN", "P", "ZZZ"}; ///< valid source ids #ifdef NMEA_EXTENSIONS - const char - *sentences_parsed[21] = - { - "GGA", "GLL", "GSA", "RMC", "DBT", "HDM", "HDT", - "MDA", "MTW", "MWV", "RMB", "TOP", "TXT", "VHW", - "VLW", "VPW", "VWR", "WCV", "XTE", "ZZZ"}; ///< parseable sentence ids + const char *sentences_parsed[21] = {"GGA", "GLL", "GSA", "RMC", "DBT", "HDM", + "HDT", "MDA", "MTW", "MWV", "RMB", "TOP", + "TXT", "VHW", "VLW", "VPW", "VWR", "WCV", + "XTE", "ZZZ"}; ///< parseable sentence ids const char *sentences_known[15] = { "APB", "DPT", "GSV", "HDG", "MWD", "ROT", "RPM", "RSA", "VDR", "VTG", "ZDA", "ZZZ"}; ///< known, but not parseable diff --git a/src/NMEA_parse.cpp b/src/NMEA_parse.cpp index 68a8633..a6d89e7 100644 --- a/src/NMEA_parse.cpp +++ b/src/NMEA_parse.cpp @@ -174,16 +174,15 @@ bool Adafruit_GPS::parse(char *nmea) { VDOP = atof(p); // last before checksum } else if (!strcmp(thisSentence, "TOP")) { //*****************************TOP - // See: https://learn.adafruit.com/adafruit-ultimate-gps-featherwing/antenna-options - // There is an output sentence that will tell you the status of the - // antenna. $PGTOP,11,x where x is the status number. If x is 3 that means - // it is using the external antenna. If x is 2 it's using the internal - // antenna and if x is 1 there was an antenna short or problem. + // See: + // https://learn.adafruit.com/adafruit-ultimate-gps-featherwing/antenna-options + // There is an output sentence that will tell you the status of the + // antenna. $PGTOP,11,x where x is the status number. If x is 3 that means + // it is using the external antenna. If x is 2 it's using the internal p = strchr(p, ',') + 1; parseAntenna(p); } - #ifdef NMEA_EXTENSIONS // Sentences not required for basic GPS functionality else if (!strcmp(thisSentence, "APB")) { //*******************************APB // from Actisense NGW-1 from SH CP150C From 156a6dcb0c98ca1765c04795ee1ec76e555c307a Mon Sep 17 00:00:00 2001 From: Bert Wijnants Date: Fri, 5 Feb 2021 01:02:44 +0100 Subject: [PATCH 5/5] #131 Even more to fix clang formatting --- src/Adafruit_GPS.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Adafruit_GPS.cpp b/src/Adafruit_GPS.cpp index 58ff307..bcf4b98 100644 --- a/src/Adafruit_GPS.cpp +++ b/src/Adafruit_GPS.cpp @@ -255,10 +255,10 @@ void Adafruit_GPS::common_init(void) { lastline = line2; hour = minute = seconds = year = month = day = fixquality = fixquality_3d = - satellites = antenna = 0; // uint8_t - lat = lon = mag = 0; // char - fix = false; // bool - milliseconds = 0; // uint16_t + satellites = antenna = 0; // uint8_t + lat = lon = mag = 0; // char + fix = false; // bool + milliseconds = 0; // uint16_t latitude = longitude = geoidheight = altitude = speed = angle = magvariation = HDOP = VDOP = PDOP = 0.0; // nmea_float_t #ifdef NMEA_EXTENSIONS