Skip to content

Commit bedd4cc

Browse files
committed
Add full auto support for NAV SVIN
1 parent 57f4189 commit bedd4cc

5 files changed

+172
-16
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ v2.1 of the library adds support for u-blox AssistNow<sup>TM</sup> Assisted GNSS
4848
This library is the new and improved version of the very popular SparkFun u-blox GNSS Arduino Library. v2.0 contains some big changes and improvements:
4949

5050
* Seamless support for "automatic" message delivery:
51-
* In v1.8, you could ask for the NAV PVT (Navigation Position Velocity Time) message to be delivered _automatically_, without polling. v2.0 adds automatic support for [**26 messages**](./Theory.md#auto-messages), covering the full range of: standard and High Precision position, velocity, attitude and time information; relative positioning; event capture with nanosecond time resolution; raw GNSS signal data including carrier phase; Sensor Fusion; and High Navigation Rate data.
51+
* In v1.8, you could ask for the NAV PVT (Navigation Position Velocity Time) message to be delivered _automatically_, without polling. v2.0 adds automatic support for [**27 messages**](./Theory.md#auto-messages), covering the full range of: standard and High Precision position, velocity, attitude and time information; relative positioning; event capture with nanosecond time resolution; raw GNSS signal data including carrier phase; Sensor Fusion; and High Navigation Rate data.
5252
* Don't see the message you really need? [Adding_New_Messages](./Adding_New_Messages.md) provides details on how to add "auto" support for your favourite message.
5353
* Dynamic memory allocation with clearly-defined data storage structs for each message:
5454
* There are no static 'global' variables to eat up your RAM. v2.0 automatically allocates memory for the automatic messages when they are enabled. You may find your total RAM use is lower with v2.0 than with v1.8.

keywords.txt

+6
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,12 @@ getCurrentLeapSeconds KEYWORD2
359359
initPacketUBXNAVTIMELS KEYWORD2
360360

361361
getSurveyStatus KEYWORD2
362+
setAutoNAVSVIN KEYWORD2
363+
setAutoNAVSVINrate KEYWORD2
364+
setAutoNAVSVINcallbackPtr KEYWORD2
365+
assumeAutoNAVSVIN KEYWORD2
366+
flushNAVSVIN KEYWORD2
367+
logNAVSVIN KEYWORD2
362368
initPacketUBXNAVSVIN KEYWORD2
363369

364370
getNAVSAT KEYWORD2

src/SparkFun_u-blox_GNSS_Arduino_Library.cpp

+156-11
Original file line numberDiff line numberDiff line change
@@ -3588,6 +3588,20 @@ void SFE_UBLOX_GNSS::processUBXpacket(ubxPacket *msg)
35883588

35893589
// Mark all datums as fresh (not read before)
35903590
packetUBXNAVSVIN->moduleQueried.moduleQueried.all = 0xFFFFFFFF;
3591+
3592+
// Check if we need to copy the data for the callback
3593+
if ((packetUBXNAVSVIN->callbackData != NULL) // If RAM has been allocated for the copy of the data
3594+
&& (packetUBXNAVSVIN->automaticFlags.flags.bits.callbackCopyValid == false)) // AND the data is stale
3595+
{
3596+
memcpy(&packetUBXNAVSVIN->callbackData->version, &packetUBXNAVSVIN->data.version, sizeof(UBX_NAV_SVIN_data_t));
3597+
packetUBXNAVSVIN->automaticFlags.flags.bits.callbackCopyValid = true;
3598+
}
3599+
3600+
// Check if we need to copy the data into the file buffer
3601+
if (packetUBXNAVSVIN->automaticFlags.flags.bits.addToFileBuffer)
3602+
{
3603+
storePacket(msg);
3604+
}
35913605
}
35923606
}
35933607
else if (msg->id == UBX_NAV_SAT) // Note: length is variable
@@ -5313,6 +5327,19 @@ void SFE_UBLOX_GNSS::checkCallbacks(void)
53135327
packetUBXNAVCLOCK->automaticFlags.flags.bits.callbackCopyValid = false; // Mark the data as stale
53145328
}
53155329

