@@ -627,6 +627,12 @@ bool SFE_UBLOX_GNSS::setPacketCfgPayloadSize(size_t payloadSize)
627
627
return (success);
628
628
}
629
629
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
+
630
636
// Initialize the I2C port
631
637
bool SFE_UBLOX_GNSS::begin(TwoWire &wirePort, uint8_t deviceAddress, uint16_t maxWait, bool assumeSuccess)
632
638
{
@@ -9178,6 +9184,8 @@ uint8_t SFE_UBLOX_GNSS::newCfgValset64(uint32_t key, uint64_t value, uint8_t lay
9178
9184
packetCfg.len = 4 + 4 + 8; // 4 byte header, 4 byte key ID, 8 bytes of value
9179
9185
packetCfg.startingSpot = 0;
9180
9186
9187
+ _numCfgKeyIDs = 1;
9188
+
9181
9189
// Clear all of packet payload
9182
9190
memset(payloadCfg, 0, packetCfgPayloadSize);
9183
9191
@@ -9215,6 +9223,8 @@ uint8_t SFE_UBLOX_GNSS::newCfgValset32(uint32_t key, uint32_t value, uint8_t lay
9215
9223
packetCfg.len = 4 + 4 + 4; // 4 byte header, 4 byte key ID, 4 bytes of value
9216
9224
packetCfg.startingSpot = 0;
9217
9225
9226
+ _numCfgKeyIDs = 1;
9227
+
9218
9228
// Clear all of packet payload
9219
9229
memset(payloadCfg, 0, packetCfgPayloadSize);
9220
9230
@@ -9248,6 +9258,8 @@ uint8_t SFE_UBLOX_GNSS::newCfgValset16(uint32_t key, uint16_t value, uint8_t lay
9248
9258
packetCfg.len = 4 + 4 + 2; // 4 byte header, 4 byte key ID, 2 bytes of value
9249
9259
packetCfg.startingSpot = 0;
9250
9260
9261
+ _numCfgKeyIDs = 1;
9262
+
9251
9263
// Clear all of packet payload
9252
9264
memset(payloadCfg, 0, packetCfgPayloadSize);
9253
9265
@@ -9279,7 +9291,9 @@ uint8_t SFE_UBLOX_GNSS::newCfgValset8(uint32_t key, uint8_t value, uint8_t layer
9279
9291
packetCfg.len = 4 + 4 + 1; // 4 byte header, 4 byte key ID, 1 byte value
9280
9292
packetCfg.startingSpot = 0;
9281
9293
9282
- // Clear all of packet payload
9294
+ _numCfgKeyIDs = 1;
9295
+
9296
+ // Clear all of packet payload
9283
9297
memset(payloadCfg, 0, packetCfgPayloadSize);
9284
9298
9285
9299
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
9298
9312
return (true);
9299
9313
}
9300
9314
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
+
9301
9336
// Add another keyID and value to an existing UBX-CFG-VALSET ubxPacket
9302
9337
// This function takes a full 32-bit key and 64-bit value
9303
9338
uint8_t SFE_UBLOX_GNSS::addCfgValset64(uint32_t key, uint64_t value)
9304
9339
{
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
+
9305
9358
// Load key into outgoing payload
9306
9359
payloadCfg[packetCfg.len + 0] = key >> 8 * 0; // Key LSB
9307
9360
payloadCfg[packetCfg.len + 1] = key >> 8 * 1;
@@ -9321,6 +9374,8 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset64(uint32_t key, uint64_t value)
9321
9374
// Update packet length: 4 byte key ID, 8 bytes of value
9322
9375
packetCfg.len = packetCfg.len + 4 + 8;
9323
9376
9377
+ _numCfgKeyIDs++;
9378
+
9324
9379
// All done
9325
9380
return (true);
9326
9381
}
@@ -9329,6 +9384,24 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset64(uint32_t key, uint64_t value)
9329
9384
// This function takes a full 32-bit key and 32-bit value
9330
9385
uint8_t SFE_UBLOX_GNSS::addCfgValset32(uint32_t key, uint32_t value)
9331
9386
{
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
+
9332
9405
// Load key into outgoing payload
9333
9406
payloadCfg[packetCfg.len + 0] = key >> 8 * 0; // Key LSB
9334
9407
payloadCfg[packetCfg.len + 1] = key >> 8 * 1;
@@ -9344,6 +9417,8 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset32(uint32_t key, uint32_t value)
9344
9417
// Update packet length: 4 byte key ID, 4 bytes of value
9345
9418
packetCfg.len = packetCfg.len + 4 + 4;
9346
9419
9420
+ _numCfgKeyIDs++;
9421
+
9347
9422
// All done
9348
9423
return (true);
9349
9424
}
@@ -9352,6 +9427,24 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset32(uint32_t key, uint32_t value)
9352
9427
// This function takes a full 32-bit key and 16-bit value
9353
9428
uint8_t SFE_UBLOX_GNSS::addCfgValset16(uint32_t key, uint16_t value)
9354
9429
{
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
+
9355
9448
// Load key into outgoing payload
9356
9449
payloadCfg[packetCfg.len + 0] = key >> 8 * 0; // Key LSB
9357
9450
payloadCfg[packetCfg.len + 1] = key >> 8 * 1;
@@ -9365,6 +9458,8 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset16(uint32_t key, uint16_t value)
9365
9458
// Update packet length: 4 byte key ID, 2 bytes of value
9366
9459
packetCfg.len = packetCfg.len + 4 + 2;
9367
9460
9461
+ _numCfgKeyIDs++;
9462
+
9368
9463
// All done
9369
9464
return (true);
9370
9465
}
@@ -9373,6 +9468,24 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset16(uint32_t key, uint16_t value)
9373
9468
// This function takes a full 32-bit key and 8-bit value
9374
9469
uint8_t SFE_UBLOX_GNSS::addCfgValset8(uint32_t key, uint8_t value)
9375
9470
{
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
+
9376
9489
// Load key into outgoing payload
9377
9490
payloadCfg[packetCfg.len + 0] = key >> 8 * 0; // Key LSB
9378
9491
payloadCfg[packetCfg.len + 1] = key >> 8 * 1;
@@ -9385,6 +9498,8 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset8(uint32_t key, uint8_t value)
9385
9498
// Update packet length: 4 byte key ID, 1 byte value
9386
9499
packetCfg.len = packetCfg.len + 4 + 1;
9387
9500
9501
+ _numCfgKeyIDs++;
9502
+
9388
9503
// All done
9389
9504
return (true);
9390
9505
}
@@ -9393,8 +9508,25 @@ uint8_t SFE_UBLOX_GNSS::addCfgValset8(uint32_t key, uint8_t value)
9393
9508
// This function takes a full 32-bit key and 64-bit value
9394
9509
uint8_t SFE_UBLOX_GNSS::sendCfgValset64(uint32_t key, uint64_t value, uint16_t maxWait)
9395
9510
{
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;
9398
9530
9399
9531
// Send VALSET command with this key and value
9400
9532
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
9404
9536
// This function takes a full 32-bit key and 32-bit value
9405
9537
uint8_t SFE_UBLOX_GNSS::sendCfgValset32(uint32_t key, uint32_t value, uint16_t maxWait)
9406
9538
{
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;
9409
9558
9410
9559
// Send VALSET command with this key and value
9411
9560
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
9415
9564
// This function takes a full 32-bit key and 16-bit value
9416
9565
uint8_t SFE_UBLOX_GNSS::sendCfgValset16(uint32_t key, uint16_t value, uint16_t maxWait)
9417
9566
{
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;
9420
9586
9421
9587
// Send VALSET command with this key and value
9422
9588
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
9426
9592
// This function takes a full 32-bit key and 8-bit value
9427
9593
uint8_t SFE_UBLOX_GNSS::sendCfgValset8(uint32_t key, uint8_t value, uint16_t maxWait)
9428
9594
{
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;
9431
9623
9432
9624
// Send VALSET command with this key and value
9433
9625
return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
9434
9626
}
9435
9627
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
+
9436
9640
//=-=-=-=-=-=-=-= "Automatic" Messages =-=-=-=-=-=-=-==-=-=-=-=-=-=-=
9437
9641
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
9438
9642
0 commit comments