Skip to content

Commit 5a4ac25

Browse files
committed
Update data logging examples 1-3 to use the new callback pointers
1 parent 0bf94be commit 5a4ac25

File tree

3 files changed

+41
-46
lines changed

3 files changed

+41
-46
lines changed

examples/Data_Logging/DataLoggingExample1_NAV_PVT/DataLoggingExample1_NAV_PVT.ino

+14-15
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
Insert a formatted micro-SD card into the socket on the Carrier Board.
2323
Connect the Carrier Board to your computer using a USB-C cable.
2424
Ensure you have the SparkFun Apollo3 boards installed: http://boardsmanager/All#SparkFun_Apollo3
25-
This code has been tested using version 2.1.0 of the Apollo3 boards on Arduino IDE 1.8.13.
26-
- Version 2.1.1 of Apollo3 contains a feature which makes I2C communication with u-blox modules problematic
27-
- We recommend using v2.1.0 of Apollo3 until v2.2.0 is released
25+
This code has been tested using version 2.2.0 of the Apollo3 boards on Arduino IDE 1.8.13.
2826
Select "Artemis MicroMod Processor" as the board type.
2927
Press upload to upload the code onto the Artemis.
3028
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
6967
#endif
7068

7169
#define packetLength 100 // NAV PVT is 92 + 8 bytes in length (including the sync chars, class, id, length and checksum bytes)
70+
uint8_t *myBuffer; // Use myBuffer to hold the data while we write it to SD card
7271

7372
// Callback: printPVTdata will be called when new NAV PVT data arrives
7473
// 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
7776
// | / _____ You can use any name you like for the struct
7877
// | | /
7978
// | | |
80-
void printPVTdata(UBX_NAV_PVT_data_t ubxDataStruct)
79+
void printPVTdata(UBX_NAV_PVT_data_t *ubxDataStruct)
8180
{
8281
Serial.println();
8382

8483
Serial.print(F("Time: ")); // Print the time
85-
uint8_t hms = ubxDataStruct.hour; // Print the hours
84+
uint8_t hms = ubxDataStruct->hour; // Print the hours
8685
if (hms < 10) Serial.print(F("0")); // Print a leading zero if required
8786
Serial.print(hms);
8887
Serial.print(F(":"));
89-
hms = ubxDataStruct.min; // Print the minutes
88+
hms = ubxDataStruct->min; // Print the minutes
9089
if (hms < 10) Serial.print(F("0")); // Print a leading zero if required
9190
Serial.print(hms);
9291
Serial.print(F(":"));
93-
hms = ubxDataStruct.sec; // Print the seconds
92+
hms = ubxDataStruct->sec; // Print the seconds
9493
if (hms < 10) Serial.print(F("0")); // Print a leading zero if required
9594
Serial.print(hms);
9695
Serial.print(F("."));
97-
unsigned long millisecs = ubxDataStruct.iTOW % 1000; // Print the milliseconds
96+
unsigned long millisecs = ubxDataStruct->iTOW % 1000; // Print the milliseconds
9897
if (millisecs < 100) Serial.print(F("0")); // Print the trailing zeros correctly
9998
if (millisecs < 10) Serial.print(F("0"));
10099
Serial.print(millisecs);
101100

102-
long latitude = ubxDataStruct.lat; // Print the latitude
101+
long latitude = ubxDataStruct->lat; // Print the latitude
103102
Serial.print(F(" Lat: "));
104103
Serial.print(latitude);
105104

106-
long longitude = ubxDataStruct.lon; // Print the longitude
105+
long longitude = ubxDataStruct->lon; // Print the longitude
107106
Serial.print(F(" Long: "));
108107
Serial.print(longitude);
109108
Serial.print(F(" (degrees * 10^-7)"));
110109

111-
long altitude = ubxDataStruct.hMSL; // Print the height above mean sea level
110+
long altitude = ubxDataStruct->hMSL; // Print the height above mean sea level
112111
Serial.print(F(" Height above MSL: "));
113112
Serial.print(altitude);
114113
Serial.println(F(" (mm)"));
@@ -200,10 +199,12 @@ void setup()
200199

201200
myGNSS.setNavigationFrequency(1); //Produce one navigation solution per second
202201

203-
myGNSS.setAutoPVTcallback(&printPVTdata); // Enable automatic NAV PVT messages with callback to printPVTdata
202+
myGNSS.setAutoPVTcallbackPtr(&printPVTdata); // Enable automatic NAV PVT messages with callback to printPVTdata
204203

205204
myGNSS.logNAVPVT(); // Enable NAV PVT data logging
206205

206+
myBuffer = new uint8_t[packetLength]; // Create our own buffer to hold the data while we write it to SD card
207+
207208
Serial.println(F("Press any key to stop logging."));
208209
}
209210

