Skip to content

Add autoSendCfgValsetAtSpaceRemaining. Update Example9 #165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ void setup()
//but with multiple messages all in one go using newCfgValset, addCfgValset and sendCfgValset.
//Original: myGNSS.enableRTCMmessage(UBX_RTCM_1005, COM_PORT_I2C, 1); //Enable message 1005 to output through I2C port, message every second

//If we will be sending a large number of key IDs and values, packetCfg could fill up before the CFG_VALSET is sent...
//There are three possible solutions:
// Increase the space available by calling myGNSS.setPacketCfgPayloadSize
// Monitor how much space is remaining by calling myGNSS.getCfgValsetSpaceRemaining. Call myGNSS.sendCfgValset(); before packetCfg becomes full.
// Call myGNSS.autoSendCfgValsetAtSpaceRemaining(16); . This will cause the existing CFG_VALSET to be send automatically and a new one created when packetCfg has less than 16 bytes remaining.
myGNSS.autoSendCfgValsetAtSpaceRemaining(16); // Trigger an auto-send when packetCfg has less than 16 bytes are remaining

//Begin with newCfgValset
setValueSuccess &= myGNSS.newCfgValset(); // Defaults to configuring the setting in Flash, RAM and BBR
//setValueSuccess &= myGNSS.newCfgValset(VAL_LAYER_RAM); //Set this and the following settings in RAM only instead of Flash/RAM/BBR
Expand Down
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ sendCfgValset64 KEYWORD2
sendCfgValset KEYWORD2
getCfgValsetLen KEYWORD2
getCfgValsetSpaceRemaining KEYWORD2
autoSendCfgValsetAtSpaceRemaining KEYWORD2

