Skip to content

Commit 05854eb

Browse files
committed
Add UBX-RXM-COR to Example18 - to show encryption/decryption
1 parent e35376f commit 05854eb

File tree

1 file changed

+145
-4
lines changed

1 file changed

+145
-4
lines changed

examples/ZED-F9P/Example18_PointPerfectClient/Example18_PointPerfectClient.ino

Lines changed: 145 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,135 @@
4545
#include <SparkFun_u-blox_GNSS_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_u-blox_GNSS
4646
SFE_UBLOX_GNSS myGNSS;
4747

48-
//Global variables
4948
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
49+
50+
//Global variables
51+
5052
long lastReceived_ms = 0; //5 RTCM messages take approximately ~300ms to arrive at 115200bps
5153
int maxTimeBeforeHangup_ms = 10000; //If we fail to get a complete RTCM frame after 10s, then disconnect from caster
54+
55+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
56+
57+
// Callback: printPVTdata will be called when new NAV PVT data arrives
58+
// See u-blox_structs.h for the full definition of UBX_NAV_PVT_data_t
59+
// _____ You can use any name you like for the callback. Use the same name when you call setAutoPVTcallbackPtr
60+
// / _____ This _must_ be UBX_NAV_PVT_data_t
61+
// | / _____ You can use any name you like for the struct
62+
// | | /
63+
// | | |
64+
void printPVTdata(UBX_NAV_PVT_data_t *ubxDataStruct)
65+
{
66+
double latitude = ubxDataStruct->lat; // Print the latitude
67+
Serial.print(F("Lat: "));
68+
Serial.print(latitude / 10000000.0, 7);
69+
70+
double longitude = ubxDataStruct->lon; // Print the longitude
71+
Serial.print(F(" Long: "));
72+
Serial.print(longitude / 10000000.0, 7);
73+
74+
double altitude = ubxDataStruct->hMSL; // Print the height above mean sea level
75+
Serial.print(F(" Height: "));
76+
Serial.print(altitude / 1000.0, 3);
77+
78+
uint8_t fixType = ubxDataStruct->fixType; // Print the fix type
79+
Serial.print(F(" Fix: "));
80+
Serial.print(fixType);
81+
if (fixType == 0)
82+
Serial.print(F(" (None)"));
83+
else if (fixType == 1)
84+
Serial.print(F(" (Dead Reckoning)"));
85+
else if (fixType == 2)
86+
Serial.print(F(" (2D)"));
87+
else if (fixType == 3)
88+
Serial.print(F(" (3D)"));
89+
else if (fixType == 3)
90+
Serial.print(F(" (GNSS + Dead Reckoning)"));
91+
else if (fixType == 5)
92+
Serial.print(F(" (Time Only)"));
93+
else
94+
Serial.print(F(" (UNKNOWN)"));
95+
96+
uint8_t carrSoln = ubxDataStruct->flags.bits.carrSoln; // Print the carrier solution
97+
Serial.print(F(" Carrier Solution: "));
98+
Serial.print(carrSoln);
99+
if (carrSoln == 0)
100+
Serial.print(F(" (None)"));
101+
else if (carrSoln == 1)
102+
Serial.print(F(" (Floating)"));
103+
else if (carrSoln == 2)
104+
Serial.print(F(" (Fixed)"));
105+
else
106+
Serial.print(F(" (UNKNOWN)"));
107+
108+
uint32_t hAcc = ubxDataStruct->hAcc; // Print the horizontal accuracy estimate
109+
Serial.print(F(" Horizontal Accuracy Estimate: "));
110+
Serial.print(hAcc);
111+
Serial.print(F(" (mm)"));
112+
113+
Serial.println();
114+
}
115+
116+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
117+
118+
// Callback: printRXMCOR will be called when new RXM COR data arrives
119+
// See u-blox_structs.h for the full definition of UBX_RXM_COR_data_t
120+
// _____ You can use any name you like for the callback. Use the same name when you call setRXMCORcallbackPtr
121+
// / _____ This _must_ be UBX_RXM_COR_data_t
122+
// | / _____ You can use any name you like for the struct
123+
// | | /
124+
// | | |
125+
void printRXMCOR(UBX_RXM_COR_data_t *ubxDataStruct)
126+
{
127+
Serial.print(F("UBX-RXM-COR: ebno: "));
128+
Serial.print(ubxDataStruct->ebno);
129+
130+
Serial.print(F(" protocol: "));
131+
if (ubxDataStruct->statusInfo.bits.protocol == 1)
132+
Serial.print(F("RTCM3"));
133+
else if (ubxDataStruct->statusInfo.bits.protocol == 2)
134+
Serial.print(F("SPARTN"));
135+
else if (ubxDataStruct->statusInfo.bits.protocol == 29)
136+
Serial.print(F("PMP (SPARTN)"));
137+
else if (ubxDataStruct->statusInfo.bits.protocol == 30)
138+
Serial.print(F("QZSSL6"));
139+
else
140+
Serial.print(F("Unknown"));
141+
142+
Serial.print(F(" errStatus: "));
143+
if (ubxDataStruct->statusInfo.bits.errStatus == 1)
144+
Serial.print(F("Error-free"));
145+
else if (ubxDataStruct->statusInfo.bits.errStatus == 2)
146+
Serial.print(F("Erroneous"));
147+
else
148+
Serial.print(F("Unknown"));
149+
150+
Serial.print(F(" msgUsed: "));
151+
if (ubxDataStruct->statusInfo.bits.msgUsed == 1)
152+
Serial.print(F("Not used"));
153+
else if (ubxDataStruct->statusInfo.bits.msgUsed == 2)
154+
Serial.print(F("Used"));
155+
else
156+
Serial.print(F("Unknown"));
157+
158+
Serial.print(F(" msgEncrypted: "));
159+
if (ubxDataStruct->statusInfo.bits.msgEncrypted == 1)
160+
Serial.print(F("Not encrypted"));
161+
else if (ubxDataStruct->statusInfo.bits.msgEncrypted == 2)
162+
Serial.print(F("Encrypted"));
163+
else
164+
Serial.print(F("Unknown"));
165+
166+
Serial.print(F(" msgDecrypted: "));
167+
if (ubxDataStruct->statusInfo.bits.msgDecrypted == 1)
168+
Serial.print(F("Not decrypted"));
169+
else if (ubxDataStruct->statusInfo.bits.msgDecrypted == 2)
170+
Serial.print(F("Successfully decrypted"));
171+
else
172+
Serial.print(F("Unknown"));
173+
174+
Serial.println();
175+
}
176+
52177
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
53178