5330+
if ((packetUBXNAVSVIN != NULL) // If RAM has been allocated for message storage
5331+
&& (packetUBXNAVSVIN->callbackData != NULL) // If RAM has been allocated for the copy of the data
5332+
&& (packetUBXNAVSVIN->automaticFlags.flags.bits.callbackCopyValid == true)) // If the copy of the data is valid
5333+
{
5334+
if (packetUBXNAVSVIN->callbackPointerPtr != NULL) // If the pointer to the callback has been defined
5335+
{
5336+
// if (_printDebug == true)
5337+
// _debugSerial->println(F("checkCallbacks: calling callbackPtr for NAV SVIN"));
5338+
packetUBXNAVSVIN->callbackPointerPtr(packetUBXNAVSVIN->callbackData); // Call the callback
5339+
}
5340+
packetUBXNAVSVIN->automaticFlags.flags.bits.callbackCopyValid = false; // Mark the data as stale
5341+
}
5342+
53165343
if ((packetUBXNAVSAT != NULL) // If RAM has been allocated for message storage
53175344
&& (packetUBXNAVSAT->callbackData != NULL) // If RAM has been allocated for the copy of the data
53185345
&& (packetUBXNAVSAT->automaticFlags.flags.bits.callbackCopyValid == true)) // If the copy of the data is valid
@@ -11629,23 +11656,126 @@ bool SFE_UBLOX_GNSS::getSurveyStatus(uint16_t maxWait)
1162911656
if (packetUBXNAVSVIN == NULL) // Abort if the RAM allocation failed
1163011657
return (false);
1163111658

