Skip to content

Commit b3aab36

Browse files
committed
Add callback Example6 - RAWX. Note:
PR (pseudorange) and CP (carrier phase) will only be displayed if your processor supports 64-bit double
1 parent d8d4313 commit b3aab36

File tree

2 files changed

+108
-1
lines changed

2 files changed

+108
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
Configuring the GNSS to automatically send RXM RZWX reports over I2C and display them using a callback
3+
By: Paul Clark
4+
SparkFun Electronics
5+
Date: March 11th, 2021
6+
License: MIT. See license file for more information but you can
7+
basically do whatever you want with this code.
8+
9+
This example shows how to configure the u-blox GNSS to send RXM RAWX reports automatically
10+
and access the data via a callback. No more polling!
11+
12+
Feel like supporting open source hardware?
13+
Buy a board from SparkFun!
14+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
15+
16+
Hardware Connections:
17+
Plug a Qwiic cable into the GPS and a BlackBoard
18+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
19+
Open the serial monitor at 115200 baud to see the output
20+
*/
21+
22+
#include <Wire.h> //Needed for I2C to GPS
23+
24+
#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS
25+
SFE_UBLOX_GNSS myGNSS;
26+
27+
// Callback: newRAWX will be called when new RXM RAWX data arrives
28+
// See u-blox_structs.h for the full definition of UBX_RXMRAWX_data_t
29+
// _____ You can use any name you like for the callback. Use the same name when you call setAutoRXMRAWXcallback
30+
// / _____ This _must_ be UBX_RXM_RAWX_data_t
31+
// | / _____ You can use any name you like for the struct
32+
// | | /
33+
// | | |
34+
void newRAWX(UBX_RXM_RAWX_data_t ubxDataStruct)
35+
{
36+
Serial.println();
37+
38+
Serial.print(F("New RAWX data received. It contains "));
39+
Serial.print(ubxDataStruct.header.numMeas); // Print numMeas (Number of measurements / blocks)
40+
Serial.println(F(" data blocks:"));
41+
42+
for (uint8_t block = 0; block < ubxDataStruct.header.numMeas; block++) // For each block
43+
{
44+
Serial.print(F("GNSS ID: "));
45+
if (ubxDataStruct.blocks[block].gnssId < 100) Serial.print(F(" ")); // Align the gnssId
46+
if (ubxDataStruct.blocks[block].gnssId < 10) Serial.print(F(" ")); // Align the gnssId
47+
Serial.print(ubxDataStruct.blocks[block].gnssId);
48+
Serial.print(F(" SV ID: "));
49+
if (ubxDataStruct.blocks[block].svId < 100) Serial.print(F(" ")); // Align the svId
50+
if (ubxDataStruct.blocks[block].svId < 10) Serial.print(F(" ")); // Align the svId
51+
Serial.print(ubxDataStruct.blocks[block].svId);
52+
53+
if (sizeof(double) == 8) // Check if our processor supports 64-bit double
54+
{
55+
// Convert prMes from uint8_t[8] to 64-bit double
56+
// prMes is little-endian
57+
double pseudorange;
58+
memcpy(&pseudorange, &ubxDataStruct.blocks[block].prMes, 8);
59+
Serial.print(F(" PR: "));
60+
Serial.print(pseudorange, 3);
61+
62+
// Convert cpMes from uint8_t[8] to 64-bit double
63+
// cpMes is little-endian
64+
double carrierPhase;
65+
memcpy(&carrierPhase, &ubxDataStruct.blocks[block].cpMes, 8);
66+
Serial.print(F(" m CP: "));
67+
Serial.print(carrierPhase, 3);
68+
Serial.print(F(" cycles"));
69+
}
70+
Serial.println();
71+
}
72+
}
73+
74+
void setup()
75+
{
76+
Serial.begin(115200);
77+
while (!Serial); //Wait for user to open terminal
78+
Serial.println("SparkFun u-blox Example");
79+
80+
Wire.begin();
81+
82+
//myGNSS.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
83+
84+
myGNSS.disableUBX7Fcheck(); // RAWX data can legitimately contain 0x7F, so we need to disable the "7F" check in checkUbloxI2C
85+
86+
if (myGNSS.begin() == false) //Connect to the u-blox module using Wire port
87+
{
88+
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring. Freezing."));
89+
while (1);
90+
}
91+
92+
myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only (turn off NMEA noise)
93+
myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR
94+
95+
myGNSS.setNavigationFrequency(1); //Produce one solution per second (RAWX produces a _lot_ of data!)
96+
97+
myGNSS.setAutoRXMRAWXcallback(&newRAWX); // Enable automatic RXM RAWX messages with callback to newRAWX
98+
}
99+
100+
void loop()
101+
{
102+
myGNSS.checkUblox(); // Check for the arrival of new data and process it.
103+
myGNSS.checkCallbacks(); // Check if any callbacks are waiting to be processed.
104+
105+
Serial.print(".");
106+
delay(50);
107+
}

src/u-blox_structs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ typedef struct
10521052
uint8_t rcvTow[8]; // Measurement time of week in receiver local time [64-bit float]
10531053
uint16_t week; // GPS week number
10541054
int8_t leapS; // GPS leap seconds
1055-
uint8_t numMeas; // Numnber of measurements to follow
1055+
uint8_t numMeas; // Number of measurements to follow
10561056
union
10571057
{
10581058
uint8_t all;

0 commit comments

Comments
 (0)