Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions examples/Callbacks/CallbackExample1_PVT/CallbackExample1_PVT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,39 @@
SFE_UBLOX_GPS myGPS;

// Callback: printPVTdata will be called when new NAV PVT data arrives
// See u-blox_structs.h for the full definition of UBX_NAV_PVT_data_t *packetUBXNAVPVTcopy
void printPVTdata()
// See u-blox_structs.h for the full definition of UBX_NAV_PVT_data_t
void printPVTdata(UBX_NAV_PVT_data_t ubxDataStruct)
{
Serial.println();

Serial.print(F("Time: ")); // Print the time
uint8_t hms = myGPS.packetUBXNAVPVTcopy->hour; // Print the hours
uint8_t hms = ubxDataStruct.hour; // Print the hours
if (hms < 10) Serial.print(F("0")); // Print a leading zero if required
Serial.print(hms);
Serial.print(F(":"));
hms = myGPS.packetUBXNAVPVTcopy->min; // Print the minutes
hms = ubxDataStruct.min; // Print the minutes
if (hms < 10) Serial.print(F("0")); // Print a leading zero if required
Serial.print(hms);
Serial.print(F(":"));
hms = myGPS.packetUBXNAVPVTcopy->sec; // Print the seconds
hms = ubxDataStruct.sec; // Print the seconds
if (hms < 10) Serial.print(F("0")); // Print a leading zero if required
Serial.print(hms);
Serial.print(F("."));
unsigned long millisecs = myGPS.packetUBXNAVPVTcopy->iTOW % 1000; // Print the milliseconds
unsigned long millisecs = ubxDataStruct.iTOW % 1000; // Print the milliseconds
if (millisecs < 100) Serial.print(F("0")); // Print the trailing zeros correctly
if (millisecs < 10) Serial.print(F("0"));
Serial.print(millisecs);

long latitude = myGPS.packetUBXNAVPVTcopy->lat; // Print the latitude
long latitude = ubxDataStruct.lat; // Print the latitude
Serial.print(F(" Lat: "));
Serial.print(latitude);

long longitude = myGPS.packetUBXNAVPVTcopy->lon; // Print the longitude
long longitude = ubxDataStruct.lon; // Print the longitude
Serial.print(F(" Long: "));
Serial.print(longitude);
Serial.print(F(" (degrees * 10^-7)"));

long altitude = myGPS.packetUBXNAVPVTcopy->hMSL; // Print the height above mean sea level
long altitude = ubxDataStruct.hMSL; // Print the height above mean sea level
Serial.print(F(" Height above MSL: "));
Serial.print(altitude);
Serial.println(F(" (mm)"));
Expand All @@ -85,8 +85,8 @@ void setup()
myGPS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR

myGPS.setNavigationFrequency(2); //Produce two solutions per second
myGPS.setAutoPVTcallback(printPVTdata); // Enable automatic NAV PVT messages with callback to printPVTdata

myGPS.setAutoPVTcallback(&printPVTdata); // Enable automatic NAV PVT messages with callback to printPVTdata
}

void loop()
Expand Down
24 changes: 13 additions & 11 deletions src/SparkFun_Ublox_Arduino_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1448,10 +1448,10 @@ void SFE_UBLOX_GPS::processUBXpacket(ubxPacket *msg)
packetUBXNAVPVT->moduleQueried.moduleQueried2.all = 0xFFFFFFFF;

//Check if we need to copy the data for the callback
if ((packetUBXNAVPVTcopy != NULL) // If RAM has been allocated for the copy of the data
if ((packetUBXNAVPVT->callbackData != NULL) // If RAM has been allocated for the copy of the data
&& (packetUBXNAVPVT->automaticFlags.flags.bits.callbackCopyValid == false)) // AND the data is stale
{
memcpy(&packetUBXNAVPVTcopy->iTOW, &packetUBXNAVPVT->data.iTOW, sizeof(UBX_NAV_PVT_data_t));
memcpy(&packetUBXNAVPVT->callbackData->iTOW, &packetUBXNAVPVT->data.iTOW, sizeof(UBX_NAV_PVT_data_t));
packetUBXNAVPVT->automaticFlags.flags.bits.callbackCopyValid = true;
}

Expand Down Expand Up @@ -2736,13 +2736,13 @@ void SFE_UBLOX_GPS::checkCallbacks(void)
packetUBXNAVATT->automaticFlags.flags.bits.callbackCopyValid = false; // Mark the data as stale
}

