Skip to content

Commit d014318

Browse files
committed
Add readNavigationDatabase. Update the AssistNow Autonomous example.
1 parent 33b8e1d commit d014318

File tree

7 files changed

+441
-24
lines changed

7 files changed

+441
-24
lines changed

Theory.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ When the user calls one of the methods the library will poll the u-blox module f
55
* Wait for a minimum of 25 ms between polls (configured dynamically when update rate is set)
66
* Write 0xFD to module
77
* Read two bytes (0xFD and 0xFE) for bytes available
8-
* If 0x7F or 0xFF then no bytes are available
98
* Otherwise, read number of bytes and process into NMEA, UBX, or RTCM frame.
109
* If checksum is valid, flag frame as complete.
1110

@@ -58,6 +57,7 @@ In v2.0, the full list of messages which can be processed and logged automatical
5857
- UBX-NAV-CLOCK (0x01 0x22): Clock solution
5958
- UBX-NAV-SVIN (0x01 0x3B): Survey-in data (**only with High Precision GNSS products**)
6059
- UBX-NAV-RELPOSNED (0x01 0x3C): Relative positioning information in NED frame (**only with High Precision GNSS products**)
60+
- UBX-NAV-AOPSTATUS (0x01 0x60): AssistNow Autonomous status
6161
- UBX-RXM-SFRBX (0x02 0x13): Broadcast navigation data subframe
6262
- UBX-RXM-RAWX (0x02 0x15): Multi-GNSS raw measurement data (**only with ADR or High Precision GNSS or Time Sync products**)
6363
- UBX-TIM-TM2 (0x0D 0x03): Time mark data

examples/AssistNow/AssistNow_Autonomous/Example1_AssistNowAutonomous_Read/Example1_AssistNowAutonomous_Read.ino

+65-9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
88
This example shows how to enable, check the status of, and read the AssistNow Autonomous data from the module.
99
10+
Note: this example will only work on boards which have plenty of RAM available.
11+
The database can be several kBytes in length and needs to be stored twice:
12+
once inside the library (by readNavigationDatabase); and again in this example code.
13+
1014
Feel like supporting open source hardware?
1115
Buy a board from SparkFun!
1216
SparkFun Thing Plus - ESP32 WROOM: https://www.sparkfun.com/products/15663
@@ -49,6 +53,8 @@ void setup()
4953

5054
myGNSS.setI2COutput(COM_TYPE_UBX); //Turn off NMEA noise
5155

56+
//myGNSS.enableDebugging(Serial, true); // Uncomment this line to see helpful debug messages on Serial
57+
5258
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
5359
// Enable AssistNow Autonomous data collection.
5460

@@ -63,35 +69,85 @@ void setup()
6369
}
6470

6571
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
66-
// Keep calling getAOPSTATUSstatus until it returns zero (indicating AssistNow Autonomous data collection si complete)
72+
// Keep calling getAOPSTATUSstatus until it returns zero (indicating AssistNow Autonomous data collection is complete)
6773
// or the user presses a key
6874

6975
Serial.println(F("AssistNow Autonomous data collection is in progress. Press any key to quit."));
76+
Serial.println(F("NAV AOPSTATUS status indicates when the AssistNow Autonomous subsystem is idle (0) or running (not 0)."));
7077

7178
bool keepGoing = true;
79+
int zerosSeen = 0; // Keep track of how many times aopStatus has been zero
7280
while (Serial.available()) Serial.read(); // Empty the serial buffer
7381

74-
while (keepGoing && !Serial.available()); // Wait keepGoing to go false, or for the arrival of a keypress
82+
while (keepGoing && !Serial.available()) // Wait for keepGoing to go false, or for the arrival of a keypress
7583
{
7684
delay(1000);
77-
Serial.print(F("NAV AOPSTATUS status is: "));
7885
uint8_t aopStatus = myGNSS.getAOPSTATUSstatus();
79-
Serial.print(aopStatus);
80-
Serial.println(F(". (Don't worry! This could take a _long_ time...)"));
86+
Serial.print(F("NAV AOPSTATUS status is: "));
87+
Serial.println(aopStatus);
8188
if (aopStatus == 0) // aopStatus will be zero when the AssistNow Autonomous subsystem is idle - i.e. data collection is complete
82-
keepGoing = false;
89+
{
90+
zerosSeen++; // Keep track of how long aopStatus has been zero
91+
if (zerosSeen >= 30)
92+
keepGoing = false; // Stop after seeing 30 consecutive zeros
93+
}
94+
else
95+
{
96+
zerosSeen = 0; // Reset the number of zeros seen
97+
}
8398
}
8499

85100
if (!keepGoing)
86-
Serial.print(F("AssistNow Autonomous data collection is complete!"));
101+
Serial.println(F("AssistNow Autonomous data collection is complete!"));
87102

