Skip to content

Commit e0e61bb

Browse files
committed
Add support for SEC SIG
1 parent 58d7a1f commit e0e61bb

File tree

6 files changed

+573
-1
lines changed

6 files changed

+573
-1
lines changed
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
/*
2+
Configuring the GNSS to automatically send SEC SIG reports over I2C and display them using a callback
3+
By: Paul Clark
4+
SparkFun Electronics
5+
Date: April 3rd, 2025
6+
License: MIT. See license file for more information.
7+
8+
This example shows how to configure the u-blox GNSS to send SEC SIG reports automatically
9+
and access the data via a callback. No more polling!
10+
11+
Feel like supporting open source hardware?
12+
Buy a board from SparkFun!
13+
ZED-F9P RTK2: https://www.sparkfun.com/products/15136
14+
15+
Hardware Connections:
16+
Plug a Qwiic cable into the GPS and a BlackBoard
17+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
18+
Open the serial monitor at 115200 baud to see the output
19+
*/
20+
21+
#include <Wire.h> //Needed for I2C to GPS
22+
23+
#include <SparkFun_u-blox_GNSS_v3.h> //http://librarymanager/All#SparkFun_u-blox_GNSS_v3
24+
SFE_UBLOX_GNSS myGNSS;
25+
26+
// Callback: newSECSIG will be called when new SEC SIG data arrives
27+
// See u-blox_structs.h for the full definition of UBX_SEC_SIG_data_t
28+
// _____ You can use any name you like for the callback. Use the same name when you call setAutoSECSIGcallback
29+
// / _____ This _must_ be UBX_SEC_SIG_data_t
30+
// | / _____ You can use any name you like for the struct
31+
// | | /
32+
// | | |
33+
void newSECSIG(UBX_SEC_SIG_data_t *ubxDataStruct)
34+
{
35+
Serial.println();
36+
37+
Serial.print(F("New SEC SIG data received. It contains version "));
38+
Serial.print(ubxDataStruct->version);
39+
Serial.println(F(" data."));
40+
41+
if (ubxDataStruct->version == 1)
42+
{
43+
Serial.print(F("Jamming detection is "));
44+
bool jamDetEnabled = (bool)ubxDataStruct->versions.version1.jamFlags.bits.jamDetEnabled;
45+
Serial.println(jamDetEnabled ? "enabled" : "disabled");
46+
if (jamDetEnabled)
47+
{
48+
Serial.print(F("Jamming state: "));
49+
switch (ubxDataStruct->versions.version1.jamFlags.bits.jammingState)
50+
{
51+
case 1:
52+
Serial.println(F("no jamming indicated"));
53+
break;
54+
case 2:
55+
Serial.println(F("warning (jamming indicated but fix OK)"));
56+
break;
57+
case 3:
58+
Serial.println(F("critical (jamming indicated and no fix)"));
59+
break;
60+
case 0:
61+
default:
62+
Serial.println(F("unknown"));
63+
break;
64+
}
65+
}
66+
Serial.print(F("Spoofing detection is "));
67+
bool spfDetEnabled = (bool)ubxDataStruct->versions.version1.spfFlags.bits.spfDetEnabled;
68+
Serial.println(spfDetEnabled ? "enabled" : "disabled");
69+
if (spfDetEnabled)
70+
{
71+
Serial.print(F("Spoofing state: "));
72+
switch (ubxDataStruct->versions.version1.spfFlags.bits.spoofingState)
73+
{
74+
case 1:
75+
Serial.println(F("no spoofing indicated"));
76+
break;
77+
case 2:
78+
Serial.println(F("spoofing indicated"));
79+
break;
80+
case 3:
81+
Serial.println(F("spoofing affirmed"));
82+
break;
83+
case 0:
84+
default:
85+
Serial.println(F("unknown"));
86+
break;
87+
}
88+
}
89+
}
90+
91+
else if (ubxDataStruct->version == 2)
92+
{
93+
Serial.print(F("Jamming detection is "));
94+
bool jamDetEnabled = (bool)ubxDataStruct->versions.version2.sigSecFlags.bits.jamDetEnabled;
95+
Serial.println(jamDetEnabled ? "enabled" : "disabled");
96+
if (jamDetEnabled)
97+
{
98+
Serial.print(F("Jamming state: "));
99+
switch (ubxDataStruct->versions.version2.sigSecFlags.bits.jamState)
100+
{
101+
case 1:
102+
Serial.println(F("no jamming indicated"));
103+
break;
104+
case 2:
105+
Serial.println(F("warning (jamming indicated)"));
106+
break;
107+
case 0:
108+
default:
109+
Serial.println(F("unknown"));
110+
break;
111+
}
112+
}
113+
Serial.print(F("Spoofing detection is "));
114+
bool spfDetEnabled = (bool)ubxDataStruct->versions.version2.sigSecFlags.bits.spfDetEnabled;
115+
Serial.println(spfDetEnabled ? "enabled" : "disabled");
116+
if (spfDetEnabled)
117+
{
118+
Serial.print(F("Spoofing state: "));
119+
switch (ubxDataStruct->versions.version2.sigSecFlags.bits.spfState)
120+
{
121+
case 1:
122+
Serial.println(F("no spoofing indicated"));
123+
break;
124+
case 2:
125+
Serial.println(F("spoofing indicated"));
126+
break;
127+
case 3:
128+
Serial.println(F("spoofing affirmed"));
129+
break;
130+
case 0:
131+
default:
132+
Serial.println(F("unknown"));
133+
break;
134+
}
135+
}
136+
Serial.print(F("Number of jamming center frequencies: "));
137+
uint8_t jamNumCentFreqs = ubxDataStruct->versions.version2.jamNumCentFreqs;
138+
Serial.println(jamNumCentFreqs);
139+
if (jamNumCentFreqs > 0)
140+
{
141+
for (uint8_t i = 0; i < jamNumCentFreqs; i++)
142+
{
143+
Serial.print(F("Center frequency: "));
144+
Serial.print(ubxDataStruct->versions.version2.jamStateCentFreq[i].bits.centFreq);
145+
Serial.print(F(" kHz "));
146+
if (ubxDataStruct->versions.version2.jamStateCentFreq[i].bits.jammed)
147+
Serial.print("- jammed");
148+
Serial.println();
149+
}
150+
}
151+
}
152+
}
153+
154+
void setup()
155+
{
156+
Serial.begin(115200);
157+
while (!Serial); //Wait for user to open terminal
158+
Serial.println("SparkFun u-blox Example");
159+
160+
Wire.begin();
161+
162+
//myGNSS.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
163+
//myGNSS.enableDebugging(Serial, true); // Uncomment this line to enable only the major debug messages on Serial
164+
165+
while (myGNSS.begin() == false) //Connect to the u-blox module using Wire port
166+
{
167+
Serial.println(F("u-blox GNSS not detected at default I2C address. Please check wiring."));
168+
}
169+
170+
myGNSS.setI2COutput(COM_TYPE_UBX); //Set the I2C port to output UBX only. Stop the NMEA messages
171+
myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR
172+
173+
// Just to prove we can, poll the SEC SIG data manually
174+
Serial.println("Polling SEC SIG data:");
175+
UBX_SEC_SIG_data_t secSig;
176+
if (myGNSS.getSECSIG(&secSig))
177+
newSECSIG(&secSig); // Call the callback manually to print the data
178+
else
179+
Serial.println("getSECSIG failed!");
180+
181+
// Now enable automatic (periodic) SEC SIG messages with callback to newSECSIG
182+
myGNSS.setAutoSECSIGcallbackPtr(&newSECSIG);
183+
}
184+
185+
void loop()
186+
{
187+
myGNSS.checkUblox(); // Check for the arrival of new data and process it.
188+
myGNSS.checkCallbacks(); // Check if any callbacks are waiting to be processed.
189+
190+
Serial.print(".");
191+
delay(50);
192+
}