if ((packetUBXNAVPVTcopy != NULL) // If RAM has been allocated for the copy of the data
&& (packetUBXNAVPVT->automaticFlags.callbackPointer != NULL) // If the pointer to the callback has been defined
if ((packetUBXNAVPVT->callbackData != NULL) // If RAM has been allocated for the copy of the data
&& (packetUBXNAVPVT->callbackPointer != NULL) // If the pointer to the callback has been defined
&& (packetUBXNAVPVT->automaticFlags.flags.bits.callbackCopyValid == true)) // If the copy of the data is valid
{
// if (_printDebug == true)
// _debugSerial->println(F("checkCallbacks: calling callback for NAV PVT"));
packetUBXNAVPVT->automaticFlags.callbackPointer(); // Call the callback
packetUBXNAVPVT->callbackPointer(*packetUBXNAVPVT->callbackData); // Call the callback
packetUBXNAVPVT->automaticFlags.flags.bits.callbackCopyValid = false; // Mark the data as stale
}

Expand Down Expand Up @@ -5280,27 +5280,27 @@ boolean SFE_UBLOX_GPS::setAutoPVT(boolean enable, boolean implicitUpdate, uint16
}

//Enable automatic navigation message generation by the GNSS. This changes the way getPVT works.
//Data is passed to the callback in packetUBXNAVPVTcopy.
boolean SFE_UBLOX_GPS::setAutoPVTcallback(void (*callbackPointer)(), uint16_t maxWait)
boolean SFE_UBLOX_GPS::setAutoPVTcallback(void (*callbackPointer)(UBX_NAV_PVT_data_t), uint16_t maxWait)
{
// Enable auto messages. Set implicitUpdate to false as we expect the user to call checkUblox manually.
boolean result = setAutoPVT(true, false, maxWait);
if (!result)
return (result); // Bail if setAutoPVT failed

if (packetUBXNAVPVTcopy == NULL) //Check if RAM has been allocated for the callback copy
if (packetUBXNAVPVT->callbackData == NULL) //Check if RAM has been allocated for the callback copy
{
packetUBXNAVPVTcopy = new UBX_NAV_PVT_data_t; //Allocate RAM for the main struct
packetUBXNAVPVT->callbackData = new UBX_NAV_PVT_data_t; //Allocate RAM for the main struct
}

if (packetUBXNAVPVTcopy == NULL)
if (packetUBXNAVPVT->callbackData == NULL)
{
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
_debugSerial->println(F("setAutoPVTcallback: PANIC! RAM allocation failed!"));
return (false);
}

packetUBXNAVPVT->automaticFlags.callbackPointer = callbackPointer;
packetUBXNAVPVT->callbackPointer = callbackPointer; // RAM has been allocated so now update the pointer

return (true);
}

Expand Down Expand Up @@ -5335,6 +5335,8 @@ boolean SFE_UBLOX_GPS::initPacketUBXNAVPVT()
packetUBXNAVPVT->automaticFlags.callbackPointer = NULL;
packetUBXNAVPVT->moduleQueried.moduleQueried1.all = 0;
packetUBXNAVPVT->moduleQueried.moduleQueried2.all = 0;
packetUBXNAVPVT->callbackPointer = NULL;
packetUBXNAVPVT->callbackData = NULL;
return (true);
}

Expand Down
3 changes: 1 addition & 2 deletions src/SparkFun_Ublox_Arduino_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ class SFE_UBLOX_GPS
boolean getPVT(uint16_t maxWait = defaultMaxWait); //Query module for latest group of datums and load global vars: lat, long, alt, speed, SIV, accuracies, etc. If autoPVT is disabled, performs an explicit poll and waits, if enabled does not block. Returns true if new PVT is available.
boolean setAutoPVT(boolean enabled, uint16_t maxWait = defaultMaxWait); //Enable/disable automatic PVT reports at the navigation frequency
boolean setAutoPVT(boolean enabled, boolean implicitUpdate, uint16_t maxWait = defaultMaxWait); //Enable/disable automatic PVT reports at the navigation frequency, with implicitUpdate == false accessing stale data will not issue parsing of data in the rxbuffer of your interface, instead you have to call checkUblox when you want to perform an update
boolean setAutoPVTcallback(void (*callbackPointer)(), uint16_t maxWait = defaultMaxWait); //Enable automatic PVT reports at the navigation frequency. Data is accessed from the callback.
boolean setAutoPVTcallback(void (*callbackPointer)(UBX_NAV_PVT_data_t), uint16_t maxWait = defaultMaxWait); //Enable automatic PVT reports at the navigation frequency. Data is accessed from the callback.
boolean assumeAutoPVT(boolean enabled, boolean implicitUpdate = true); //In case no config access to the GPS is possible and PVT is send cyclically already
boolean initPacketUBXNAVPVT(); // Allocate RAM for packetUBXNAVPVT and initialize it
void flushPVT(); //Mark all the PVT data as read/stale
Expand Down Expand Up @@ -1009,7 +1009,6 @@ class SFE_UBLOX_GPS
UBX_NAV_ATT_t *packetUBXNAVATT = NULL; // Pointer to struct. RAM will be allocated for this if/when necessary
UBX_NAV_ATT_data_t *packetUBXNAVATTcopy = NULL; // Copy of the data - to be passed to the callback if required
UBX_NAV_PVT_t *packetUBXNAVPVT = NULL; // Pointer to struct. RAM will be allocated for this if/when necessary
UBX_NAV_PVT_data_t *packetUBXNAVPVTcopy = NULL; // Copy of the data - to be passed to the callback if required
UBX_NAV_ODO_t *packetUBXNAVODO = NULL; // Pointer to struct. RAM will be allocated for this if/when necessary
UBX_NAV_ODO_data_t *packetUBXNAVODOcopy = NULL; // Copy of the data - to be passed to the callback if required
UBX_NAV_VELECEF_t *packetUBXNAVVELECEF = NULL; // Pointer to struct. RAM will be allocated for this if/when necessary
Expand Down
2 changes: 2 additions & 0 deletions src/u-blox_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,8 @@ typedef struct
ubxAutomaticFlags automaticFlags;
UBX_NAV_PVT_data_t data;
UBX_NAV_PVT_moduleQueried_t moduleQueried;
void (*callbackPointer)(UBX_NAV_PVT_data_t);
UBX_NAV_PVT_data_t *callbackData;
} UBX_NAV_PVT_t;

// UBX-NAV-ODO (0x01 0x09): Odometer solution
Expand Down