@@ -6548,81 +6548,59 @@ void DevUBLOXGNSS::factoryReset()
6548
6548
{
6549
6549
// Copy default settings to permanent
6550
6550
// Note: this does not load the permanent configuration into the current configuration. Calling factoryDefault() will do that.
6551
- packetCfg.cls = UBX_CLASS_CFG;
6552
- packetCfg.id = UBX_CFG_CFG;
6553
- packetCfg.len = 13;
6554
- packetCfg.startingSpot = 0;
6555
- for (uint8_t i = 0; i < 4; i++)
6556
- {
6557
- payloadCfg[0 + i] = 0xff; // clear mask: copy default config to permanent config
6558
- payloadCfg[4 + i] = 0x00; // save mask: don't save current to permanent
6559
- payloadCfg[8 + i] = 0x00; // load mask: don't copy permanent config to current
6560
- }
6561
- payloadCfg[12] = 0xff; // all forms of permanent memory
6562
- sendCommand(&packetCfg, 0); // don't expect ACK
6551
+ uint8_t clearMemory[13] = {0xff,0xff,0xff,0xff,0,0,0,0,0,0,0,0,0xff};
6552
+ cfgCfg(clearMemory, 13, 0);
6563
6553
hardReset(); // cause factory default config to actually be loaded and used cleanly
6564
6554
}
6565
6555
6566
6556
void DevUBLOXGNSS::hardReset()
6567
6557
{
6568
6558
// Issue hard reset
6569
- packetCfg.cls = UBX_CLASS_CFG;
6570
- packetCfg.id = UBX_CFG_RST;
6571
- packetCfg.len = 4;
6572
- packetCfg.startingSpot = 0;
6573
- payloadCfg[0] = 0xff; // cold start
6574
- payloadCfg[1] = 0xff; // cold start
6575
- payloadCfg[2] = 0; // 0=HW reset
6576
- payloadCfg[3] = 0; // reserved
6577
- sendCommand(&packetCfg, 0); // don't expect ACK
6559
+ uint8_t softwareResetGNSS[4] = {0xff,0xff,0,0};
6560
+ cfgRst(softwareResetGNSS, 4);
6578
6561
}
6579
6562
6580
6563
void DevUBLOXGNSS::softwareResetGNSSOnly()
6581
6564
{
6582
6565
// Issue controlled software reset (GNSS only)
6583
- packetCfg.cls = UBX_CLASS_CFG;
6584
- packetCfg.id = UBX_CFG_RST;
6585
- packetCfg.len = 4;
6586
- packetCfg.startingSpot = 0;
6587
- payloadCfg[0] = 0; // hot start
6588
- payloadCfg[1] = 0; // hot start
6589
- payloadCfg[2] = 0x02; // 0x02 = Controlled software reset (GNSS only)
6590
- payloadCfg[3] = 0; // reserved
6591
- sendCommand(&packetCfg, 0); // don't expect ACK
6566
+ uint8_t softwareResetGNSS[4] = {0,0,0x02,0};
6567
+ cfgRst(softwareResetGNSS, 4);
6592
6568
}
6593
6569
6594
6570
void DevUBLOXGNSS::softwareEnableGNSS(bool enable)
6595
6571
{
6596
6572
// Issue controlled software reset (GNSS only)
6573
+ uint8_t softwareEnable[4] = {0,0,0,0};
6574
+ softwareEnable[2] = enable ? 0x09 : 0x08; // 0x09 = start GNSS, 0x08 = stop GNSS
6575
+ cfgRst(softwareEnable, 4);
6576
+ }
6577
+
6578
+ void DevUBLOXGNSS::cfgRst(uint8_t *data, uint8_t len)
6579
+ {
6597
6580
packetCfg.cls = UBX_CLASS_CFG;
6598
6581
packetCfg.id = UBX_CFG_RST;
6599
- packetCfg.len = 4 ;
6582
+ packetCfg.len = len ;
6600
6583
packetCfg.startingSpot = 0;
6601
- payloadCfg[0] = 0; // hot start
6602
- payloadCfg[1] = 0; // hot start
6603
- payloadCfg[2] = enable ? 0x09 : 0x08; // 0x09 = start GNSS, 0x08 = stop GNSS
6604
- payloadCfg[3] = 0; // reserved
6584
+ for (uint8_t i = 0; i < len; i++)
6585
+ payloadCfg[i] = *data++;
6605
6586
sendCommand(&packetCfg, 0); // don't expect ACK
6606
6587
}
6607
6588
6608
6589
// Reset module to factory defaults
6609
6590
// This still works but it is the old way of configuring ublox modules. See getVal and setVal for the new methods
6610
6591
bool DevUBLOXGNSS::factoryDefault(uint16_t maxWait)
6611
6592
{
6612
- packetCfg.cls = UBX_CLASS_CFG;
6613
- packetCfg.id = UBX_CFG_CFG;
6614
- packetCfg.len = 12;
6615
- packetCfg.startingSpot = 0;
6593
+ uint8_t configSelective[12];
6616
6594
6617
6595
// Clear packet payload
6618
- memset(payloadCfg , 0, packetCfg.len );
6596
+ memset(configSelective , 0, 12 );
6619
6597
6620
- packetCfg.payload [0] = 0xFF; // Set any bit in the clearMask field to clear saved config
6621
- packetCfg.payload [1] = 0xFF;
6622
- packetCfg.payload [8] = 0xFF; // Set any bit in the loadMask field to discard current config and rebuild from lower non-volatile memory layers
6623
- packetCfg.payload [9] = 0xFF;
6598
+ configSelective [0] = 0xFF; // Set any bit in the clearMask field to clear saved config
6599
+ configSelective [1] = 0xFF;
6600
+ configSelective [8] = 0xFF; // Set any bit in the loadMask field to discard current config and rebuild from lower non-volatile memory layers
6601
+ configSelective [9] = 0xFF;
6624
6602
6625
- return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
6603
+ return (cfgCfg(configSelective, 12, maxWait));
6626
6604
}
6627
6605
6628
6606
// Save configuration to BBR / Flash
@@ -6631,37 +6609,42 @@ bool DevUBLOXGNSS::factoryDefault(uint16_t maxWait)
6631
6609
// This still works but it is the old way of configuring ublox modules. See getVal and setVal for the new methods
6632
6610
bool DevUBLOXGNSS::saveConfiguration(uint16_t maxWait)
6633
6611
{
6634
- packetCfg.cls = UBX_CLASS_CFG;
6635
- packetCfg.id = UBX_CFG_CFG;
6636
- packetCfg.len = 12;
6637
- packetCfg.startingSpot = 0;
6612
+ uint8_t configSelective[12];
6638
6613
6639
6614
// Clear packet payload
6640
- memset(payloadCfg , 0, packetCfg.len );
6615
+ memset(configSelective , 0, 12 );
6641
6616
6642
- packetCfg.payload [4] = 0xFF; // Set any bit in the saveMask field to save current config to Flash and BBR
6643
- packetCfg.payload [5] = 0xFF;
6617
+ configSelective [4] = 0xFF; // Set any bit in the saveMask field to save current config to Flash and BBR
6618
+ configSelective [5] = 0xFF;
6644
6619
6645
- return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
6620
+ return (cfgCfg(configSelective, 12, maxWait));
6646
6621
}
6647
6622
6648
6623
// Save the selected configuration sub-sections to flash and BBR (battery backed RAM)
6649
6624
// This still works but it is the old way of configuring ublox modules. See getVal and setVal for the new methods
6650
6625
bool DevUBLOXGNSS::saveConfigSelective(uint32_t configMask, uint16_t maxWait)
6651
6626
{
6652
- packetCfg.cls = UBX_CLASS_CFG;
6653
- packetCfg.id = UBX_CFG_CFG;
6654
- packetCfg.len = 12;
6655
- packetCfg.startingSpot = 0;
6627
+ uint8_t configSelective[12];
6656
6628
6657
6629
// Clear packet payload
6658
- memset(payloadCfg , 0, packetCfg.len );
6630
+ memset(configSelective , 0, 12 );
6659
6631
6660
- packetCfg.payload[4] = configMask & 0xFF; // Set the appropriate bits in the saveMask field to save current config to Flash and BBR
6661
- packetCfg.payload[5] = (configMask >> 8) & 0xFF;
6662
- packetCfg.payload[6] = (configMask >> 16) & 0xFF;
6663
- packetCfg.payload[7] = (configMask >> 24) & 0xFF;
6632
+ configSelective[4] = configMask & 0xFF; // Set the appropriate bits in the saveMask field to save current config to Flash and BBR
6633
+ configSelective[5] = (configMask >> 8) & 0xFF;
6634
+ configSelective[6] = (configMask >> 16) & 0xFF;
6635
+ configSelective[7] = (configMask >> 24) & 0xFF;
6636
+
6637
+ return (cfgCfg(configSelective, 12, maxWait));
6638
+ }
6664
6639
6640
+ bool DevUBLOXGNSS::cfgCfg(uint8_t *data, uint8_t len, uint16_t maxWait)
6641
+ {
6642
+ packetCfg.cls = UBX_CLASS_CFG;
6643
+ packetCfg.id = UBX_CFG_CFG;
6644
+ packetCfg.len = len;
6645
+ packetCfg.startingSpot = 0;
6646
+ for (uint8_t i = 0; i < len; i++)
6647
+ payloadCfg[i] = *data++;
6665
6648
return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
6666
6649
}
6667
6650
0 commit comments