88103
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
89-
// Read the AssistNow Autonomous data from the module and pretty-print it (so it can be copied and pasted into Example2)
104+
// Read the AssistNow Autonomous data from the module and pretty-print it (so it can be copied and pasted into Example2)
105+
106+
#define MAX_DATABASE_LENGTH 32768 // Allocate 32kBytes to store the navigation database
107+
size_t maxDatabaseLen = MAX_DATABASE_LENGTH;
108+
uint8_t *database = new uint8_t[MAX_DATABASE_LENGTH]; // The database will be stored here
109+
110+
Serial.println(F("Storage has been allocated for the database.")); Serial.flush();
111+
112+
size_t actualDatabaseLen = myGNSS.readNavigationDatabase(database, maxDatabaseLen); // Read the database
113+
114+
Serial.print(F("The Navigation Database length was "));
115+
Serial.println(actualDatabaseLen);
116+
117+
if (actualDatabaseLen == maxDatabaseLen)
118+
Serial.println(F("There was not enough memory to store the entire database. Some data will have been lost!"));
119+
120+
// Pretty-print the database so it can be copied into Example2
121+
Serial.println(F("Copy and paste the following into Example2, so you can write it back to the module:"));
122+
Serial.println();
123+
Serial.print(F("size_t databaseLen = "));
124+
Serial.print(actualDatabaseLen);
125+
Serial.println(F(";"));
126+
Serial.print(F("const uint8_t database["));
127+
Serial.print(actualDatabaseLen);
128+
Serial.println(F("] = {"));
129+
size_t i;
130+
for(i = 0; i < actualDatabaseLen; i++)
131+
{
132+
if ((i % 32) == 0)
133+
Serial.print(F(" 0x"));
134+
if (*(database + i) < 0x10) // Print leading zero
135+
Serial.print(F("0"));
136+
Serial.print(*(database + i), HEX);
137+
if (i == (actualDatabaseLen - 1))
138+
Serial.println();
139+
else if ((i % 32) == 31)
140+
Serial.println(F(","));
141+
else
142+
Serial.print(F(", 0x"));
143+
}
144+
Serial.println(F("};"));
90145

91146
}
92147

93148
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
94149

95150
void loop()
96151
{
97-
}
152+
// Nothing to do here
153+
}

examples/AssistNow/README.md

+30
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,33 @@ AssistNow Autonomous is disabled by default. You can enable it by calling ```set
174174

175175
* set ```aopCfg``` to 1 to enable AssistNow Autonomous, or 0 to disable it
176176
* ```aopOrbMaxErr``` is used to set the 'lifetime' of the AssistNow data. It is recommended to set aopOrbMaxErr to 0 (the default value). This instructs the module to use the firmware default value that corresponds to a default orbit data validity of approximately three days (for GPS satellites observed once) and up to six days (for GPS and GLONASS satellites observed multiple times over a period of at least half a day).
177+
178+
Once AssistNow Autonomous is enabled, you can monitor its progress via the ```status``` field in the UBX-NAV-AOPSTATUS message. You can read the ```status``` by calling ```getAOPSTATUSstatus```. It will return zero when the AssistNow Autonomous data collection is complete. Non-zero values indicate that data collection is still in progress.
179+
180+
* <b>uint8_t getAOPSTATUSstatus(uint16_t maxWait);</b>
181+
* <b>uint8_t getAOPSTATUSuseAOP(uint16_t maxWait);</b>
182+
183+
We have included full 'auto' support for UBX-NAV-AOPSTATUS, so you can have the message delivered periodically, add a callback for it, and/or log it to the file buffer:
184+
185+
* <b>bool getAOPSTATUS(uint16_t maxWait);</b>
186+
* <b>bool setAutoAOPSTATUS(bool enabled, uint16_t maxWait);</b>
187+
* <b>bool setAutoAOPSTATUS(bool enabled, bool implicitUpdate, uint16_t maxWait);</b>
188+
* <b>bool setAutoAOPSTATUSrate(uint8_t rate, bool implicitUpdate, uint16_t maxWait);</b>
189+
* <b>bool setAutoAOPSTATUScallback(void (*callbackPointer)(UBX_NAV_AOPSTATUS_data_t), uint16_t maxWait);</b>
190+
* <b>bool assumeAutoAOPSTATUS(bool enabled, bool implicitUpdate);</b>
191+
* <b>void flushAOPSTATUS();</b>
192+
* <b>void logNAVAOPSTATUS(bool enabled);</b>
193+
194+
The AssistNow Autonomous data is stored in the module's RAM memory. If that RAM is Battery-Backed - all SparkFun GNSS boards include battery back-up - then the data will be available after the module is powered down and powered back up again. However, you can also read (poll) the navigation database and store the contents in processor memory. ```readNavigationDatabase``` allows you to do that:
195+
196+
* <b>size_t readNavigationDatabase(uint8_t *dataBytes, size_t maxNumDataBytes, uint16_t maxWait);</b>
197+
198+
Data is written to ```dataBytes```. Set ```maxNumDataBytes``` to the (maximum) size of dataBytes. If the database exceeds maxNumDataBytes, the excess bytes will be lost.
199+
200+
```readNavigationDatabase``` returns the number of database bytes written to ```dataBytes```. The return value will be equal to ```maxNumDataBytes``` if excess data was received.
201+
202+
```readNavigationDatabase``` will timeout after ```maxWait``` milliseconds - in case the final UBX-MGA-ACK was missed.
203+
204+
You can then write the database back into the module using ```pushAssistNowData```. Don't forget to call ```setUTCTimeAssistance``` _before_ ```pushAssistNowData```.
205+
206+
Note: UBX-MGA-DBD messages are only intended to be sent back to the same receiver that generated them. They are firmware-specific.

keywords.txt

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ setUTCTimeAssistance KEYWORD2
9595
setPositionAssistanceXYZ KEYWORD2
9696
setPositionAssistanceLLH KEYWORD2
9797
findMGAANOForDate KEYWORD2
98+
readNavigationDatabase KEYWORD2
9899

99100
setFileBufferSize KEYWORD2
100101
getFileBufferSize KEYWORD2

0 commit comments

Comments
 (0)