54179
void setup()
@@ -59,6 +184,8 @@ void setup()
59184

60185
Wire.begin(); //Start I2C
61186

187+
//myGNSS.enableDebugging(); // Uncomment this line to enable debug messages on Serial
188+
62189
if (myGNSS.begin() == false) //Connect to the Ublox module using Wire port
63190
{
64191
Serial.println(F("u-blox GPS not detected at default I2C address. Please check wiring. Freezing."));
@@ -73,6 +200,11 @@ void setup()
73200
myGNSS.setNavigationFrequency(1); //Set output in Hz.
74201
myGNSS.setVal8(UBLOX_CFG_SPARTN_USE_SOURCE, 0); // Use IP source (default). Change this to 1 for L-Band (PMP)
75202

203+
myGNSS.setAutoPVTcallbackPtr(&printPVTdata); // Enable automatic NAV PVT messages with callback to printPVTdata so we can watch the carrier solution go to fixed
204+
205+
myGNSS.setVal8(UBLOX_CFG_MSGOUT_UBX_RXM_COR_I2C, 1); // Enable UBX-RXM-COR messages on I2C
206+
myGNSS.setRXMCORcallbackPtr(&printRXMCOR); // Print the contents of UBX-RXM-COR messages so we can check if the SPARTN data is being decrypted successfully
207+
76208
Serial.print(F("Connecting to local WiFi"));
77209
WiFi.begin(ssid, password);
78210
while (WiFi.status() != WL_CONNECTED) {
@@ -85,19 +217,24 @@ void setup()
85217
Serial.println(WiFi.localIP());
86218

87219
while (Serial.available()) Serial.read();
220+
221+
Serial.println(F("Press any key to start MQTT/SPARTN Client."));
222+
88223
}
89224

90225
void loop()
91226
{
92227
if (Serial.available())
93228
{
94229
beginClient();
230+
95231
while (Serial.available()) Serial.read(); //Empty buffer of any newline chars
232+
233+
Serial.println(F("Press any key to start MQTT/SPARTN Client."));
96234
}
97235

98-
Serial.println(F("Press any key to start MQTT/SPARTN Client."));
99-
100-
delay(1000);
236+
myGNSS.checkUblox(); // Check for the arrival of new GNSS data and process it.
237+
myGNSS.checkCallbacks(); // Check if any GNSS callbacks are waiting to be processed.
101238
}
102239

103240
WiFiClientSecure wifiClient = WiFiClientSecure();
@@ -163,6 +300,7 @@ void beginClient()
163300
else {
164301
mqttClient.poll();
165302
}
303+
166304
//Close socket if we don't have new data for 10s
167305
if (millis() - lastReceived_ms > maxTimeBeforeHangup_ms)
168306
{
@@ -172,6 +310,9 @@ void beginClient()
172310
return;
173311
}
174312

313+
myGNSS.checkUblox(); // Check for the arrival of new GNSS data and process it.
314+
myGNSS.checkCallbacks(); // Check if any GNSS callbacks are waiting to be processed.
315+
175316
delay(10);
176317
}
177318

0 commit comments

Comments
 (0)