From 9b6369e94353fd63063037ccb9bd687fcb60662d Mon Sep 17 00:00:00 2001 From: PaulZC Date: Wed, 2 Mar 2022 13:46:35 +0000 Subject: [PATCH] Disable auto-NMEA support on the Uno - to avoid exceeding the program memory --- src/SparkFun_u-blox_GNSS_Arduino_Library.cpp | 22 +++++++++++++------- src/SparkFun_u-blox_GNSS_Arduino_Library.h | 10 +++++++-- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp b/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp index 616c816..aa2c340 100644 --- a/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp +++ b/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp @@ -422,6 +422,7 @@ void SFE_UBLOX_GNSS::end(void) packetUBXHNRPVT = NULL; // Redundant? } +#ifndef SFE_UBLOX_REDUCED_PROG_MEM if (storageNMEAGPGGA != NULL) { if (storageNMEAGPGGA->callbackCopy != NULL) @@ -501,6 +502,7 @@ void SFE_UBLOX_GNSS::end(void) delete storageNMEAGNZDA; storageNMEAGNZDA = NULL; // Redundant? } +#endif } // Allow the user to change packetCfgPayloadSize. Handy if you want to process big messages like RAWX @@ -1861,6 +1863,7 @@ void SFE_UBLOX_GNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t r _signsOfLife = isNMEAHeaderValid(); } +#ifndef SFE_UBLOX_REDUCED_PROG_MEM // Check if we have automatic storage for this message if (isThisNMEAauto()) { @@ -1872,6 +1875,7 @@ void SFE_UBLOX_GNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t r memcpy(nmeaPtr, &nmeaAddressField[0], 6); // Copy the start character and address field into the working copy } else +#endif { // if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging // { @@ -1898,6 +1902,7 @@ void SFE_UBLOX_GNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t r if ((nmeaByteCounter > 5) || (nmeaByteCounter < 0)) // Should we add incoming to the file buffer and/or pass it to processNMEA? { +#ifndef SFE_UBLOX_REDUCED_PROG_MEM if (isThisNMEAauto()) { uint8_t *lengthPtr = getNMEAWorkingLengthPtr(); // Get a pointer to the working copy length @@ -1909,15 +1914,14 @@ void SFE_UBLOX_GNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t r *lengthPtr = *lengthPtr + 1; // Increment the length if (*lengthPtr == nmeaMaxLength) { -#ifndef SFE_UBLOX_REDUCED_PROG_MEM if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging { _debugSerial->println(F("process: NMEA buffer is full!")); } -#endif } } } +#endif if (logThisNMEA()) storeFileBytes(&incoming, 1); // Add incoming to the file buffer if (processThisNMEA()) @@ -1934,6 +1938,7 @@ void SFE_UBLOX_GNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t r if (nmeaByteCounter == 0) // Check if we are done { +#ifndef SFE_UBLOX_REDUCED_PROG_MEM if (isThisNMEAauto()) { uint8_t *workingLengthPtr = getNMEAWorkingLengthPtr(); // Get a pointer to the working copy length @@ -1988,7 +1993,6 @@ void SFE_UBLOX_GNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t r } else { -#ifndef SFE_UBLOX_REDUCED_PROG_MEM if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging { _debugSerial->print(F("process: NMEA checksum fail (2)! Expected ")); @@ -1999,19 +2003,17 @@ void SFE_UBLOX_GNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t r _debugSerial->write(*(workingNMEAPtr + charsChecked + 1)); _debugSerial->println(); } -#endif } } else { -#ifndef SFE_UBLOX_REDUCED_PROG_MEM if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging { _debugSerial->println(F("process: NMEA checksum fail (1)!")); } -#endif } } +#endif currentSentence = NONE; // All done! } } @@ -2192,6 +2194,7 @@ void SFE_UBLOX_GNSS::processNMEA(char incoming) _nmeaOutputPort->write(incoming); // Echo this byte to the serial port } +#ifndef SFE_UBLOX_REDUCED_PROG_MEM // Check if the NMEA message (in nmeaAddressField) is "auto" (i.e. has RAM allocated for it) bool SFE_UBLOX_GNSS::isThisNMEAauto() { @@ -2763,6 +2766,7 @@ nmeaAutomaticFlags *SFE_UBLOX_GNSS::getNMEAFlagsPtr() return NULL; } +#endif // We need to be able to identify an RTCM packet and then the length // so that we know when the RTCM message is completely received and we then start @@ -5564,6 +5568,7 @@ void SFE_UBLOX_GNSS::checkCallbacks(void) packetUBXHNRPVT->automaticFlags.flags.bits.callbackCopyValid = false; // Mark the data as stale } +#ifndef SFE_UBLOX_REDUCED_PROG_MEM if ((storageNMEAGPGGA != NULL) // If RAM has been allocated for message storage && (storageNMEAGPGGA->callbackCopy != NULL) // If RAM has been allocated for the copy of the data && (storageNMEAGPGGA->automaticFlags.flags.bits.callbackCopyValid == 1)) // If the copy of the data is valid @@ -5715,6 +5720,7 @@ void SFE_UBLOX_GNSS::checkCallbacks(void) } storageNMEAGNZDA->automaticFlags.flags.bits.callbackCopyValid = 0; // Mark the data as stale } +#endif checkCallbacksReentrant = false; } @@ -14812,6 +14818,7 @@ uint32_t SFE_UBLOX_GNSS::getProcessNMEAMask() return (_processNMEA.all); } +#ifndef SFE_UBLOX_REDUCED_PROG_MEM // Initiate automatic storage of NMEA GPGGA messages // Get the most recent GPGGA message @@ -15234,7 +15241,7 @@ bool SFE_UBLOX_GNSS::initStorageNMEAGNVTG() return (true); } -// Initiate automatic storage of NMEA GPVTG messages +// Initiate automatic storage of NMEA GPRMC messages // Get the most recent GPRMC message // Return 0 if the message has not been received from the module @@ -15655,6 +15662,7 @@ bool SFE_UBLOX_GNSS::initStorageNMEAGNZDA() return (true); } +#endif // ***** CFG RATE Helper Functions diff --git a/src/SparkFun_u-blox_GNSS_Arduino_Library.h b/src/SparkFun_u-blox_GNSS_Arduino_Library.h index 2ae0485..b22e40f 100644 --- a/src/SparkFun_u-blox_GNSS_Arduino_Library.h +++ b/src/SparkFun_u-blox_GNSS_Arduino_Library.h @@ -57,9 +57,9 @@ #include "u-blox_structs.h" // Uncomment the next line (or add SFE_UBLOX_REDUCED_PROG_MEM as a compiler directive) to reduce the amount of program memory used by the library -//#define SFE_UBLOX_REDUCED_PROG_MEM // Uncommenting this line will delete the minor debug messages to save memory +//#define SFE_UBLOX_REDUCED_PROG_MEM // Uncommenting this line will delete the minor debug messages and disable auto-NMEA support to save memory -// The code just about fills the program memory on the ATmega328P (Arduino Uno), so let's delete the minor debug messages anyway +// The code just about fills the program memory on the ATmega328P (Arduino Uno), so let's delete the minor debug messages and disable auto-NMEA support anyway #if !defined(SFE_UBLOX_REDUCED_PROG_MEM) && defined(ARDUINO_ARCH_AVR) #define SFE_UBLOX_REDUCED_PROG_MEM #endif @@ -1431,6 +1431,7 @@ public: void setProcessNMEAMask(uint32_t messages = SFE_UBLOX_FILTER_NMEA_ALL); // Control which NMEA messages are passed to processNMEA. Default to passing ALL messages uint32_t getProcessNMEAMask(); // Return which NMEA messages are passed to processNMEA +#ifndef SFE_UBLOX_REDUCED_PROG_MEM // Support for "auto" storage of NMEA messages uint8_t getLatestNMEAGPGGA(NMEA_GGA_data_t *data); // Return the most recent GPGGA: 0 = no data, 1 = stale data, 2 = fresh data bool setNMEAGPGGAcallback(void (*callbackPointer)(NMEA_GGA_data_t)); // Enable a callback on the arrival of a GPGGA message @@ -1456,6 +1457,7 @@ public: uint8_t getLatestNMEAGNZDA(NMEA_ZDA_data_t *data); // Return the most recent GNZDA: 0 = no data, 1 = stale data, 2 = fresh data bool setNMEAGNZDAcallback(void (*callbackPointer)(NMEA_ZDA_data_t)); // Enable a callback on the arrival of a GNZDA message bool setNMEAGNZDAcallbackPtr(void (*callbackPointerPtr)(NMEA_ZDA_data_t *)); // Enable a callback on the arrival of a GNZDA message +#endif // Functions to extract signed and unsigned 8/16/32-bit data from a ubxPacket // From v2.0: These are public. The user can call these to extract data from custom packets @@ -1511,6 +1513,7 @@ public: UBX_MGA_ACK_DATA0_t *packetUBXMGAACK = NULL; // Pointer to struct. RAM will be allocated for this if/when necessary UBX_MGA_DBD_t *packetUBXMGADBD = NULL; // Pointer to struct. RAM will be allocated for this if/when necessary +#ifndef SFE_UBLOX_REDUCED_PROG_MEM NMEA_GPGGA_t *storageNMEAGPGGA = NULL; // Pointer to struct. RAM will be allocated for this if/when necessary NMEA_GNGGA_t *storageNMEAGNGGA = NULL; // Pointer to struct. RAM will be allocated for this if/when necessary NMEA_GPVTG_t *storageNMEAGPVTG = NULL; // Pointer to struct. RAM will be allocated for this if/when necessary @@ -1519,6 +1522,7 @@ public: NMEA_GNRMC_t *storageNMEAGNRMC = NULL; // Pointer to struct. RAM will be allocated for this if/when necessary NMEA_GPZDA_t *storageNMEAGPZDA = NULL; // Pointer to struct. RAM will be allocated for this if/when necessary NMEA_GNZDA_t *storageNMEAGNZDA = NULL; // Pointer to struct. RAM will be allocated for this if/when necessary +#endif uint16_t rtcmFrameCounter = 0; // Tracks the type of incoming byte inside RTCM frame @@ -1602,6 +1606,7 @@ private: bool initPacketUBXMGAACK(); // Allocate RAM for packetUBXMGAACK and initialize it bool initPacketUBXMGADBD(); // Allocate RAM for packetUBXMGADBD and initialize it +#ifndef SFE_UBLOX_REDUCED_PROG_MEM bool initStorageNMEAGPGGA(); // Allocate RAM for incoming NMEA GPGGA messages and initialize it bool initStorageNMEAGNGGA(); // Allocate RAM for incoming NMEA GNGGA messages and initialize it bool initStorageNMEAGPVTG(); // Allocate RAM for incoming NMEA GPVTG messages and initialize it @@ -1610,6 +1615,7 @@ private: bool initStorageNMEAGNRMC(); // Allocate RAM for incoming NMEA GNRMC messages and initialize it bool initStorageNMEAGPZDA(); // Allocate RAM for incoming NMEA GPZDA messages and initialize it bool initStorageNMEAGNZDA(); // Allocate RAM for incoming NMEA GNZDA messages and initialize it +#endif // Variables TwoWire *_i2cPort; // The generic connection to user's chosen I2C hardware