keywords.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,14 @@ assumeAutoHNRPVT KEYWORD2
620620
flushHNRPVT KEYWORD2
621621
logHNRPVT KEYWORD2
622622

623+
getSECSIG KEYWORD2
624+
setAutoSECSIG KEYWORD2
625+
setAutoSECSIGrate KEYWORD2
626+
setAutoSECSIGcallbackPtr KEYWORD2
627+
assumeAutoSECSIG KEYWORD2
628+
flushSECSIG KEYWORD2
629+
logSECSIG KEYWORD2
630+
623631
setNavigationFrequency KEYWORD2
624632
getNavigationFrequency KEYWORD2
625633
setMeasurementRate KEYWORD2

src/u-blox_Class_and_ID.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ const uint8_t UBX_RXM_SPARTNKEY = 0x36; // Poll/transfer dynamic SPARTN keys
290290

291291
// Class: SEC
292292
// The following are used to configure the SEC UBX messages (security feature messages). Descriptions from UBX messages overview (ZED_F9P Interface Description Document page 36)
293+
const uint8_t UBX_SEC_SIG = 0x09; // Signal security information
293294
const uint8_t UBX_SEC_UNIQID = 0x03; // Unique chip ID
294295

295296
// Class: TIM

0 commit comments

Comments
 (0)