Add the new callback example

This commit is contained in:
PaulZC
2022-01-13 12:01:23 +00:00
parent a1814e32ab
commit a08198b27e
5 changed files with 140 additions and 6 deletions
+20 -2
View File
@@ -1712,6 +1712,13 @@ void SFE_UBLOX_GNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t r
memset(nmeaPtr, 0, nmeaMaxLength); // Clear the working copy
memcpy(nmeaPtr, &nmeaAddressField[0], 6); // Copy the start character and address field into the working copy
}
else
{
// if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
// {
// _debugSerial->println(F("process: non-auto NMEA message"));
// }
}
// We've just received the end of the address field. Check if it is selected for logging
if (logThisNMEA())
@@ -1804,7 +1811,7 @@ void SFE_UBLOX_GNSS::process(uint8_t incoming, ubxPacket *incomingUBX, uint8_t r
nmeaAutomaticFlags *flagsPtr = getNMEAFlagsPtr(); // Get a pointer to the flags
nmeaAutomaticFlags flagsCopy = *flagsPtr;
flagsCopy.flags.bits.completeCopyValid = 1; // Set the complete copy valid flag
flagsCopy.flags.bits.completeCopyRead = 0; // Clear the complete copy read/stale flag
flagsCopy.flags.bits.completeCopyRead = 0; // Clear the complete copy read flag
*flagsPtr = flagsCopy; // Update the flags
// Callback
if (doesThisNMEAHaveCallback()) // Do we need to copy the data into the callback copy?
@@ -4628,7 +4635,7 @@ void SFE_UBLOX_GNSS::checkCallbacks(void)
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->callbackPointer != NULL) // If the pointer to the callback has been defined
&& (storageNMEAGPGGA->automaticFlags.flags.bits.callbackCopyValid == true)) // If the copy of the data is valid
&& (storageNMEAGPGGA->automaticFlags.flags.bits.callbackCopyValid == 1)) // If the copy of the data is valid
{
// if (_printDebug == true)
// _debugSerial->println(F("checkCallbacks: calling callback for GPGGA"));
@@ -4636,6 +4643,17 @@ void SFE_UBLOX_GNSS::checkCallbacks(void)
storageNMEAGPGGA->automaticFlags.flags.bits.callbackCopyValid = 0; // Mark the data as stale
}
if ((storageNMEAGNGGA != NULL) // If RAM has been allocated for message storage
&& (storageNMEAGNGGA->callbackCopy != NULL) // If RAM has been allocated for the copy of the data
&& (storageNMEAGNGGA->callbackPointer != NULL) // If the pointer to the callback has been defined
&& (storageNMEAGNGGA->automaticFlags.flags.bits.callbackCopyValid == 1)) // If the copy of the data is valid
{
// if (_printDebug == true)
// _debugSerial->println(F("checkCallbacks: calling callback for GNGGA"));
storageNMEAGNGGA->callbackPointer(*storageNMEAGNGGA->callbackCopy); // Call the callback
storageNMEAGNGGA->automaticFlags.flags.bits.callbackCopyValid = 0; // Mark the data as stale
}
checkCallbacksReentrant = false;
}
+1 -1
View File
@@ -1345,7 +1345,7 @@ public:
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
uint8_t getLatestNMEAGNGGA(NMEA_GGA_data_t *data); // Return the most recent GNGGA: 0 = no data, 1 = stale data, 2 = fresh data
bool setNMEAGNGGAcallback(void (*callbackPointer)(NMEA_GGA_data_t)); //Enable a callback on the arrival of a GPGGA message
bool setNMEAGNGGAcallback(void (*callbackPointer)(NMEA_GGA_data_t)); //Enable a callback on the arrival of a GNGGA message
// 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
+1 -2
View File
@@ -2242,7 +2242,7 @@ struct nmeaAutomaticFlags
uint8_t all;
struct
{
uint8_t completeCopyValid : 1; // Is the copy of the data struct used by the get function valid/fresh? 0 = invalid/stale, 1 = valid/fresh
uint8_t completeCopyValid : 1; // Is the copy of the data struct used by the get function valid/fresh? 0 = invalid, 1 = valid
uint8_t completeCopyRead : 1; // Has the complete copy been read? 0 = unread, 1 = read
uint8_t callbackCopyValid : 1; // Is the copy of the data struct used by the callback valid/fresh? 0 = invalid/stale, 1 = valid/fresh
} bits;
@@ -2280,5 +2280,4 @@ typedef struct
NMEA_GGA_data_t *callbackCopy; // The callback gets its own preserved copy of the complete copy
} NMEA_GNGGA_t;
#endif