From 7d889e3a9d966b2158f8150fdc83503a890fbaba Mon Sep 17 00:00:00 2001 From: Rick Sellens Date: Wed, 29 Jan 2020 12:03:25 -0500 Subject: [PATCH] Reorder and document Align the order in the .h with the order in the various .cpp Note that ! is also a valid starting character for an NMEA sentence. --- src/Adafruit_GPS.cpp | 318 +++++++++++++++++++++---------------------- src/Adafruit_GPS.h | 41 +++--- 2 files changed, 176 insertions(+), 183 deletions(-) diff --git a/src/Adafruit_GPS.cpp b/src/Adafruit_GPS.cpp index e8aad41..65e5c10 100644 --- a/src/Adafruit_GPS.cpp +++ b/src/Adafruit_GPS.cpp @@ -140,44 +140,144 @@ static bool strStartsWith(const char *str, const char *prefix); /**************************************************************************/ /*! - @brief Time in seconds since the last position fix was obtained. Will - fail by rolling over to zero after one millis() cycle, about 6-1/2 weeks. - @return nmea_float_t value in seconds since last fix. + @brief Start the HW or SW serial port + @param baud_or_i2caddr Baud rate if using serial, I2C address if using I2C + @returns True on successful hardware init, False on failure */ /**************************************************************************/ -nmea_float_t Adafruit_GPS::secondsSinceFix() { - return (millis() - lastFix) / 1000.; +bool Adafruit_GPS::begin(uint32_t baud_or_i2caddr) { +#if (defined(__AVR__) || defined(ESP8266)) && defined(USE_SW_SERIAL) + if (gpsSwSerial) { + gpsSwSerial->begin(baud_or_i2caddr); + } +#endif + if (gpsHwSerial) { + gpsHwSerial->begin(baud_or_i2caddr); + } + if (gpsI2C) { + gpsI2C->begin(); + if (baud_or_i2caddr > 0x7F) { + _i2caddr = GPS_DEFAULT_I2C_ADDR; + } else { + _i2caddr = baud_or_i2caddr; + } + // A basic scanner, see if it ACK's + gpsI2C->beginTransmission(_i2caddr); + return (gpsI2C->endTransmission() == 0); + } + if (gpsSPI) { + gpsSPI->begin(); + gpsSPI_settings = SPISettings(baud_or_i2caddr, MSBFIRST, SPI_MODE0); + if (gpsSPI_cs >= 0) { + pinMode(gpsSPI_cs, OUTPUT); + digitalWrite(gpsSPI_cs, HIGH); + } + } + + delay(10); + return true; } /**************************************************************************/ /*! - @brief Time in seconds since the last GPS time was obtained. Will fail - by rolling over to zero after one millis() cycle, about 6-1/2 weeks. - @return nmea_float_t value in seconds since last GPS time. + @brief Constructor when using SoftwareSerial + @param ser Pointer to SoftwareSerial device */ /**************************************************************************/ -nmea_float_t Adafruit_GPS::secondsSinceTime() { - return (millis() - lastTime) / 1000.; +#if (defined(__AVR__) || defined(ESP8266)) && defined(USE_SW_SERIAL) +Adafruit_GPS::Adafruit_GPS(SoftwareSerial *ser) { + common_init(); // Set everything to common state, then... + gpsSwSerial = ser; // ...override gpsSwSerial with value passed. +} +#endif + +/**************************************************************************/ +/*! + @brief Constructor when using HardwareSerial + @param ser Pointer to a HardwareSerial object +*/ +/**************************************************************************/ +Adafruit_GPS::Adafruit_GPS(HardwareSerial *ser) { + common_init(); // Set everything to common state, then... + gpsHwSerial = ser; // ...override gpsHwSerial with value passed. } /**************************************************************************/ /*! - @brief Time in seconds since the last GPS date was obtained. Will fail - by rolling over to zero after one millis() cycle, about 6-1/2 weeks. - @return nmea_float_t value in seconds since last GPS date. + @brief Constructor when using I2C + @param theWire Pointer to an I2C TwoWire object */ /**************************************************************************/ -nmea_float_t Adafruit_GPS::secondsSinceDate() { - return (millis() - lastDate) / 1000.; +Adafruit_GPS::Adafruit_GPS(TwoWire *theWire) { + common_init(); // Set everything to common state, then... + gpsI2C = theWire; // ...override gpsI2C } /**************************************************************************/ /*! - @brief Fakes time of receipt of a sentence. Use between build() and parse() - to make the timing look like the sentence arrived from the GPS. + @brief Constructor when using SPI + @param theSPI Pointer to an SPI device object + @param cspin The pin connected to the GPS CS, can be -1 if unused */ /**************************************************************************/ -void Adafruit_GPS::resetSentTime() { sentTime = millis(); } +Adafruit_GPS::Adafruit_GPS(SPIClass *theSPI, int8_t cspin) { + common_init(); // Set everything to common state, then... + gpsSPI = theSPI; // ...override gpsSPI + gpsSPI_cs = cspin; +} + +/**************************************************************************/ +/*! + @brief Constructor when there are no communications attached +*/ +/**************************************************************************/ +Adafruit_GPS::Adafruit_GPS() { + common_init(); // Set everything to common state, then... + noComms = true; +} + +/**************************************************************************/ +/*! + @brief Initialization code used by all constructor types +*/ +/**************************************************************************/ +void Adafruit_GPS::common_init(void) { +#if (defined(__AVR__) || defined(ESP8266)) && defined(USE_SW_SERIAL) + gpsSwSerial = NULL; // Set both to NULL, then override correct +#endif + gpsHwSerial = NULL; // port pointer in corresponding constructor + gpsI2C = NULL; + gpsSPI = NULL; + recvdflag = false; + paused = false; + lineidx = 0; + currentline = line1; + lastline = line2; + + hour = minute = seconds = year = month = day = fixquality = fixquality_3d = + satellites = 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 + data_init(); +#endif +} + +/**************************************************************************/ +/*! + @brief Destroy the object. + @return none +*/ +/**************************************************************************/ +Adafruit_GPS::~Adafruit_GPS() { +#ifdef NMEA_EXTENSIONS + for (int i = 0; i < (int)NMEA_MAX_INDEX; i++) + removeHistory((nmea_index_t)i); // to free any history mallocs +#endif +} /**************************************************************************/ /*! @@ -354,147 +454,6 @@ char Adafruit_GPS::read(void) { return c; } -/**************************************************************************/ -/*! - @brief Constructor when using SoftwareSerial - @param ser Pointer to SoftwareSerial device -*/ -/**************************************************************************/ -#if (defined(__AVR__) || defined(ESP8266)) && defined(USE_SW_SERIAL) -Adafruit_GPS::Adafruit_GPS(SoftwareSerial *ser) { - common_init(); // Set everything to common state, then... - gpsSwSerial = ser; // ...override gpsSwSerial with value passed. -} -#endif - -/**************************************************************************/ -/*! - @brief Constructor when using HardwareSerial - @param ser Pointer to a HardwareSerial object -*/ -/**************************************************************************/ -Adafruit_GPS::Adafruit_GPS(HardwareSerial *ser) { - common_init(); // Set everything to common state, then... - gpsHwSerial = ser; // ...override gpsHwSerial with value passed. -} - -/**************************************************************************/ -/*! - @brief Constructor when using I2C - @param theWire Pointer to an I2C TwoWire object -*/ -/**************************************************************************/ -Adafruit_GPS::Adafruit_GPS(TwoWire *theWire) { - common_init(); // Set everything to common state, then... - gpsI2C = theWire; // ...override gpsI2C -} - -/**************************************************************************/ -/*! - @brief Constructor when using SPI - @param theSPI Pointer to an SPI device object - @param cspin The pin connected to the GPS CS, can be -1 if unused -*/ -/**************************************************************************/ -Adafruit_GPS::Adafruit_GPS(SPIClass *theSPI, int8_t cspin) { - common_init(); // Set everything to common state, then... - gpsSPI = theSPI; // ...override gpsSPI - gpsSPI_cs = cspin; -} - -/**************************************************************************/ -/*! - @brief Constructor when there are no communications attached -*/ -/**************************************************************************/ -Adafruit_GPS::Adafruit_GPS() { - common_init(); // Set everything to common state, then... - noComms = true; -} - -/**************************************************************************/ -/*! - @brief Initialization code used by all constructor types -*/ -/**************************************************************************/ -void Adafruit_GPS::common_init(void) { -#if (defined(__AVR__) || defined(ESP8266)) && defined(USE_SW_SERIAL) - gpsSwSerial = NULL; // Set both to NULL, then override correct -#endif - gpsHwSerial = NULL; // port pointer in corresponding constructor - gpsI2C = NULL; - gpsSPI = NULL; - recvdflag = false; - paused = false; - lineidx = 0; - currentline = line1; - lastline = line2; - - hour = minute = seconds = year = month = day = fixquality = fixquality_3d = - satellites = 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 - data_init(); -#endif -} - -/**************************************************************************/ -/*! - @brief Destroy the object. - @return none -*/ -/**************************************************************************/ -Adafruit_GPS::~Adafruit_GPS() { -#ifdef NMEA_EXTENSIONS - for (int i = 0; i < (int)NMEA_MAX_INDEX; i++) - removeHistory((nmea_index_t)i); // to free any history mallocs -#endif -} - -/**************************************************************************/ -/*! - @brief Start the HW or SW serial port - @param baud_or_i2caddr Baud rate if using serial, I2C address if using I2C - @returns True on successful hardware init, False on failure -*/ -/**************************************************************************/ -bool Adafruit_GPS::begin(uint32_t baud_or_i2caddr) { -#if (defined(__AVR__) || defined(ESP8266)) && defined(USE_SW_SERIAL) - if (gpsSwSerial) { - gpsSwSerial->begin(baud_or_i2caddr); - } -#endif - if (gpsHwSerial) { - gpsHwSerial->begin(baud_or_i2caddr); - } - if (gpsI2C) { - gpsI2C->begin(); - if (baud_or_i2caddr > 0x7F) { - _i2caddr = GPS_DEFAULT_I2C_ADDR; - } else { - _i2caddr = baud_or_i2caddr; - } - // A basic scanner, see if it ACK's - gpsI2C->beginTransmission(_i2caddr); - return (gpsI2C->endTransmission() == 0); - } - if (gpsSPI) { - gpsSPI->begin(); - gpsSPI_settings = SPISettings(baud_or_i2caddr, MSBFIRST, SPI_MODE0); - if (gpsSPI_cs >= 0) { - pinMode(gpsSPI_cs, OUTPUT); - digitalWrite(gpsSPI_cs, HIGH); - } - } - - delay(10); - return true; -} - /**************************************************************************/ /*! @brief Send a command to the GPS device @@ -670,6 +629,47 @@ bool Adafruit_GPS::wakeup(void) { } } +/**************************************************************************/ +/*! + @brief Time in seconds since the last position fix was obtained. Will + fail by rolling over to zero after one millis() cycle, about 6-1/2 weeks. + @return nmea_float_t value in seconds since last fix. +*/ +/**************************************************************************/ +nmea_float_t Adafruit_GPS::secondsSinceFix() { + return (millis() - lastFix) / 1000.; +} + +/**************************************************************************/ +/*! + @brief Time in seconds since the last GPS time was obtained. Will fail + by rolling over to zero after one millis() cycle, about 6-1/2 weeks. + @return nmea_float_t value in seconds since last GPS time. +*/ +/**************************************************************************/ +nmea_float_t Adafruit_GPS::secondsSinceTime() { + return (millis() - lastTime) / 1000.; +} + +/**************************************************************************/ +/*! + @brief Time in seconds since the last GPS date was obtained. Will fail + by rolling over to zero after one millis() cycle, about 6-1/2 weeks. + @return nmea_float_t value in seconds since last GPS date. +*/ +/**************************************************************************/ +nmea_float_t Adafruit_GPS::secondsSinceDate() { + return (millis() - lastDate) / 1000.; +} + +/**************************************************************************/ +/*! + @brief Fakes time of receipt of a sentence. Use between build() and parse() + to make the timing look like the sentence arrived from the GPS. +*/ +/**************************************************************************/ +void Adafruit_GPS::resetSentTime() { sentTime = millis(); } + /**************************************************************************/ /*! @brief Checks whether a string starts with a specified prefix diff --git a/src/Adafruit_GPS.h b/src/Adafruit_GPS.h index a0c0dea..730fc26 100644 --- a/src/Adafruit_GPS.h +++ b/src/Adafruit_GPS.h @@ -21,8 +21,6 @@ */ /**************************************************************************/ -// Fllybob added lines 34,35 and 40,41 to add 100mHz logging capability - #ifndef _ADAFRUIT_GPS_H #define _ADAFRUIT_GPS_H @@ -67,7 +65,7 @@ /// type for resulting code from running check() typedef enum { NMEA_BAD = 0, ///< passed none of the checks - NMEA_HAS_DOLLAR = 1, ///< has a dollar sign in the first position + NMEA_HAS_DOLLAR = 1, ///< has a dollar sign or exclamation mark in the first position NMEA_HAS_CHECKSUM = 2, ///< has a valid checksum at the end NMEA_HAS_NAME = 4, ///< there is a token after the $ followed by a comma NMEA_HAS_SOURCE = 10, ///< has a recognized source ID @@ -81,6 +79,7 @@ typedef enum { */ class Adafruit_GPS : public Print { public: + // Adafruit_GPS.cpp bool begin(uint32_t baud_or_i2caddr); #if (defined(__AVR__) || defined(ESP8266)) && defined(USE_SW_SERIAL) @@ -90,28 +89,28 @@ public: Adafruit_GPS(TwoWire *theWire); // Constructor when using I2C Adafruit_GPS(SPIClass *theSPI, int8_t cspin); // Constructor when using SPI Adafruit_GPS(); // Constructor for no communications, just data storage + void common_init(void); virtual ~Adafruit_GPS(); - char *lastNMEA(void); - bool newNMEAreceived(); - void common_init(void); - - void sendCommand(const char *); - - void pause(bool b); - - char read(void); - size_t write(uint8_t); size_t available(void); - + size_t write(uint8_t); + char read(void); + void sendCommand(const char *); + bool newNMEAreceived(); + void pause(bool b); + char *lastNMEA(void); + bool waitForSentence(const char *wait, uint8_t max = MAXWAITSENTENCE, + bool usingInterrupts = false); + bool LOCUS_StartLogger(void); + bool LOCUS_StopLogger(void); + bool LOCUS_ReadStatus(void); + bool standby(void); + bool wakeup(void); nmea_float_t secondsSinceFix(); nmea_float_t secondsSinceTime(); nmea_float_t secondsSinceDate(); void resetSentTime(); - - bool wakeup(void); - bool standby(void); - + // NMEA_parse.cpp bool parse(char *); bool check(char *nmea); @@ -197,12 +196,6 @@ public: uint8_t fixquality_3d; ///< 3D fix quality (1, 3, 3 = Nofix, 2D fix, 3D fix) uint8_t satellites; ///< Number of satellites in use - bool waitForSentence(const char *wait, uint8_t max = MAXWAITSENTENCE, - bool usingInterrupts = false); - bool LOCUS_StartLogger(void); - bool LOCUS_StopLogger(void); - bool LOCUS_ReadStatus(void); - uint16_t LOCUS_serial; ///< Log serial number uint16_t LOCUS_records; ///< Log number of data record uint8_t LOCUS_type; ///< Log type, 0: Overlap, 1: FullStop