@@ -627,6 +627,12 @@ bool SFE_UBLOX_GNSS::setPacketCfgPayloadSize(size_t payloadSize)
627627 return (success);
628628}
629629
630+ // Return the number of free bytes remaining in packetCfgPayload
631+ size_t SFE_UBLOX_GNSS::getPacketCfgSpaceRemaining()
632+ {
633+ return (packetCfgPayloadSize - packetCfg.len);
634+ }
635+
630636// Initialize the I2C port
631637bool SFE_UBLOX_GNSS::begin(TwoWire &wirePort, uint8_t deviceAddress, uint16_t maxWait, bool assumeSuccess)
632638{
@@ -9178,6 +9184,8 @@ uint8_t SFE_UBLOX_GNSS::newCfgValset64(uint32_t key, uint64_t value, uint8_t lay
91789184 packetCfg.len = 4 + 4 + 8; // 4 byte header, 4 byte key ID, 8 bytes of value
91799185 packetCfg.startingSpot = 0;
91809186
9187+ _numCfgKeyIDs = 1;
9188+
91819189 // Clear all of packet payload
91829190 memset(payloadCfg, 0, packetCfgPayloadSize);
91839191
@@ -9215,6 +9223,8 @@ uint8_t SFE_UBLOX_GNSS::newCfgValset32(uint32_t key, uint32_t value, uint8_t lay
92159223 packetCfg.len = 4 + 4 + 4; // 4 byte header, 4 byte key ID, 4 bytes of value
92169224 packetCfg.startingSpot = 0;
92179225
9226+ _numCfgKeyIDs = 1;
9227+
92189228 // Clear all of packet payload
92199229 memset(payloadCfg, 0, packetCfgPayloadSize);
92209230
@@ -9248,6 +9258,8 @@ uint8_t SFE_UBLOX_GNSS::newCfgValset16(uint32_t key, uint16_t value, uint8_t lay
92489258 packetCfg.len = 4 + 4 + 2; // 4 byte header, 4 byte key ID, 2 bytes of value
92499259 packetCfg.startingSpot = 0;
92509260
9261+ _numCfgKeyIDs = 1;
9262+
92519263 // Clear all of packet payload
92529264 memset(payloadCfg, 0, packetCfgPayloadSize);
92539265
@@ -9279,7 +9291,9 @@ uint8_t SFE_UBLOX_GNSS::newCfgValset8(uint32_t key, uint8_t value, uint8_t layer
92799291 packetCfg.len = 4 + 4 + 1; // 4 byte header, 4 byte key ID, 1 byte value
92809292 packetCfg.startingSpot = 0;
92819293
9282- // Clear all of packet payload
9294+ _numCfgKeyIDs = 1;
9295+
9296+ // Clear all of packet payload
92839297 memset(payloadCfg, 0, packetCfgPayloadSize);
92849298
92859299 payloadCfg[0] = 0; // Message Version - set to 0
@@ -9298,10 +9312,49 @@ uint8_t SFE_UBLOX_GNSS::newCfgValset8(uint32_t key, uint8_t value, uint8_t layer
92989312 return (true);
92999313}
93009314
9315+ // Start defining a new (empty) UBX-CFG-VALSET ubxPacket
9316+ // Configuration of modern u-blox modules is now done via getVal/setVal/delVal, ie protocol v27 and above found on ZED-F9P
9317+ uint8_t SFE_UBLOX_GNSS::newCfgValset(uint8_t layer)
9318+ {
9319+ packetCfg.cls = UBX_CLASS_CFG;
9320+ packetCfg.id = UBX_CFG_VALSET;
9321+ packetCfg.len = 4; // 4 byte header
9322+ packetCfg.startingSpot = 0;
9323+
9324+ _numCfgKeyIDs = 0;
9325+
9326+ // Clear all of packet payload
9327+ memset(payloadCfg, 0, packetCfgPayloadSize);
9328+
9329+ payloadCfg[0] = 0; // Message Version - set to 0
9330+ payloadCfg[1] = layer; // By default we ask for the BBR layer
9331+
9332+ // All done
9333+ return (true);
9334+ }
9335+
93019336// Add another keyID and value to an existing UBX-CFG-VALSET ubxPacket
93029337// This function takes a full 32-bit key and 64-bit value
93039338uint8_t SFE_UBLOX_GNSS::addCfgValset64(uint32_t key, uint64_t value)
93049339{
9340+ if (packetCfg.len >= (packetCfgPayloadSize - 12))
9341+ {
9342+ #ifndef SFE_UBLOX_REDUCED_PROG_MEM
9343+ if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
9344+ _debugSerial->println(F("addCfgValset64: packetCfgPayloadSize reached!"));
9345+ #endif
9346+ return false;
9347+ }
9348+
9349+ if (_numCfgKeyIDs == CFG_VALSET_MAX_KEYS)
9350+ {
9351+ #ifndef SFE_UBLOX_REDUCED_PROG_MEM
9352+ if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
9353+ _debugSerial->println(F("addCfgValset64: key limit reached!"));
9354+ #endif
9355+ return false;
9356+ }
9357+
93059358 // Load key into outgoing payload
93069359 payloadCfg[packetCfg.len + 0] = key >> 8 * 0; // Key LSB
93079360 payloadCfg[packetCfg.len + 1] = key >> 8 * 1;
@@ -9321,6 +9374,8 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset64(uint32_t key, uint64_t value)
93219374 // Update packet length: 4 byte key ID, 8 bytes of value
93229375 packetCfg.len = packetCfg.len + 4 + 8;
93239376
9377+ _numCfgKeyIDs++;
9378+
93249379 // All done
93259380 return (true);
93269381}
@@ -9329,6 +9384,24 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset64(uint32_t key, uint64_t value)
93299384// This function takes a full 32-bit key and 32-bit value
93309385uint8_t SFE_UBLOX_GNSS::addCfgValset32(uint32_t key, uint32_t value)
93319386{
9387+ if (packetCfg.len >= (packetCfgPayloadSize - 8))
9388+ {
9389+ #ifndef SFE_UBLOX_REDUCED_PROG_MEM
9390+ if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
9391+ _debugSerial->println(F("addCfgValset32: packetCfgPayloadSize reached!"));
9392+ #endif
9393+ return false;
9394+ }
9395+
9396+ if (_numCfgKeyIDs == CFG_VALSET_MAX_KEYS)
9397+ {
9398+ #ifndef SFE_UBLOX_REDUCED_PROG_MEM
9399+ if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
9400+ _debugSerial->println(F("addCfgValset32: key limit reached!"));
9401+ #endif
9402+ return false;
9403+ }
9404+
93329405 // Load key into outgoing payload
93339406 payloadCfg[packetCfg.len + 0] = key >> 8 * 0; // Key LSB
93349407 payloadCfg[packetCfg.len + 1] = key >> 8 * 1;
@@ -9344,6 +9417,8 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset32(uint32_t key, uint32_t value)
93449417 // Update packet length: 4 byte key ID, 4 bytes of value
93459418 packetCfg.len = packetCfg.len + 4 + 4;
93469419
9420+ _numCfgKeyIDs++;
9421+
93479422 // All done
93489423 return (true);
93499424}
@@ -9352,6 +9427,24 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset32(uint32_t key, uint32_t value)
93529427// This function takes a full 32-bit key and 16-bit value
93539428uint8_t SFE_UBLOX_GNSS::addCfgValset16(uint32_t key, uint16_t value)
93549429{
9430+ if (packetCfg.len >= (packetCfgPayloadSize - 6))
9431+ {
9432+ #ifndef SFE_UBLOX_REDUCED_PROG_MEM
9433+ if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
9434+ _debugSerial->println(F("addCfgValset16: packetCfgPayloadSize reached!"));
9435+ #endif
9436+ return false;
9437+ }
9438+
9439+ if (_numCfgKeyIDs == CFG_VALSET_MAX_KEYS)
9440+ {
9441+ #ifndef SFE_UBLOX_REDUCED_PROG_MEM
9442+ if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
9443+ _debugSerial->println(F("addCfgValset16: key limit reached!"));
9444+ #endif
9445+ return false;
9446+ }
9447+
93559448 // Load key into outgoing payload
93569449 payloadCfg[packetCfg.len + 0] = key >> 8 * 0; // Key LSB
93579450 payloadCfg[packetCfg.len + 1] = key >> 8 * 1;
@@ -9365,6 +9458,8 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset16(uint32_t key, uint16_t value)
93659458 // Update packet length: 4 byte key ID, 2 bytes of value
93669459 packetCfg.len = packetCfg.len + 4 + 2;
93679460
9461+ _numCfgKeyIDs++;
9462+
93689463 // All done
93699464 return (true);
93709465}
@@ -9373,6 +9468,24 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset16(uint32_t key, uint16_t value)
93739468// This function takes a full 32-bit key and 8-bit value
93749469uint8_t SFE_UBLOX_GNSS::addCfgValset8(uint32_t key, uint8_t value)
93759470{
9471+ if (packetCfg.len >= (packetCfgPayloadSize - 5))
9472+ {
9473+ #ifndef SFE_UBLOX_REDUCED_PROG_MEM
9474+ if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
9475+ _debugSerial->println(F("addCfgValset8: packetCfgPayloadSize reached!"));
9476+ #endif
9477+ return false;
9478+ }
9479+
9480+ if (_numCfgKeyIDs == CFG_VALSET_MAX_KEYS)
9481+ {
9482+ #ifndef SFE_UBLOX_REDUCED_PROG_MEM
9483+ if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
9484+ _debugSerial->println(F("addCfgValset8: key limit reached!"));
9485+ #endif
9486+ return false;
9487+ }
9488+
93769489 // Load key into outgoing payload
93779490 payloadCfg[packetCfg.len + 0] = key >> 8 * 0; // Key LSB
93789491 payloadCfg[packetCfg.len + 1] = key >> 8 * 1;
@@ -9385,6 +9498,8 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset8(uint32_t key, uint8_t value)
93859498 // Update packet length: 4 byte key ID, 1 byte value
93869499 packetCfg.len = packetCfg.len + 4 + 1;
93879500
9501+ _numCfgKeyIDs++;
9502+
93889503 // All done
93899504 return (true);
93909505}
@@ -9393,8 +9508,25 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset8(uint32_t key, uint8_t value)
93939508// This function takes a full 32-bit key and 64-bit value
93949509uint8_t SFE_UBLOX_GNSS::sendCfgValset64(uint32_t key, uint64_t value, uint16_t maxWait)
93959510{
9396- // Load keyID and value into outgoing payload
9397- addCfgValset64(key, value);
9511+ if (packetCfg.len >= (packetCfgPayloadSize - 12))
9512+ {
9513+ #ifndef SFE_UBLOX_REDUCED_PROG_MEM
9514+ if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
9515+ _debugSerial->println(F("sendCfgValset64: packetCfgPayloadSize reached!"));
9516+ #endif
9517+ }
9518+ else if (_numCfgKeyIDs == CFG_VALSET_MAX_KEYS)
9519+ {
9520+ #ifndef SFE_UBLOX_REDUCED_PROG_MEM
9521+ if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
9522+ _debugSerial->println(F("sendCfgValset64: key limit reached!"));
9523+ #endif
9524+ }
9525+ else
9526+ // Load keyID and value into outgoing payload
9527+ addCfgValset64(key, value);
9528+
9529+ _numCfgKeyIDs = 0;
93989530
93999531 // Send VALSET command with this key and value
94009532 return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
@@ -9404,8 +9536,25 @@ uint8_t SFE_UBLOX_GNSS::sendCfgValset64(uint32_t key, uint64_t value, uint16_t m
94049536// This function takes a full 32-bit key and 32-bit value
94059537uint8_t SFE_UBLOX_GNSS::sendCfgValset32(uint32_t key, uint32_t value, uint16_t maxWait)
94069538{
9407- // Load keyID and value into outgoing payload
9408- addCfgValset32(key, value);
9539+ if (packetCfg.len >= (packetCfgPayloadSize - 8))
9540+ {
9541+ #ifndef SFE_UBLOX_REDUCED_PROG_MEM
9542+ if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
9543+ _debugSerial->println(F("sendCfgValset32: packetCfgPayloadSize reached!"));
9544+ #endif
9545+ }
9546+ else if (_numCfgKeyIDs == CFG_VALSET_MAX_KEYS)
9547+ {
9548+ #ifndef SFE_UBLOX_REDUCED_PROG_MEM
9549+ if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
9550+ _debugSerial->println(F("sendCfgValset32: key limit reached!"));
9551+ #endif
9552+ }
9553+ else
9554+ // Load keyID and value into outgoing payload
9555+ addCfgValset32(key, value);
9556+
9557+ _numCfgKeyIDs = 0;
94099558
94109559 // Send VALSET command with this key and value
94119560 return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
@@ -9415,8 +9564,25 @@ uint8_t SFE_UBLOX_GNSS::sendCfgValset32(uint32_t key, uint32_t value, uint16_t m
94159564// This function takes a full 32-bit key and 16-bit value
94169565uint8_t SFE_UBLOX_GNSS::sendCfgValset16(uint32_t key, uint16_t value, uint16_t maxWait)
94179566{
9418- // Load keyID and value into outgoing payload
9419- addCfgValset16(key, value);
9567+ if (packetCfg.len >= (packetCfgPayloadSize - 6))
9568+ {
9569+ #ifndef SFE_UBLOX_REDUCED_PROG_MEM
9570+ if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
9571+ _debugSerial->println(F("sendCfgValset16: packetCfgPayloadSize reached!"));
9572+ #endif
9573+ }
9574+ else if (_numCfgKeyIDs == CFG_VALSET_MAX_KEYS)
9575+ {
9576+ #ifndef SFE_UBLOX_REDUCED_PROG_MEM
9577+ if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
9578+ _debugSerial->println(F("sendCfgValset16: key limit reached!"));
9579+ #endif
9580+ }
9581+ else
9582+ // Load keyID and value into outgoing payload
9583+ addCfgValset16(key, value);
9584+
9585+ _numCfgKeyIDs = 0;
94209586
94219587 // Send VALSET command with this key and value
94229588 return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
@@ -9426,13 +9592,51 @@ uint8_t SFE_UBLOX_GNSS::sendCfgValset16(uint32_t key, uint16_t value, uint16_t m
94269592// This function takes a full 32-bit key and 8-bit value
94279593uint8_t SFE_UBLOX_GNSS::sendCfgValset8(uint32_t key, uint8_t value, uint16_t maxWait)
94289594{
9429- // Load keyID and value into outgoing payload
9430- addCfgValset8(key, value);
9595+ if (packetCfg.len >= (packetCfgPayloadSize - 5))
9596+ {
9597+ #ifndef SFE_UBLOX_REDUCED_PROG_MEM
9598+ if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
9599+ _debugSerial->println(F("sendCfgValset8: packetCfgPayloadSize reached!"));
9600+ #endif
9601+ }
9602+ else if (_numCfgKeyIDs == CFG_VALSET_MAX_KEYS)
9603+ {
9604+ #ifndef SFE_UBLOX_REDUCED_PROG_MEM
9605+ if ((_printDebug == true) || (_printLimitedDebug == true)) // This is important. Print this if doing limited debugging
9606+ _debugSerial->println(F("sendCfgValset8: key limit reached!"));
9607+ #endif
9608+ }
9609+ else
9610+ // Load keyID and value into outgoing payload
9611+ addCfgValset8(key, value);
9612+
9613+ _numCfgKeyIDs = 0;
9614+
9615+ // Send VALSET command with this key and value
9616+ return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
9617+ }
9618+
9619+ // Send the UBX-CFG-VALSET ubxPacket
9620+ uint8_t SFE_UBLOX_GNSS::sendCfgValset(uint16_t maxWait)
9621+ {
9622+ _numCfgKeyIDs = 0;
94319623
94329624 // Send VALSET command with this key and value
94339625 return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
94349626}
94359627
9628+ // Return the number of keys in the CfgValset
9629+ uint8_t SFE_UBLOX_GNSS::getCfgValsetLen()
9630+ {
9631+ return _numCfgKeyIDs;
9632+ }
9633+
9634+ // Return the number of free bytes remaining in packetCfgPayload
9635+ size_t SFE_UBLOX_GNSS::getCfgValsetSpaceRemaining()
9636+ {
9637+ return getPacketCfgSpaceRemaining();
9638+ }
9639+
94369640//=-=-=-=-=-=-=-= "Automatic" Messages =-=-=-=-=-=-=-==-=-=-=-=-=-=-=
94379641//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
94389642
0 commit comments