@@ -214,9 +215,7 @@ void loop()
214215

215216
if (myGNSS.fileBufferAvailable() >= packetLength) // Check to see if a new packetLength-byte NAV PVT message has been stored
216217
{
217-
uint8_t myBuffer[packetLength]; // Create our own buffer to hold the data while we write it to SD card
218-
219-
myGNSS.extractFileBufferData((uint8_t *)&myBuffer, packetLength); // Extract exactly packetLength bytes from the UBX file buffer and put them into myBuffer
218+
myGNSS.extractFileBufferData(myBuffer, packetLength); // Extract exactly packetLength bytes from the UBX file buffer and put them into myBuffer
220219

221220
myFile.write(myBuffer, packetLength); // Write exactly packetLength bytes from myBuffer to the ubxDataFile on the SD card
222221

examples/Data_Logging/DataLoggingExample2_TIM_TM2/DataLoggingExample2_TIM_TM2.ino

+14-15
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
Insert a formatted micro-SD card into the socket on the Carrier Board.
2323
Connect the Carrier Board to your computer using a USB-C cable.
2424
Ensure you have the SparkFun Apollo3 boards installed: http://boardsmanager/All#SparkFun_Apollo3
25-
This code has been tested using version 2.1.0 of the Apollo3 boards on Arduino IDE 1.8.13.
26-
- Version 2.1.1 of Apollo3 contains a feature which makes I2C communication with u-blox modules problematic
27-
- We recommend using v2.1.0 of Apollo3 until v2.2.0 is released
25+
This code has been tested using version 2.2.0 of the Apollo3 boards on Arduino IDE 1.8.13.
2826
Select "Artemis MicroMod Processor" as the board type.
2927
Press upload to upload the code onto the Artemis.
3028
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
8280
#endif
8381

8482
#define packetLength 36 // TIM TM2 is 28 + 8 bytes in length (including the sync chars, class, id, length and checksum bytes)
83+
uint8_t *myBuffer; // Use myBuffer to hold the data while we write it to SD card
8584

8685
int dotsPrinted = 0; // Print dots in rows of 50 while waiting for a TIM TM2 message
8786

@@ -92,30 +91,30 @@ int dotsPrinted = 0; // Print dots in rows of 50 while waiting for a TIM TM2 mes
9291
// | / _____ You can use any name you like for the struct
9392
// | | /
9493
// | | |
95-
void printTIMTM2data(UBX_TIM_TM2_data_t ubxDataStruct)
94+
void printTIMTM2data(UBX_TIM_TM2_data_t *ubxDataStruct)
9695
{
9796
Serial.println();
9897

9998
Serial.print(F("newFallingEdge: ")); // 1 if a new falling edge was detected
100-
Serial.print(ubxDataStruct.flags.bits.newFallingEdge);
99+
Serial.print(ubxDataStruct->flags.bits.newFallingEdge);
101100

102101
Serial.print(F(" newRisingEdge: ")); // 1 if a new rising edge was detected
103-
Serial.print(ubxDataStruct.flags.bits.newRisingEdge);
102+
Serial.print(ubxDataStruct->flags.bits.newRisingEdge);
104103

105104
Serial.print(F(" Rising Edge Counter: ")); // Rising edge counter
106-
Serial.print(ubxDataStruct.count);
105+
Serial.print(ubxDataStruct->count);
107106

108107
Serial.print(F(" towMsR: ")); // Time Of Week of rising edge (ms)
109-
Serial.print(ubxDataStruct.towMsR);
108+
Serial.print(ubxDataStruct->towMsR);
110109

111110
Serial.print(F(" towSubMsR: ")); // Millisecond fraction of Time Of Week of rising edge in nanoseconds
112-
Serial.print(ubxDataStruct.towSubMsR);
111+
Serial.print(ubxDataStruct->towSubMsR);
113112

114113
Serial.print(F(" towMsF: ")); // Time Of Week of falling edge (ms)
115-
Serial.print(ubxDataStruct.towMsF);
114+
Serial.print(ubxDataStruct->towMsF);
116115

117116
Serial.print(F(" towSubMsF: ")); // Millisecond fraction of Time Of Week of falling edge in nanoseconds
118-
Serial.println(ubxDataStruct.towSubMsF);
117+
Serial.println(ubxDataStruct->towSubMsF);
119118

120119
dotsPrinted = 0; // Reset dotsPrinted
121120
}
@@ -206,10 +205,12 @@ void setup()
206205

207206
myGNSS.setNavigationFrequency(1); //Produce one navigation solution per second
208207

209-
myGNSS.setAutoTIMTM2callback(&printTIMTM2data); // Enable automatic TIM TM2 messages with callback to printTIMTM2data
208+
myGNSS.setAutoTIMTM2callbackPtr(&printTIMTM2data); // Enable automatic TIM TM2 messages with callback to printTIMTM2data
210209

211210
myGNSS.logTIMTM2(); // Enable TIM TM2 data logging
212211

212+
myBuffer = new uint8_t[packetLength]; // Create our own buffer to hold the data while we write it to SD card
213+
213214
Serial.println(F("Press any key to stop logging."));
214215
}
215216