getNAVPOSECEF KEYWORD2
setAutoNAVPOSECEF KEYWORD2
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SparkFun u-blox GNSS Arduino Library
version=2.2.18
version=2.2.19
author=SparkFun Electronics <[email protected]>
maintainer=SparkFun Electronics <sparkfun.com>
sentence=Library for I2C, Serial and SPI Communication with u-blox GNSS modules<br/><br/>
Expand Down
114 changes: 112 additions & 2 deletions src/SparkFun_u-blox_GNSS_Arduino_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9337,6 +9337,19 @@ uint8_t SFE_UBLOX_GNSS::newCfgValset(uint8_t layer)
// This function takes a full 32-bit key and 64-bit value
uint8_t SFE_UBLOX_GNSS::addCfgValset64(uint32_t key, uint64_t value)
{
if ((_autoSendAtSpaceRemaining > 0) && (packetCfg.len >= (packetCfgPayloadSize - _autoSendAtSpaceRemaining)))
{
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
_debugSerial->println(F("addCfgValset64: autosend"));
#endif
sendCommand(&packetCfg);
packetCfg.len = 4; // 4 byte header
packetCfg.startingSpot = 0;
_numCfgKeyIDs = 0;
memset(&payloadCfg[4], 0, packetCfgPayloadSize - 4);
}

if (packetCfg.len >= (packetCfgPayloadSize - 12))
{
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
Expand Down Expand Up @@ -9384,6 +9397,19 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset64(uint32_t key, uint64_t value)
// This function takes a full 32-bit key and 32-bit value
uint8_t SFE_UBLOX_GNSS::addCfgValset32(uint32_t key, uint32_t value)
{
if ((_autoSendAtSpaceRemaining > 0) && (packetCfg.len >= (packetCfgPayloadSize - _autoSendAtSpaceRemaining)))
{
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
_debugSerial->println(F("addCfgValset32: autosend"));
#endif
sendCommand(&packetCfg);
packetCfg.len = 4; // 4 byte header
packetCfg.startingSpot = 0;
_numCfgKeyIDs = 0;
memset(&payloadCfg[4], 0, packetCfgPayloadSize - 4);
}

if (packetCfg.len >= (packetCfgPayloadSize - 8))
{
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
Expand Down Expand Up @@ -9427,6 +9453,19 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset32(uint32_t key, uint32_t value)
// This function takes a full 32-bit key and 16-bit value
uint8_t SFE_UBLOX_GNSS::addCfgValset16(uint32_t key, uint16_t value)
{
if ((_autoSendAtSpaceRemaining > 0) && (packetCfg.len >= (packetCfgPayloadSize - _autoSendAtSpaceRemaining)))
{
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
_debugSerial->println(F("addCfgValset16: autosend"));
#endif
sendCommand(&packetCfg);
packetCfg.len = 4; // 4 byte header
packetCfg.startingSpot = 0;
_numCfgKeyIDs = 0;
memset(&payloadCfg[4], 0, packetCfgPayloadSize - 4);
}

if (packetCfg.len >= (packetCfgPayloadSize - 6))
{
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
Expand Down Expand Up @@ -9468,6 +9507,19 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset16(uint32_t key, uint16_t value)
// This function takes a full 32-bit key and 8-bit value
uint8_t SFE_UBLOX_GNSS::addCfgValset8(uint32_t key, uint8_t value)
{
if ((_autoSendAtSpaceRemaining > 0) && (packetCfg.len >= (packetCfgPayloadSize - _autoSendAtSpaceRemaining)))
{
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
_debugSerial->println(F("addCfgValset8: autosend"));
#endif
sendCommand(&packetCfg);
packetCfg.len = 4; // 4 byte header
packetCfg.startingSpot = 0;
_numCfgKeyIDs = 0;
memset(&payloadCfg[4], 0, packetCfgPayloadSize - 4);
}

if (packetCfg.len >= (packetCfgPayloadSize - 5))
{
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
Expand Down Expand Up @@ -9508,6 +9560,19 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset8(uint32_t key, uint8_t value)
// This function takes a full 32-bit key and 64-bit value
uint8_t SFE_UBLOX_GNSS::sendCfgValset64(uint32_t key, uint64_t value, uint16_t maxWait)
{
if ((_autoSendAtSpaceRemaining > 0) && (packetCfg.len >= (packetCfgPayloadSize - _autoSendAtSpaceRemaining)))
{
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
_debugSerial->println(F("sendCfgValset64: autosend"));
#endif
sendCommand(&packetCfg);
packetCfg.len = 4; // 4 byte header
packetCfg.startingSpot = 0;
_numCfgKeyIDs = 0;
memset(&payloadCfg[4], 0, packetCfgPayloadSize - 4);
}

if (packetCfg.len >= (packetCfgPayloadSize - 12))
{
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
Expand Down Expand Up @@ -9536,6 +9601,19 @@ uint8_t SFE_UBLOX_GNSS::sendCfgValset64(uint32_t key, uint64_t value, uint16_t m
// This function takes a full 32-bit key and 32-bit value
uint8_t SFE_UBLOX_GNSS::sendCfgValset32(uint32_t key, uint32_t value, uint16_t maxWait)
{
if ((_autoSendAtSpaceRemaining > 0) && (packetCfg.len >= (packetCfgPayloadSize - _autoSendAtSpaceRemaining)))
{
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
_debugSerial->println(F("sendCfgValset32: autosend"));
#endif
sendCommand(&packetCfg);
packetCfg.len = 4; // 4 byte header
packetCfg.startingSpot = 0;
_numCfgKeyIDs = 0;
memset(&payloadCfg[4], 0, packetCfgPayloadSize - 4);
}

if (packetCfg.len >= (packetCfgPayloadSize - 8))
{
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
Expand Down Expand Up @@ -9564,6 +9642,19 @@ uint8_t SFE_UBLOX_GNSS::sendCfgValset32(uint32_t key, uint32_t value, uint16_t m
// This function takes a full 32-bit key and 16-bit value
uint8_t SFE_UBLOX_GNSS::sendCfgValset16(uint32_t key, uint16_t value, uint16_t maxWait)
{
if ((_autoSendAtSpaceRemaining > 0) && (packetCfg.len >= (packetCfgPayloadSize - _autoSendAtSpaceRemaining)))
{
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
_debugSerial->println(F("sendCfgValset16: autosend"));
#endif
sendCommand(&packetCfg);
packetCfg.len = 4; // 4 byte header
packetCfg.startingSpot = 0;
_numCfgKeyIDs = 0;
memset(&payloadCfg[4], 0, packetCfgPayloadSize - 4);
}

if (packetCfg.len >= (packetCfgPayloadSize - 6))
{
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
Expand Down Expand Up @@ -9592,6 +9683,19 @@ uint8_t SFE_UBLOX_GNSS::sendCfgValset16(uint32_t key, uint16_t value, uint16_t m
// This function takes a full 32-bit key and 8-bit value
uint8_t SFE_UBLOX_GNSS::sendCfgValset8(uint32_t key, uint8_t value, uint16_t maxWait)
{
if ((_autoSendAtSpaceRemaining > 0) && (packetCfg.len >= (packetCfgPayloadSize - _autoSendAtSpaceRemaining)))
{
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
_debugSerial->println(F("sendCfgValset8: autosend"));
#endif
sendCommand(&packetCfg);
packetCfg.len = 4; // 4 byte header
packetCfg.startingSpot = 0;
_numCfgKeyIDs = 0;
memset(&payloadCfg[4], 0, packetCfgPayloadSize - 4);
}

if (packetCfg.len >= (packetCfgPayloadSize - 5))
{
#ifndef SFE_UBLOX_REDUCED_PROG_MEM
Expand Down Expand Up @@ -9619,10 +9723,16 @@ uint8_t SFE_UBLOX_GNSS::sendCfgValset8(uint32_t key, uint8_t value, uint16_t max
// Send the UBX-CFG-VALSET ubxPacket
uint8_t SFE_UBLOX_GNSS::sendCfgValset(uint16_t maxWait)
{
_numCfgKeyIDs = 0;
if (_numCfgKeyIDs == 0)
return true; // Nothing to send...

// Send VALSET command with this key and value
return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
bool success = sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT; // We are only expecting an ACK

if (success)
_numCfgKeyIDs = 0;

return success;
}

// Return the number of keys in the CfgValset
Expand Down
4 changes: 4 additions & 0 deletions src/SparkFun_u-blox_GNSS_Arduino_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ class SFE_UBLOX_GNSS
uint8_t sendCfgValset(uint16_t maxWait = defaultMaxWait); // Send the CfgValset (UBX-CFG-VALSET) construct
uint8_t getCfgValsetLen(); // Returns the length of the current CfgValset construct as number-of-keyIDs
size_t getCfgValsetSpaceRemaining(); // Returns the number of free bytes remaining in packetCfg
void autoSendCfgValsetAtSpaceRemaining(size_t spaceRemaining) { _autoSendAtSpaceRemaining = spaceRemaining; } // Cause CFG_VALSET packets to be sent automatically when packetCfg has less than this many bytes available

// get and set functions for all of the "automatic" message processing

Expand Down Expand Up @@ -1796,6 +1797,9 @@ class SFE_UBLOX_GNSS

// Keep track of how many keys have been added to CfgValset
uint8_t _numCfgKeyIDs = 0;

// Send the current CFG_VALSET message when packetCfg has less than this many bytes available
size_t _autoSendAtSpaceRemaining = 0;
};

#endif