Add set/getNMEALoggingMask. Allows selective logging of enabled NMEA messages

This commit is contained in:
PaulZC
2021-04-13 19:17:31 +01:00
parent 1220ef204a
commit e14ce7366c
4 changed files with 183 additions and 17 deletions
@@ -144,7 +144,9 @@ void setup()
myGNSS.enableNMEAMessage(UBX_NMEA_GGA, COM_PORT_I2C, 1); // Ensure the GxGGA (Global positioning system fix data) message is enabled. Send every measurement.
myGNSS.enableNMEAMessage(UBX_NMEA_GSA, COM_PORT_I2C, 1); // Ensure the GxGSA (GNSS DOP and Active satellites) message is enabled. Send every measurement.
myGNSS.enableNMEAMessage(UBX_NMEA_GSV, COM_PORT_I2C, 1); // Ensure the GxGSV (GNSS satellites in view) message is enabled. Send every measurement.
myGNSS.logNMEA(); // Enable NMEA logging
myGNSS.setNMEALoggingMask(SFE_UBLOX_LOG_NMEA_ALL); // Enable logging of all enabled NMEA messages
//myGNSS.setNMEALoggingMask(SFE_UBLOX_LOG_NMEA_GGA | SFE_UBLOX_LOG_NMEA_GSA); // Or we can, for example, log only GxGGA and GxGSA. Ignore GxGSV
Serial.println(F("Press any key to stop logging."));
+27 -1
View File
@@ -382,7 +382,8 @@ initPacketUBXHNRPVT KEYWORD2
flushHNRPVT KEYWORD2
logHNRPVT KEYWORD2
logNMEA KEYWORD2
setNMEALoggingMask KEYWORD2
getNMEALoggingMask KEYWORD2
setNavigationFrequency KEYWORD2
getNavigationFrequency KEYWORD2
@@ -546,16 +547,41 @@ UBX_NMEA_GLQ LITERAL1
UBX_NMEA_GNQ LITERAL1
UBX_NMEA_GNS LITERAL1
UBX_NMEA_GPQ LITERAL1
UBX_NMEA_GQQ LITERAL1
UBX_NMEA_GRS LITERAL1
UBX_NMEA_GSA LITERAL1
UBX_NMEA_GST LITERAL1
UBX_NMEA_GSV LITERAL1
UBX_NMEA_RLM LITERAL1
UBX_NMEA_RMC LITERAL1
UBX_NMEA_TXT LITERAL1
UBX_NMEA_VLW LITERAL1
UBX_NMEA_VTG LITERAL1
UBX_NMEA_ZDA LITERAL1
SFE_UBLOX_LOG_NMEA_ALL LITERAL1
SFE_UBLOX_LOG_NMEA_DTM LITERAL1
SFE_UBLOX_LOG_NMEA_GAQ LITERAL1
SFE_UBLOX_LOG_NMEA_GBQ LITERAL1
SFE_UBLOX_LOG_NMEA_GBS LITERAL1
SFE_UBLOX_LOG_NMEA_GGA LITERAL1
SFE_UBLOX_LOG_NMEA_GLL LITERAL1
SFE_UBLOX_LOG_NMEA_GLQ LITERAL1
SFE_UBLOX_LOG_NMEA_GNQ LITERAL1
SFE_UBLOX_LOG_NMEA_GNS LITERAL1
SFE_UBLOX_LOG_NMEA_GPQ LITERAL1
SFE_UBLOX_LOG_NMEA_GQQ LITERAL1
SFE_UBLOX_LOG_NMEA_GRS LITERAL1
SFE_UBLOX_LOG_NMEA_GSA LITERAL1
SFE_UBLOX_LOG_NMEA_GST LITERAL1
SFE_UBLOX_LOG_NMEA_GSV LITERAL1
SFE_UBLOX_LOG_NMEA_RLM LITERAL1
SFE_UBLOX_LOG_NMEA_RMC LITERAL1
SFE_UBLOX_LOG_NMEA_TXT LITERAL1
SFE_UBLOX_LOG_NMEA_VLW LITERAL1
SFE_UBLOX_LOG_NMEA_VTG LITERAL1
SFE_UBLOX_LOG_NMEA_ZDA LITERAL1
UBX_NAV_ATT LITERAL1
UBX_NAV_CLOCK LITERAL1
UBX_NAV_DOP LITERAL1
+79 -8
View File
@@ -50,6 +50,8 @@ SFE_UBLOX_GNSS::SFE_UBLOX_GNSS(void)
pinMode((uint8_t)debugPin, OUTPUT);
digitalWrite((uint8_t)debugPin, HIGH);
}
_logNMEA.all = 0; // Default to logging no NMEA messages
}
//Stop all automatic message processing. Free all used RAM
@@ -1020,6 +1022,7 @@ void SFE_UBLOX_GNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t r
}
else if (incoming == '$')
{
nmeaByteCounter = 0; // Reset the NMEA byte counter
currentSentence = NMEA;
}
else if (incoming == 0xD3) //RTCM frames start with 0xD3
@@ -1241,13 +1244,48 @@ void SFE_UBLOX_GNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t r
//Finally, increment the frame counter
ubxFrameCounter++;
}
else if (currentSentence == NMEA)
else if (currentSentence == NMEA) // Process incoming NMEA mesages. Selectively log if desired.
{
//If _logNMEA is true, attempt to store incoming in the file buffer
if (_logNMEA)
storeFileBytes(&incoming, 1);
if ((nmeaByteCounter == 0) && (incoming != '$'))
{
currentSentence = NONE; //Something went wrong. Reset. (Almost certainly redundant!)
}
else if ((nmeaByteCounter == 1) && (incoming != 'G'))
{
currentSentence = NONE; //Something went wrong. Reset.
}
else if ((nmeaByteCounter >= 0) && (nmeaByteCounter <= 5))
{
nmeaAddressField[nmeaByteCounter] = incoming; // Store the start character and NMEA address field
}
processNMEA(incoming); //Process each NMEA character
if (nmeaByteCounter == 5)
{
// We've just received the end of the address field. Check if it is selected for logging
if (logThisNMEA())
{
storeFileBytes(&nmeaAddressField[0], 6); // Add start character and address field to the file buffer
}
}
if ((nmeaByteCounter > 5) || (nmeaByteCounter < 0)) // Should we add incoming to the file buffer?
{
if (logThisNMEA())
storeFileBytes(&incoming, 1); // Add incoming to the file buffer
}
if (incoming == '*')
nmeaByteCounter = -5; // We are expecting * plus two checksum bytes plus CR and LF
nmeaByteCounter++; // Increment the byte counter
if (nmeaByteCounter == maxNMEAByteCount) // Check if we have processed too many bytes
currentSentence = NONE; //Something went wrong. Reset.
if (nmeaByteCounter == 0) // Check if we are done
currentSentence = NONE; // All done!
processNMEA(incoming); //Process each and every NMEA character
}
else if (currentSentence == RTCM)
{
@@ -1255,6 +1293,34 @@ void SFE_UBLOX_GNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t r
}
}
// PRIVATE: Return true if we should log this NMEA message
boolean SFE_UBLOX_GNSS::logThisNMEA()
{
if (_logNMEA.bits.all == 1) return (true);
if ((nmeaAddressField[3] == 'D') && (nmeaAddressField[4] == 'T') && (nmeaAddressField[5] == 'M') && (_logNMEA.bits.UBX_NMEA_DTM == 1)) return (true);
if ((nmeaAddressField[3] == 'G') && (nmeaAddressField[4] == 'A') && (nmeaAddressField[5] == 'Q') && (_logNMEA.bits.UBX_NMEA_GAQ == 1)) return (true);
if ((nmeaAddressField[3] == 'G') && (nmeaAddressField[4] == 'B') && (nmeaAddressField[5] == 'Q') && (_logNMEA.bits.UBX_NMEA_GBQ == 1)) return (true);
if ((nmeaAddressField[3] == 'G') && (nmeaAddressField[4] == 'B') && (nmeaAddressField[5] == 'S') && (_logNMEA.bits.UBX_NMEA_GBS == 1)) return (true);
if ((nmeaAddressField[3] == 'G') && (nmeaAddressField[4] == 'G') && (nmeaAddressField[5] == 'A') && (_logNMEA.bits.UBX_NMEA_GGA == 1)) return (true);
if ((nmeaAddressField[3] == 'G') && (nmeaAddressField[4] == 'L') && (nmeaAddressField[5] == 'L') && (_logNMEA.bits.UBX_NMEA_GLL == 1)) return (true);
if ((nmeaAddressField[3] == 'G') && (nmeaAddressField[4] == 'L') && (nmeaAddressField[5] == 'Q') && (_logNMEA.bits.UBX_NMEA_GLQ == 1)) return (true);
if ((nmeaAddressField[3] == 'G') && (nmeaAddressField[4] == 'N') && (nmeaAddressField[5] == 'Q') && (_logNMEA.bits.UBX_NMEA_GNQ == 1)) return (true);
if ((nmeaAddressField[3] == 'G') && (nmeaAddressField[4] == 'N') && (nmeaAddressField[5] == 'S') && (_logNMEA.bits.UBX_NMEA_GNS == 1)) return (true);
if ((nmeaAddressField[3] == 'G') && (nmeaAddressField[4] == 'P') && (nmeaAddressField[5] == 'Q') && (_logNMEA.bits.UBX_NMEA_GPQ == 1)) return (true);
if ((nmeaAddressField[3] == 'G') && (nmeaAddressField[4] == 'Q') && (nmeaAddressField[5] == 'Q') && (_logNMEA.bits.UBX_NMEA_GQQ == 1)) return (true);
if ((nmeaAddressField[3] == 'G') && (nmeaAddressField[4] == 'R') && (nmeaAddressField[5] == 'S') && (_logNMEA.bits.UBX_NMEA_GRS == 1)) return (true);
if ((nmeaAddressField[3] == 'G') && (nmeaAddressField[4] == 'S') && (nmeaAddressField[5] == 'A') && (_logNMEA.bits.UBX_NMEA_GSA == 1)) return (true);
if ((nmeaAddressField[3] == 'G') && (nmeaAddressField[4] == 'S') && (nmeaAddressField[5] == 'T') && (_logNMEA.bits.UBX_NMEA_GST == 1)) return (true);
if ((nmeaAddressField[3] == 'G') && (nmeaAddressField[4] == 'S') && (nmeaAddressField[5] == 'V') && (_logNMEA.bits.UBX_NMEA_GSV == 1)) return (true);
if ((nmeaAddressField[3] == 'R') && (nmeaAddressField[4] == 'L') && (nmeaAddressField[5] == 'M') && (_logNMEA.bits.UBX_NMEA_RLM == 1)) return (true);
if ((nmeaAddressField[3] == 'R') && (nmeaAddressField[4] == 'M') && (nmeaAddressField[5] == 'C') && (_logNMEA.bits.UBX_NMEA_RMC == 1)) return (true);
if ((nmeaAddressField[3] == 'T') && (nmeaAddressField[4] == 'X') && (nmeaAddressField[5] == 'T') && (_logNMEA.bits.UBX_NMEA_TXT == 1)) return (true);
if ((nmeaAddressField[3] == 'V') && (nmeaAddressField[4] == 'L') && (nmeaAddressField[5] == 'W') && (_logNMEA.bits.UBX_NMEA_VLW == 1)) return (true);
if ((nmeaAddressField[3] == 'V') && (nmeaAddressField[4] == 'T') && (nmeaAddressField[5] == 'G') && (_logNMEA.bits.UBX_NMEA_VTG == 1)) return (true);
if ((nmeaAddressField[3] == 'Z') && (nmeaAddressField[4] == 'D') && (nmeaAddressField[5] == 'A') && (_logNMEA.bits.UBX_NMEA_ZDA == 1)) return (true);
return (false);
}
//This is the default or generic NMEA processor. We're only going to pipe the data to serial port so we can see it.
//User could overwrite this function to pipe characters to nmea.process(c) of tinyGPS or MicroNMEA
//Or user could pipe each character to a buffer, radio, etc.
@@ -9079,10 +9145,15 @@ void SFE_UBLOX_GNSS::logHNRPVT(boolean enabled)
// ***** Helper Functions for NMEA Logging
//Log NMEA data in file buffer - if it exists! User needs to call setFileBufferSize before .begin
void SFE_UBLOX_GNSS::logNMEA(boolean enabled)
// Log selected NMEA messages to file buffer - if the messages are enabled and if the file buffer exists
// User needs to call setFileBufferSize before .begin
void SFE_UBLOX_GNSS::setNMEALoggingMask(uint32_t messages)
{
_logNMEA = enabled;
_logNMEA.all = messages;
}
uint32_t SFE_UBLOX_GNSS::getNMEALoggingMask()
{
return (_logNMEA.all);
}
// ***** CFG RATE Helper Functions
+74 -7
View File
@@ -99,6 +99,66 @@ typedef enum
SFE_UBLOX_PACKET_PACKETAUTO
} sfe_ublox_packet_buffer_e;
// Define a struct to allow selective logging of NMEA messages
typedef struct
{
union
{
uint32_t all;
struct
{
uint32_t all : 1;
uint32_t UBX_NMEA_DTM : 1;
uint32_t UBX_NMEA_GAQ : 1;
uint32_t UBX_NMEA_GBQ : 1;
uint32_t UBX_NMEA_GBS : 1;
uint32_t UBX_NMEA_GGA : 1;
uint32_t UBX_NMEA_GLL : 1;
uint32_t UBX_NMEA_GLQ : 1;
uint32_t UBX_NMEA_GNQ : 1;
uint32_t UBX_NMEA_GNS : 1;
uint32_t UBX_NMEA_GPQ : 1;
uint32_t UBX_NMEA_GQQ : 1;
uint32_t UBX_NMEA_GRS : 1;
uint32_t UBX_NMEA_GSA : 1;
uint32_t UBX_NMEA_GST : 1;
uint32_t UBX_NMEA_GSV : 1;
uint32_t UBX_NMEA_RLM : 1;
uint32_t UBX_NMEA_RMC : 1;
uint32_t UBX_NMEA_TXT : 1;
uint32_t UBX_NMEA_VLW : 1;
uint32_t UBX_NMEA_VTG : 1;
uint32_t UBX_NMEA_ZDA : 1;
} bits;
};
} sfe_ublox_nmea_logging_t;
// Define an enum to make it easy to enable/disable selected NMEA messages for logging
typedef enum
{
SFE_UBLOX_LOG_NMEA_ALL = 0x00000001,
SFE_UBLOX_LOG_NMEA_DTM = 0x00000002,
SFE_UBLOX_LOG_NMEA_GAQ = 0x00000004,
SFE_UBLOX_LOG_NMEA_GBQ = 0x00000008,
SFE_UBLOX_LOG_NMEA_GBS = 0x00000010,
SFE_UBLOX_LOG_NMEA_GGA = 0x00000020,
SFE_UBLOX_LOG_NMEA_GLL = 0x00000040,
SFE_UBLOX_LOG_NMEA_GLQ = 0x00000080,
SFE_UBLOX_LOG_NMEA_GNQ = 0x00000100,
SFE_UBLOX_LOG_NMEA_GNS = 0x00000200,
SFE_UBLOX_LOG_NMEA_GPQ = 0x00000400,
SFE_UBLOX_LOG_NMEA_GQQ = 0x00000800,
SFE_UBLOX_LOG_NMEA_GRS = 0x00001000,
SFE_UBLOX_LOG_NMEA_GSA = 0x00002000,
SFE_UBLOX_LOG_NMEA_GST = 0x00004000,
SFE_UBLOX_LOG_NMEA_GSV = 0x00008000,
SFE_UBLOX_LOG_NMEA_RLM = 0x00010000,
SFE_UBLOX_LOG_NMEA_RMC = 0x00020000,
SFE_UBLOX_LOG_NMEA_TXT = 0x00040000,
SFE_UBLOX_LOG_NMEA_VLW = 0x00080000,
SFE_UBLOX_LOG_NMEA_VTG = 0x00100000,
SFE_UBLOX_LOG_NMEA_ZDA = 0x00200000
} sfe_ublox_nmea_logging_selective_e;
//Registers
const uint8_t UBX_SYNCH_1 = 0xB5;
const uint8_t UBX_SYNCH_2 = 0x62;
@@ -159,7 +219,7 @@ const uint8_t UBX_CFG_VALSET = 0x8A; //Used for config of higher version u-blox
//Class: NMEA
//The following are used to enable NMEA messages. Descriptions come from the NMEA messages overview in the ZED-F9P Interface Description
const uint8_t UBX_NMEA_MSB = 0xF0; //All NMEA enable commands have 0xF0 as MSB
const uint8_t UBX_NMEA_MSB = 0xF0; //All NMEA enable commands have 0xF0 as MSB. Equal to UBX_CLASS_NMEA
const uint8_t UBX_NMEA_DTM = 0x0A; //GxDTM (datum reference)
const uint8_t UBX_NMEA_GAQ = 0x45; //GxGAQ (poll a standard message (if the current talker ID is GA))
const uint8_t UBX_NMEA_GBQ = 0x44; //GxGBQ (poll a standard message (if the current Talker ID is GB))
@@ -169,11 +229,13 @@ const uint8_t UBX_NMEA_GLL = 0x01; //GxGLL (latitude and long, whith time of pos
const uint8_t UBX_NMEA_GLQ = 0x43; //GxGLQ (poll a standard message (if the current Talker ID is GL))
const uint8_t UBX_NMEA_GNQ = 0x42; //GxGNQ (poll a standard message (if the current Talker ID is GN))
const uint8_t UBX_NMEA_GNS = 0x0D; //GxGNS (GNSS fix data)
const uint8_t UBX_NMEA_GPQ = 0x040; //GxGPQ (poll a standard message (if the current Talker ID is GP))
const uint8_t UBX_NMEA_GPQ = 0x40; //GxGPQ (poll a standard message (if the current Talker ID is GP))
const uint8_t UBX_NMEA_GQQ = 0x47; //GxGQQ (poll a standard message (if the current Talker ID is GQ))
const uint8_t UBX_NMEA_GRS = 0x06; //GxGRS (GNSS range residuals)
const uint8_t UBX_NMEA_GSA = 0x02; //GxGSA (GNSS DOP and Active satellites)
const uint8_t UBX_NMEA_GST = 0x07; //GxGST (GNSS Pseudo Range Error Statistics)
const uint8_t UBX_NMEA_GSV = 0x03; //GxGSV (GNSS satellites in view)
const uint8_t UBX_NMEA_RLM = 0x0B; //GxRMC (Return link message (RLM))
const uint8_t UBX_NMEA_RMC = 0x04; //GxRMC (Recommended minimum data)
const uint8_t UBX_NMEA_TXT = 0x41; //GxTXT (text transmission)
const uint8_t UBX_NMEA_VLW = 0x0F; //GxVLW (dual ground/water distance)
@@ -928,8 +990,9 @@ public:
void flushHNRPVT(); //Mark all the data as read/stale
void logHNRPVT(boolean enabled = true); // Log data to file buffer
// Helper function for NMEA logging
void logNMEA(boolean enabled = true); // Log NMEA data to file buffer
// Helper functions for NMEA logging
void setNMEALoggingMask(uint32_t messages = SFE_UBLOX_LOG_NMEA_ALL); // Log selected NMEA messages to file buffer - if enabled
uint32_t getNMEALoggingMask(); // Return which NMEA messages are selected for logging to the file buffer - if enabled
// Helper functions for CFG RATE
@@ -1186,7 +1249,7 @@ private:
boolean ubx7FcheckDisabled = false; // Flag to indicate if the "7F" check should be ignored in checkUbloxI2C
boolean _logNMEA = false; // Flag to indicate if NMEA data should be added to the file buffer
sfe_ublox_nmea_logging_t _logNMEA; // Flags to indicate which NMEA messages should be added to the file buffer for logging
//The packet buffers
//These are pointed at from within the ubxPacket
@@ -1218,11 +1281,15 @@ private:
unsigned long lastCheck = 0;
uint16_t ubxFrameCounter; //It counts all UBX frame. [Fixed header(2bytes), CLS(1byte), ID(1byte), length(2bytes), payload(x bytes), checksums(2bytes)]
uint16_t ubxFrameCounter; //Count all UBX frame bytes. [Fixed header(2bytes), CLS(1byte), ID(1byte), length(2bytes), payload(x bytes), checksums(2bytes)]
uint8_t rollingChecksumA; //Rolls forward as we receive incoming bytes. Checked against the last two A/B checksum bytes
uint8_t rollingChecksumB; //Rolls forward as we receive incoming bytes. Checked against the last two A/B checksum bytes
int16_t nmeaByteCounter; //Count all NMEA message bytes.
const int16_t maxNMEAByteCount = 1024; // Abort NMEA message reception if nmeaByteCounter exceeds this
uint8_t nmeaAddressField[6]; // NMEA Address Field - includes the start character (*)
boolean logThisNMEA(); // Return true if we should log this NMEA message
uint16_t rtcmLen = 0;
// Flag to prevent reentry into checkCallbacks