@@ -220,9 +221,7 @@ void loop()
220221

221222
if (myGNSS.fileBufferAvailable() >= packetLength) // Check to see if a new packetLength-byte TIM TM2 message has been stored
222223
{
223-
uint8_t myBuffer[packetLength]; // Create our own buffer to hold the data while we write it to SD card
224-
225-
myGNSS.extractFileBufferData((uint8_t *)&myBuffer, packetLength); // Extract exactly packetLength bytes from the UBX file buffer and put them into myBuffer
224+
myGNSS.extractFileBufferData(myBuffer, packetLength); // Extract exactly packetLength bytes from the UBX file buffer and put them into myBuffer
226225

227226
myFile.write(myBuffer, packetLength); // Write exactly packetLength bytes from myBuffer to the ubxDataFile on the SD card
228227

examples/Data_Logging/DataLoggingExample3_RXM_SFRBX_and_RAWX/DataLoggingExample3_RXM_SFRBX_and_RAWX.ino

+13-16
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
Insert a formatted micro-SD card into the socket on the Carrier Board.
3535
Connect the Carrier Board to your computer using a USB-C cable.
3636
Ensure you have the SparkFun Apollo3 boards installed: http://boardsmanager/All#SparkFun_Apollo3
37-
This code has been tested using version 2.1.0 of the Apollo3 boards on Arduino IDE 1.8.13.
38-
- Version 2.1.1 of Apollo3 contains a feature which makes I2C communication with u-blox modules problematic
39-
- We recommend using v2.1.0 of Apollo3 until v2.2.0 is released
37+
This code has been tested using version 2.2.0 of the Apollo3 boards on Arduino IDE 1.8.13.
4038
Select "Artemis MicroMod Processor" as the board type.
4139
Press upload to upload the code onto the Artemis.
4240
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
7674

7775
#define sdWriteSize 512 // Write data to the SD card in blocks of 512 bytes
7876
#define fileBufferSize 16384 // Allocate 16KBytes of RAM for UBX message storage
77+
uint8_t *myBuffer; // Use myBuffer to hold the data while we write it to SD card
7978

8079
unsigned long lastPrint; // Record when the last Serial print took place
8180

@@ -90,10 +89,10 @@ int numRAWX = 0; // Keep count of how many RAWX message groups have been receive
9089
// See u-blox_structs.h for the full definition of UBX_RXMSFRBX_data_t
9190
// _____ You can use any name you like for the callback. Use the same name when you call setAutoRXMSFRBXcallback
9291
// / _____ This _must_ be UBX_RXM_SFRBX_data_t
93-
// | / _____ You can use any name you like for the struct
94-
// | | /
95-
// | | |
96-
void newSFRBX(UBX_RXM_SFRBX_data_t ubxDataStruct)
92+
// | / _____ You can use any name you like for the struct
93+
// | | /
94+
// | | |
95+
void newSFRBX(UBX_RXM_SFRBX_data_t *ubxDataStruct)
9796
{
9897
numSFRBX++; // Increment the count
9998
}
@@ -105,7 +104,7 @@ void newSFRBX(UBX_RXM_SFRBX_data_t ubxDataStruct)
105104
// | / _____ You can use any name you like for the struct
106105
// | | /
107106
// | | |
108-
void newRAWX(UBX_RXM_RAWX_data_t ubxDataStruct)
107+
void newRAWX(UBX_RXM_RAWX_data_t *ubxDataStruct)
109108
{
110109
numRAWX++; // Increment the count
111110
}
@@ -202,14 +201,16 @@ void setup()
202201

203202
myGNSS.setNavigationFrequency(1); //Produce one navigation solution per second (that's plenty for Precise Point Positioning)
204203

205-
myGNSS.setAutoRXMSFRBXcallback(&newSFRBX); // Enable automatic RXM SFRBX messages with callback to newSFRBX
204+
myGNSS.setAutoRXMSFRBXcallbackPtr(&newSFRBX); // Enable automatic RXM SFRBX messages with callback to newSFRBX
206205

207206
myGNSS.logRXMSFRBX(); // Enable RXM SFRBX data logging
208207

209-
myGNSS.setAutoRXMRAWXcallback(&newRAWX); // Enable automatic RXM RAWX messages with callback to newRAWX
208+
myGNSS.setAutoRXMRAWXcallbackPtr(&newRAWX); // Enable automatic RXM RAWX messages with callback to newRAWX
210209

211210
myGNSS.logRXMRAWX(); // Enable RXM RAWX data logging
212211

212+
myBuffer = new uint8_t[sdWriteSize]; // Create our own buffer to hold the data while we write it to SD card
213+
213214
Serial.println(F("Press any key to stop logging."));
214215

215216
lastPrint = millis(); // Initialize lastPrint
@@ -228,9 +229,7 @@ void loop()
228229
{
229230
digitalWrite(LED_BUILTIN, HIGH); // Flash LED_BUILTIN each time we write to the SD card
230231

231-
uint8_t myBuffer[sdWriteSize]; // Create our own buffer to hold the data while we write it to SD card
232-
233-
myGNSS.extractFileBufferData((uint8_t *)&myBuffer, sdWriteSize); // Extract exactly sdWriteSize bytes from the UBX file buffer and put them into myBuffer
232+
myGNSS.extractFileBufferData(myBuffer, sdWriteSize); // Extract exactly sdWriteSize bytes from the UBX file buffer and put them into myBuffer
234233

235234
myFile.write(myBuffer, sdWriteSize); // Write exactly sdWriteSize bytes from myBuffer to the ubxDataFile on the SD card
236235

@@ -273,15 +272,13 @@ void loop()
273272
{
274273
digitalWrite(LED_BUILTIN, HIGH); // Flash LED_BUILTIN while we write to the SD card
275274

276-
uint8_t myBuffer[sdWriteSize]; // Create our own buffer to hold the data while we write it to SD card
277-
278275
uint16_t bytesToWrite = remainingBytes; // Write the remaining bytes to SD card sdWriteSize bytes at a time
279276
if (bytesToWrite > sdWriteSize)
280277
{
281278
bytesToWrite = sdWriteSize;
282279
}
283280

284-
myGNSS.extractFileBufferData((uint8_t *)&myBuffer, bytesToWrite); // Extract bytesToWrite bytes from the UBX file buffer and put them into myBuffer
281+
myGNSS.extractFileBufferData(myBuffer, bytesToWrite); // Extract bytesToWrite bytes from the UBX file buffer and put them into myBuffer
285282

286283
myFile.write(myBuffer, bytesToWrite); // Write bytesToWrite bytes from myBuffer to the ubxDataFile on the SD card
287284

0 commit comments

Comments
 (0)