Update data logging examples 1-3 to use the new callback pointers

This commit is contained in:
PaulZC
2022-02-06 10:13:53 +00:00
parent 0bf94bebdd
commit 5a4ac25f55
3 changed files with 41 additions and 46 deletions
@@ -22,9 +22,7 @@
Insert a formatted micro-SD card into the socket on the Carrier Board. Insert a formatted micro-SD card into the socket on the Carrier Board.
Connect the Carrier Board to your computer using a USB-C cable. Connect the Carrier Board to your computer using a USB-C cable.
Ensure you have the SparkFun Apollo3 boards installed: http://boardsmanager/All#SparkFun_Apollo3 Ensure you have the SparkFun Apollo3 boards installed: http://boardsmanager/All#SparkFun_Apollo3
This code has been tested using version 2.1.0 of the Apollo3 boards on Arduino IDE 1.8.13. This code has been tested using version 2.2.0 of the Apollo3 boards on Arduino IDE 1.8.13.
- Version 2.1.1 of Apollo3 contains a feature which makes I2C communication with u-blox modules problematic
- We recommend using v2.1.0 of Apollo3 until v2.2.0 is released
Select "Artemis MicroMod Processor" as the board type. Select "Artemis MicroMod Processor" as the board type.
Press upload to upload the code onto the Artemis. Press upload to upload the code onto the Artemis.
Open the Serial Monitor at 115200 baud to see the output. Open the Serial Monitor at 115200 baud to see the output.
@@ -69,6 +67,7 @@ File myFile; //File that all GNSS data is written to
#endif #endif
#define packetLength 100 // NAV PVT is 92 + 8 bytes in length (including the sync chars, class, id, length and checksum bytes) #define packetLength 100 // NAV PVT is 92 + 8 bytes in length (including the sync chars, class, id, length and checksum bytes)
uint8_t *myBuffer; // Use myBuffer to hold the data while we write it to SD card
// Callback: printPVTdata will be called when new NAV PVT data arrives // 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 // See u-blox_structs.h for the full definition of UBX_NAV_PVT_data_t
@@ -77,38 +76,38 @@ File myFile; //File that all GNSS data is written to
// | / _____ You can use any name you like for the struct // | / _____ You can use any name you like for the struct
// | | / // | | /
// | | | // | | |
void printPVTdata(UBX_NAV_PVT_data_t ubxDataStruct) void printPVTdata(UBX_NAV_PVT_data_t *ubxDataStruct)
{ {
Serial.println(); Serial.println();
Serial.print(F("Time: ")); // Print the time Serial.print(F("Time: ")); // Print the time
uint8_t hms = ubxDataStruct.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 if (hms < 10) Serial.print(F("0")); // Print a leading zero if required
Serial.print(hms); Serial.print(hms);
Serial.print(F(":")); Serial.print(F(":"));
hms = ubxDataStruct.min; // Print the minutes hms = ubxDataStruct->min; // Print the minutes
if (hms < 10) Serial.print(F("0")); // Print a leading zero if required if (hms < 10) Serial.print(F("0")); // Print a leading zero if required
Serial.print(hms); Serial.print(hms);
Serial.print(F(":")); Serial.print(F(":"));
hms = ubxDataStruct.sec; // Print the seconds hms = ubxDataStruct->sec; // Print the seconds
if (hms < 10) Serial.print(F("0")); // Print a leading zero if required if (hms < 10) Serial.print(F("0")); // Print a leading zero if required
Serial.print(hms); Serial.print(hms);
Serial.print(F(".")); Serial.print(F("."));
unsigned long millisecs = ubxDataStruct.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 < 100) Serial.print(F("0")); // Print the trailing zeros correctly
if (millisecs < 10) Serial.print(F("0")); if (millisecs < 10) Serial.print(F("0"));
Serial.print(millisecs); Serial.print(millisecs);
long latitude = ubxDataStruct.lat; // Print the latitude long latitude = ubxDataStruct->lat; // Print the latitude
Serial.print(F(" Lat: ")); Serial.print(F(" Lat: "));
Serial.print(latitude); Serial.print(latitude);
long longitude = ubxDataStruct.lon; // Print the longitude long longitude = ubxDataStruct->lon; // Print the longitude
Serial.print(F(" Long: ")); Serial.print(F(" Long: "));
Serial.print(longitude); Serial.print(longitude);
Serial.print(F(" (degrees * 10^-7)")); Serial.print(F(" (degrees * 10^-7)"));
long altitude = ubxDataStruct.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(F(" Height above MSL: "));
Serial.print(altitude); Serial.print(altitude);
Serial.println(F(" (mm)")); Serial.println(F(" (mm)"));
@@ -200,10 +199,12 @@ void setup()
myGNSS.setNavigationFrequency(1); //Produce one navigation solution per second myGNSS.setNavigationFrequency(1); //Produce one navigation solution per second
myGNSS.setAutoPVTcallback(&printPVTdata); // Enable automatic NAV PVT messages with callback to printPVTdata myGNSS.setAutoPVTcallbackPtr(&printPVTdata); // Enable automatic NAV PVT messages with callback to printPVTdata
myGNSS.logNAVPVT(); // Enable NAV PVT data logging myGNSS.logNAVPVT(); // Enable NAV PVT data logging
myBuffer = new uint8_t[packetLength]; // Create our own buffer to hold the data while we write it to SD card
Serial.println(F("Press any key to stop logging.")); Serial.println(F("Press any key to stop logging."));
} }
@@ -214,9 +215,7 @@ void loop()
if (myGNSS.fileBufferAvailable() >= packetLength) // Check to see if a new packetLength-byte NAV PVT message has been stored if (myGNSS.fileBufferAvailable() >= packetLength) // Check to see if a new packetLength-byte NAV PVT message has been stored
{ {
uint8_t myBuffer[packetLength]; // Create our own buffer to hold the data while we write it to SD card myGNSS.extractFileBufferData(myBuffer, packetLength); // Extract exactly packetLength bytes from the UBX file buffer and put them into myBuffer
myGNSS.extractFileBufferData((uint8_t *)&myBuffer, packetLength); // Extract exactly packetLength bytes from the UBX file buffer and put them into myBuffer
myFile.write(myBuffer, packetLength); // Write exactly packetLength bytes from myBuffer to the ubxDataFile on the SD card myFile.write(myBuffer, packetLength); // Write exactly packetLength bytes from myBuffer to the ubxDataFile on the SD card
@@ -22,9 +22,7 @@
Insert a formatted micro-SD card into the socket on the Carrier Board. Insert a formatted micro-SD card into the socket on the Carrier Board.
Connect the Carrier Board to your computer using a USB-C cable. Connect the Carrier Board to your computer using a USB-C cable.
Ensure you have the SparkFun Apollo3 boards installed: http://boardsmanager/All#SparkFun_Apollo3 Ensure you have the SparkFun Apollo3 boards installed: http://boardsmanager/All#SparkFun_Apollo3
This code has been tested using version 2.1.0 of the Apollo3 boards on Arduino IDE 1.8.13. This code has been tested using version 2.2.0 of the Apollo3 boards on Arduino IDE 1.8.13.
- Version 2.1.1 of Apollo3 contains a feature which makes I2C communication with u-blox modules problematic
- We recommend using v2.1.0 of Apollo3 until v2.2.0 is released
Select "Artemis MicroMod Processor" as the board type. Select "Artemis MicroMod Processor" as the board type.
Press upload to upload the code onto the Artemis. Press upload to upload the code onto the Artemis.
Open the Serial Monitor at 115200 baud to see the output. Open the Serial Monitor at 115200 baud to see the output.
@@ -82,6 +80,7 @@ File myFile; //File that all GNSS data is written to
#endif #endif
#define packetLength 36 // TIM TM2 is 28 + 8 bytes in length (including the sync chars, class, id, length and checksum bytes) #define packetLength 36 // TIM TM2 is 28 + 8 bytes in length (including the sync chars, class, id, length and checksum bytes)
uint8_t *myBuffer; // Use myBuffer to hold the data while we write it to SD card
int dotsPrinted = 0; // Print dots in rows of 50 while waiting for a TIM TM2 message int dotsPrinted = 0; // Print dots in rows of 50 while waiting for a TIM TM2 message
@@ -92,30 +91,30 @@ int dotsPrinted = 0; // Print dots in rows of 50 while waiting for a TIM TM2 mes
// | / _____ You can use any name you like for the struct // | / _____ You can use any name you like for the struct
// | | / // | | /
// | | | // | | |
void printTIMTM2data(UBX_TIM_TM2_data_t ubxDataStruct) void printTIMTM2data(UBX_TIM_TM2_data_t *ubxDataStruct)
{ {
Serial.println(); Serial.println();
Serial.print(F("newFallingEdge: ")); // 1 if a new falling edge was detected Serial.print(F("newFallingEdge: ")); // 1 if a new falling edge was detected
Serial.print(ubxDataStruct.flags.bits.newFallingEdge); Serial.print(ubxDataStruct->flags.bits.newFallingEdge);
Serial.print(F(" newRisingEdge: ")); // 1 if a new rising edge was detected Serial.print(F(" newRisingEdge: ")); // 1 if a new rising edge was detected
Serial.print(ubxDataStruct.flags.bits.newRisingEdge); Serial.print(ubxDataStruct->flags.bits.newRisingEdge);
Serial.print(F(" Rising Edge Counter: ")); // Rising edge counter Serial.print(F(" Rising Edge Counter: ")); // Rising edge counter
Serial.print(ubxDataStruct.count); Serial.print(ubxDataStruct->count);
Serial.print(F(" towMsR: ")); // Time Of Week of rising edge (ms) Serial.print(F(" towMsR: ")); // Time Of Week of rising edge (ms)
Serial.print(ubxDataStruct.towMsR); Serial.print(ubxDataStruct->towMsR);
Serial.print(F(" towSubMsR: ")); // Millisecond fraction of Time Of Week of rising edge in nanoseconds Serial.print(F(" towSubMsR: ")); // Millisecond fraction of Time Of Week of rising edge in nanoseconds
Serial.print(ubxDataStruct.towSubMsR); Serial.print(ubxDataStruct->towSubMsR);
Serial.print(F(" towMsF: ")); // Time Of Week of falling edge (ms) Serial.print(F(" towMsF: ")); // Time Of Week of falling edge (ms)
Serial.print(ubxDataStruct.towMsF); Serial.print(ubxDataStruct->towMsF);
Serial.print(F(" towSubMsF: ")); // Millisecond fraction of Time Of Week of falling edge in nanoseconds Serial.print(F(" towSubMsF: ")); // Millisecond fraction of Time Of Week of falling edge in nanoseconds
Serial.println(ubxDataStruct.towSubMsF); Serial.println(ubxDataStruct->towSubMsF);
dotsPrinted = 0; // Reset dotsPrinted dotsPrinted = 0; // Reset dotsPrinted
} }
@@ -206,10 +205,12 @@ void setup()
myGNSS.setNavigationFrequency(1); //Produce one navigation solution per second myGNSS.setNavigationFrequency(1); //Produce one navigation solution per second
myGNSS.setAutoTIMTM2callback(&printTIMTM2data); // Enable automatic TIM TM2 messages with callback to printTIMTM2data myGNSS.setAutoTIMTM2callbackPtr(&printTIMTM2data); // Enable automatic TIM TM2 messages with callback to printTIMTM2data
myGNSS.logTIMTM2(); // Enable TIM TM2 data logging myGNSS.logTIMTM2(); // Enable TIM TM2 data logging
myBuffer = new uint8_t[packetLength]; // Create our own buffer to hold the data while we write it to SD card
Serial.println(F("Press any key to stop logging.")); Serial.println(F("Press any key to stop logging."));
} }
@@ -220,9 +221,7 @@ void loop()
if (myGNSS.fileBufferAvailable() >= packetLength) // Check to see if a new packetLength-byte TIM TM2 message has been stored if (myGNSS.fileBufferAvailable() >= packetLength) // Check to see if a new packetLength-byte TIM TM2 message has been stored
{ {
uint8_t myBuffer[packetLength]; // Create our own buffer to hold the data while we write it to SD card myGNSS.extractFileBufferData(myBuffer, packetLength); // Extract exactly packetLength bytes from the UBX file buffer and put them into myBuffer
myGNSS.extractFileBufferData((uint8_t *)&myBuffer, packetLength); // Extract exactly packetLength bytes from the UBX file buffer and put them into myBuffer
myFile.write(myBuffer, packetLength); // Write exactly packetLength bytes from myBuffer to the ubxDataFile on the SD card myFile.write(myBuffer, packetLength); // Write exactly packetLength bytes from myBuffer to the ubxDataFile on the SD card
@@ -34,9 +34,7 @@
Insert a formatted micro-SD card into the socket on the Carrier Board. Insert a formatted micro-SD card into the socket on the Carrier Board.
Connect the Carrier Board to your computer using a USB-C cable. Connect the Carrier Board to your computer using a USB-C cable.
Ensure you have the SparkFun Apollo3 boards installed: http://boardsmanager/All#SparkFun_Apollo3 Ensure you have the SparkFun Apollo3 boards installed: http://boardsmanager/All#SparkFun_Apollo3
This code has been tested using version 2.1.0 of the Apollo3 boards on Arduino IDE 1.8.13. This code has been tested using version 2.2.0 of the Apollo3 boards on Arduino IDE 1.8.13.
- Version 2.1.1 of Apollo3 contains a feature which makes I2C communication with u-blox modules problematic
- We recommend using v2.1.0 of Apollo3 until v2.2.0 is released
Select "Artemis MicroMod Processor" as the board type. Select "Artemis MicroMod Processor" as the board type.
Press upload to upload the code onto the Artemis. Press upload to upload the code onto the Artemis.
Open the Serial Monitor at 115200 baud to see the output. Open the Serial Monitor at 115200 baud to see the output.
@@ -76,6 +74,7 @@ File myFile; //File that all GNSS data is written to
#define sdWriteSize 512 // Write data to the SD card in blocks of 512 bytes #define sdWriteSize 512 // Write data to the SD card in blocks of 512 bytes
#define fileBufferSize 16384 // Allocate 16KBytes of RAM for UBX message storage #define fileBufferSize 16384 // Allocate 16KBytes of RAM for UBX message storage
uint8_t *myBuffer; // Use myBuffer to hold the data while we write it to SD card
unsigned long lastPrint; // Record when the last Serial print took place unsigned long lastPrint; // Record when the last Serial print took place
@@ -90,10 +89,10 @@ int numRAWX = 0; // Keep count of how many RAWX message groups have been receive
// See u-blox_structs.h for the full definition of UBX_RXMSFRBX_data_t // See u-blox_structs.h for the full definition of UBX_RXMSFRBX_data_t
// _____ You can use any name you like for the callback. Use the same name when you call setAutoRXMSFRBXcallback // _____ You can use any name you like for the callback. Use the same name when you call setAutoRXMSFRBXcallback
// / _____ This _must_ be UBX_RXM_SFRBX_data_t // / _____ This _must_ be UBX_RXM_SFRBX_data_t
// | / _____ You can use any name you like for the struct // | / _____ You can use any name you like for the struct
// | | / // | | /
// | | | // | | |
void newSFRBX(UBX_RXM_SFRBX_data_t ubxDataStruct) void newSFRBX(UBX_RXM_SFRBX_data_t *ubxDataStruct)
{ {
numSFRBX++; // Increment the count numSFRBX++; // Increment the count
} }
@@ -105,7 +104,7 @@ void newSFRBX(UBX_RXM_SFRBX_data_t ubxDataStruct)
// | / _____ You can use any name you like for the struct // | / _____ You can use any name you like for the struct
// | | / // | | /
// | | | // | | |
void newRAWX(UBX_RXM_RAWX_data_t ubxDataStruct) void newRAWX(UBX_RXM_RAWX_data_t *ubxDataStruct)
{ {
numRAWX++; // Increment the count numRAWX++; // Increment the count
} }
@@ -202,14 +201,16 @@ void setup()
myGNSS.setNavigationFrequency(1); //Produce one navigation solution per second (that's plenty for Precise Point Positioning) myGNSS.setNavigationFrequency(1); //Produce one navigation solution per second (that's plenty for Precise Point Positioning)
myGNSS.setAutoRXMSFRBXcallback(&newSFRBX); // Enable automatic RXM SFRBX messages with callback to newSFRBX myGNSS.setAutoRXMSFRBXcallbackPtr(&newSFRBX); // Enable automatic RXM SFRBX messages with callback to newSFRBX
myGNSS.logRXMSFRBX(); // Enable RXM SFRBX data logging myGNSS.logRXMSFRBX(); // Enable RXM SFRBX data logging
myGNSS.setAutoRXMRAWXcallback(&newRAWX); // Enable automatic RXM RAWX messages with callback to newRAWX myGNSS.setAutoRXMRAWXcallbackPtr(&newRAWX); // Enable automatic RXM RAWX messages with callback to newRAWX
myGNSS.logRXMRAWX(); // Enable RXM RAWX data logging myGNSS.logRXMRAWX(); // Enable RXM RAWX data logging
myBuffer = new uint8_t[sdWriteSize]; // Create our own buffer to hold the data while we write it to SD card
Serial.println(F("Press any key to stop logging.")); Serial.println(F("Press any key to stop logging."));
lastPrint = millis(); // Initialize lastPrint lastPrint = millis(); // Initialize lastPrint
@@ -228,9 +229,7 @@ void loop()
{ {
digitalWrite(LED_BUILTIN, HIGH); // Flash LED_BUILTIN each time we write to the SD card digitalWrite(LED_BUILTIN, HIGH); // Flash LED_BUILTIN each time we write to the SD card
uint8_t myBuffer[sdWriteSize]; // Create our own buffer to hold the data while we write it to SD card myGNSS.extractFileBufferData(myBuffer, sdWriteSize); // Extract exactly sdWriteSize bytes from the UBX file buffer and put them into myBuffer
myGNSS.extractFileBufferData((uint8_t *)&myBuffer, sdWriteSize); // Extract exactly sdWriteSize bytes from the UBX file buffer and put them into myBuffer
myFile.write(myBuffer, sdWriteSize); // Write exactly sdWriteSize bytes from myBuffer to the ubxDataFile on the SD card myFile.write(myBuffer, sdWriteSize); // Write exactly sdWriteSize bytes from myBuffer to the ubxDataFile on the SD card
@@ -273,15 +272,13 @@ void loop()
{ {
digitalWrite(LED_BUILTIN, HIGH); // Flash LED_BUILTIN while we write to the SD card digitalWrite(LED_BUILTIN, HIGH); // Flash LED_BUILTIN while we write to the SD card
uint8_t myBuffer[sdWriteSize]; // Create our own buffer to hold the data while we write it to SD card
uint16_t bytesToWrite = remainingBytes; // Write the remaining bytes to SD card sdWriteSize bytes at a time uint16_t bytesToWrite = remainingBytes; // Write the remaining bytes to SD card sdWriteSize bytes at a time
if (bytesToWrite > sdWriteSize) if (bytesToWrite > sdWriteSize)
{ {
bytesToWrite = sdWriteSize; bytesToWrite = sdWriteSize;
} }
myGNSS.extractFileBufferData((uint8_t *)&myBuffer, bytesToWrite); // Extract bytesToWrite bytes from the UBX file buffer and put them into myBuffer myGNSS.extractFileBufferData(myBuffer, bytesToWrite); // Extract bytesToWrite bytes from the UBX file buffer and put them into myBuffer
myFile.write(myBuffer, bytesToWrite); // Write bytesToWrite bytes from myBuffer to the ubxDataFile on the SD card myFile.write(myBuffer, bytesToWrite); // Write bytesToWrite bytes from myBuffer to the ubxDataFile on the SD card