11632-
packetCfg.cls = UBX_CLASS_NAV;
11633-
packetCfg.id = UBX_NAV_SVIN;
11634-
packetCfg.len = 0;
11659+
if (packetUBXNAVSVIN->automaticFlags.flags.bits.automatic && packetUBXNAVSVIN->automaticFlags.flags.bits.implicitUpdate)
11660+
{
11661+
// The GPS is automatically reporting, we just check whether we got unread data
11662+
checkUbloxInternal(&packetCfg, UBX_CLASS_NAV, UBX_NAV_SVIN);
11663+
return packetUBXNAVSVIN->moduleQueried.moduleQueried.bits.all;
11664+
}
11665+
else if (packetUBXNAVSVIN->automaticFlags.flags.bits.automatic && !packetUBXNAVSVIN->automaticFlags.flags.bits.implicitUpdate)
11666+
{
11667+
// Someone else has to call checkUblox for us...
11668+
return (false);
11669+
}
11670+
else
11671+
{
11672+
// The GPS is not automatically reporting SVIN so we have to poll explicitly
11673+
packetCfg.cls = UBX_CLASS_NAV;
11674+
packetCfg.id = UBX_NAV_SVIN;
11675+
packetCfg.len = 0;
11676+
packetCfg.startingSpot = 0;
11677+
11678+
// The data is parsed as part of processing the response
11679+
sfe_ublox_status_e retVal = sendCommand(&packetCfg, maxWait);
11680+
11681+
if (retVal == SFE_UBLOX_STATUS_DATA_RECEIVED)
11682+
return (true);
11683+
11684+
if (retVal == SFE_UBLOX_STATUS_DATA_OVERWRITTEN)
11685+
{
11686+
return (true);
11687+
}
11688+
11689+
return (false);
11690+
}
11691+
}
11692+
11693+
// Enable or disable automatic SVIN message generation by the GNSS. This changes the way getSurveyStatus
11694+
// works.
11695+
bool SFE_UBLOX_GNSS::setAutoNAVSVIN(bool enable, uint16_t maxWait)
11696+
{
11697+
return setAutoNAVSVINrate(enable ? 1 : 0, true, maxWait);
11698+
}
11699+
11700+
// Enable or disable automatic SVIN message generation by the GNSS. This changes the way getSurveyStatus
11701+
// works.
11702+
bool SFE_UBLOX_GNSS::setAutoNAVSVIN(bool enable, bool implicitUpdate, uint16_t maxWait)
11703+
{
11704+
return setAutoNAVSVINrate(enable ? 1 : 0, implicitUpdate, maxWait);
11705+
}
11706+
11707+
// Enable or disable automatic SVIN message generation by the GNSS. This changes the way getSurveyStatus
11708+
// works.
11709+
bool SFE_UBLOX_GNSS::setAutoNAVSVINrate(uint8_t rate, bool implicitUpdate, uint16_t maxWait)
11710+
{
11711+
if (packetUBXNAVSVIN == NULL)
11712+
initPacketUBXNAVSVIN(); // Check that RAM has been allocated for the data
11713+
if (packetUBXNAVSVIN == NULL) // Only attempt this if RAM allocation was successful
11714+
return false;
11715+
11716+
if (rate > 127)
11717+
rate = 127;
11718+
11719+
packetCfg.cls = UBX_CLASS_CFG;
11720+
packetCfg.id = UBX_CFG_MSG;
11721+
packetCfg.len = 3;
1163511722
packetCfg.startingSpot = 0;
11723+
payloadCfg[0] = UBX_CLASS_NAV;
11724+
payloadCfg[1] = UBX_NAV_SVIN;
11725+
payloadCfg[2] = rate; // rate relative to navigation freq.
1163611726

11637-
// The data is parsed as part of processing the response
11638-
sfe_ublox_status_e retVal = sendCommand(&packetCfg, maxWait);
11727+
bool ok = ((sendCommand(&packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
11728+
if (ok)
11729+
{
11730+
packetUBXNAVSVIN->automaticFlags.flags.bits.automatic = (rate > 0);
11731+
packetUBXNAVSVIN->automaticFlags.flags.bits.implicitUpdate = implicitUpdate;
11732+
}
11733+
packetUBXNAVSVIN->moduleQueried.moduleQueried.bits.all = false; // Mark data as stale
11734+
return ok;
11735+
}
1163911736

11640-
if (retVal == SFE_UBLOX_STATUS_DATA_RECEIVED)
11641-
return (true);
11737+
// Enable automatic navigation message generation by the GNSS.
11738+
bool SFE_UBLOX_GNSS::setAutoNAVSVINcallbackPtr(void (*callbackPointerPtr)(UBX_NAV_SVIN_data_t *), uint16_t maxWait)
11739+
{
11740+
// Enable auto messages. Set implicitUpdate to false as we expect the user to call checkUblox manually.
11741+
bool result = setAutoNAVSVIN(true, false, maxWait);
11742+
if (!result)
11743+
return (result); // Bail if setAuto failed
1164211744

11643-
if (retVal == SFE_UBLOX_STATUS_DATA_OVERWRITTEN)
11745+
if (packetUBXNAVSVIN->callbackData == NULL) // Check if RAM has been allocated for the callback copy
1164411746
{
11645-
return (true);
11747+
packetUBXNAVSVIN->callbackData = new UBX_NAV_SVIN_data_t; // Allocate RAM for the main struct
1164611748
}
1164711749

11648-
return (false);
11750+
if (packetUBXNAVSVIN->callbackData == NULL)
11751+
{
11752+
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
11753+
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
11754+
_debugSerial->println(F("setAutoNAVSVINcallbackPtr: RAM alloc failed!"));
11755+
#endif
11756+
return (false);
11757+
}
11758+
11759+
packetUBXNAVSVIN->callbackPointerPtr = callbackPointerPtr;
11760+
return (true);
11761+
}
11762+
11763+
// In case no config access to the GNSS is possible and SVIN is send cyclically already
11764+
// set config to suitable parameters
11765+
bool SFE_UBLOX_GNSS::assumeAutoNAVSVIN(bool enabled, bool implicitUpdate)
11766+
{
11767+
if (packetUBXNAVSVIN == NULL)
11768+
initPacketUBXNAVSVIN(); // Check that RAM has been allocated for the SVIN data
11769+
if (packetUBXNAVSVIN == NULL) // Bail if the RAM allocation failed
11770+
return (false);
11771+
11772+
bool changes = packetUBXNAVSVIN->automaticFlags.flags.bits.automatic != enabled || packetUBXNAVSVIN->automaticFlags.flags.bits.implicitUpdate != implicitUpdate;
11773+
if (changes)
11774+
{
11775+
packetUBXNAVSVIN->automaticFlags.flags.bits.automatic = enabled;
11776+
packetUBXNAVSVIN->automaticFlags.flags.bits.implicitUpdate = implicitUpdate;
11777+
}
11778+
return changes;
1164911779
}
1165011780

1165111781
// PRIVATE: Allocate RAM for packetUBXNAVSVIN and initialize it
@@ -11661,13 +11791,28 @@ bool SFE_UBLOX_GNSS::initPacketUBXNAVSVIN()
1166111791
return (false);
1166211792
}
1166311793
packetUBXNAVSVIN->automaticFlags.flags.all = 0;
11664-
packetUBXNAVSVIN->callbackPointer = NULL;
1166511794
packetUBXNAVSVIN->callbackPointerPtr = NULL;
1166611795
packetUBXNAVSVIN->callbackData = NULL;
1166711796
packetUBXNAVSVIN->moduleQueried.moduleQueried.all = 0;
1166811797
return (true);
1166911798
}
1167011799

11800+
// Mark all the data as read/stale
11801+
void SFE_UBLOX_GNSS::flushNAVSVIN()
11802+
{
11803+
if (packetUBXNAVSVIN == NULL)
11804+
return; // Bail if RAM has not been allocated (otherwise we could be writing anywhere!)
11805+
packetUBXNAVSVIN->moduleQueried.moduleQueried.all = 0; // Mark all datums as stale (read before)
11806+
}
11807+
11808+
// Log this data in file buffer
11809+
void SFE_UBLOX_GNSS::logNAVSVIN(bool enabled)
11810+
{
11811+
if (packetUBXNAVSVIN == NULL)
11812+
return; // Bail if RAM has not been allocated (otherwise we could be writing anywhere!)
11813+
packetUBXNAVSVIN->automaticFlags.flags.bits.addToFileBuffer = (uint8_t)enabled;
11814+
}
11815+
1167111816
// ***** NAV SAT automatic support
1167211817

1167311818
// Signal information

src/SparkFun_u-blox_GNSS_Arduino_Library.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -1110,11 +1110,17 @@ class SFE_UBLOX_GNSS
11101110
void flushNAVCLOCK(); // Mark all the data as read/stale
11111111
void logNAVCLOCK(bool enabled = true); // Log data to file buffer
11121112

1113-
// Add "auto" support for NAV SVIN - to avoid needing 'global' storage
1114-
bool getSurveyStatus(uint16_t maxWait); // Reads survey in status
1113+
bool getSurveyStatus(uint16_t maxWait = 2100); // NAV SVIN - Reads survey in status
1114+
bool setAutoNAVSVIN(bool enabled, uint16_t maxWait = defaultMaxWait); // Enable/disable automatic survey in reports at the navigation frequency
1115+
bool setAutoNAVSVIN(bool enabled, bool implicitUpdate, uint16_t maxWait = defaultMaxWait); // Enable/disable automatic survey in reports at the navigation frequency, with implicitUpdate == false accessing stale data will not issue parsing of data in the rxbuffer of your interface, instead you have to call checkUblox when you want to perform an update
1116+
bool setAutoNAVSVINrate(uint8_t rate, bool implicitUpdate = true, uint16_t maxWait = defaultMaxWait); // Set the rate for automatic SVIN reports
1117+
bool setAutoNAVSVINcallbackPtr(void (*callbackPointerPtr)(UBX_NAV_SVIN_data_t *), uint16_t maxWait = defaultMaxWait); // Enable automatic SVIN reports at the navigation frequency. Data is accessed from the callback.
1118+
bool assumeAutoNAVSVIN(bool enabled, bool implicitUpdate = true); // In case no config access to the GPS is possible and survey in is send cyclically already
1119+
void flushNAVSVIN(); // Mark all the data as read/stale
1120+
void logNAVSVIN(bool enabled = true); // Log data to file buffer
11151121

11161122
// Add "auto" support for NAV TIMELS - to avoid needing 'global' storage
1117-
bool getLeapSecondEvent(uint16_t maxWait); // Reads leap second event info
1123+
bool getLeapSecondEvent(uint16_t maxWait = defaultMaxWait); // Reads leap second event info
11181124

11191125
bool getNAVSAT(uint16_t maxWait = defaultMaxWait); // Query module for latest AssistNow Autonomous status and load global vars:. If autoNAVSAT is disabled, performs an explicit poll and waits, if enabled does not block. Returns true if new NAVSAT is available.
11201126
bool setAutoNAVSAT(bool enabled, uint16_t maxWait = defaultMaxWait); // Enable/disable automatic NAVSAT reports at the navigation frequency

src/u-blox_structs.h

-1
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,6 @@ typedef struct
12331233
ubxAutomaticFlags automaticFlags;
12341234
UBX_NAV_SVIN_data_t data;
12351235
UBX_NAV_SVIN_moduleQueried_t moduleQueried;
1236-
void (*callbackPointer)(UBX_NAV_SVIN_data_t);
12371236
void (*callbackPointerPtr)(UBX_NAV_SVIN_data_t *);
12381237
UBX_NAV_SVIN_data_t *callbackData;
12391238
} UBX_NAV_SVIN_t;

0 commit comments

Comments
 (0)