Skip to content

Commit 6613ec5

Browse files
committed
Add cfgRst and cfgCfg to simplify resets and saves
1 parent dd574f5 commit 6613ec5

File tree

2 files changed

+48
-63
lines changed

2 files changed

+48
-63
lines changed

src/u-blox_GNSS.cpp

+45-62
Original file line numberDiff line numberDiff line change
@@ -6548,81 +6548,59 @@ void DevUBLOXGNSS::factoryReset()
65486548
{
65496549
// Copy default settings to permanent
65506550
// 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);
65636553
hardReset(); // cause factory default config to actually be loaded and used cleanly
65646554
}
65656555

65666556
void DevUBLOXGNSS::hardReset()
65676557
{
65686558
// 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);
65786561
}
65796562

65806563
void DevUBLOXGNSS::softwareResetGNSSOnly()
65816564
{
65826565
// 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);
65926568
}
65936569

65946570
void DevUBLOXGNSS::softwareEnableGNSS(bool enable)
65956571
{
65966572
// 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+
{
65976580
packetCfg.cls = UBX_CLASS_CFG;
65986581
packetCfg.id = UBX_CFG_RST;
6599-
packetCfg.len = 4;
6582+
packetCfg.len = len;
66006583
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++;
66056586
sendCommand(&packetCfg, 0); // don't expect ACK
66066587
}
66076588

66086589
// Reset module to factory defaults
66096590
// This still works but it is the old way of configuring ublox modules. See getVal and setVal for the new methods
66106591
bool DevUBLOXGNSS::factoryDefault(uint16_t maxWait)
66116592
{
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];
66166594

66176595
// Clear packet payload
6618-
memset(payloadCfg, 0, packetCfg.len);
6596+
memset(configSelective, 0, 12);
66196597

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;
66246602

6625-
return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
6603+
return (cfgCfg(configSelective, 12, maxWait));
66266604
}
66276605

66286606
// Save configuration to BBR / Flash
@@ -6631,37 +6609,42 @@ bool DevUBLOXGNSS::factoryDefault(uint16_t maxWait)
66316609
// This still works but it is the old way of configuring ublox modules. See getVal and setVal for the new methods
66326610
bool DevUBLOXGNSS::saveConfiguration(uint16_t maxWait)
66336611
{
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];
66386613

66396614
// Clear packet payload
6640-
memset(payloadCfg, 0, packetCfg.len);
6615+
memset(configSelective, 0, 12);
66416616

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;
66446619

6645-
return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
6620+
return (cfgCfg(configSelective, 12, maxWait));
66466621
}
66476622

66486623
// Save the selected configuration sub-sections to flash and BBR (battery backed RAM)
66496624
// This still works but it is the old way of configuring ublox modules. See getVal and setVal for the new methods
66506625
bool DevUBLOXGNSS::saveConfigSelective(uint32_t configMask, uint16_t maxWait)
66516626
{
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];
66566628

66576629
// Clear packet payload
6658-
memset(payloadCfg, 0, packetCfg.len);
6630+
memset(configSelective, 0, 12);
66596631

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+
}
66646639

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++;
66656648
return (sendCommand(&packetCfg, maxWait) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
66666649
}
66676650

src/u-blox_GNSS.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,17 @@ class DevUBLOXGNSS
298298
// Reset to defaults
299299

300300
void factoryReset(); // Send factory reset sequence (i.e. load "default" configuration and perform hardReset)
301+
bool factoryDefault(uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Reset module to factory defaults
301302
void hardReset(); // Perform a reset leading to a cold start (zero info start-up)
302303
void softwareResetGNSSOnly(); // Controlled Software Reset (GNSS only) only restarts the GNSS tasks, without reinitializing the full system or reloading any stored configuration.
303304
void softwareEnableGNSS(bool enable); // Controlled Software Start / Stop (GNSS only)
304-
bool factoryDefault(uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Reset module to factory defaults
305+
void cfgRst(uint8_t *data, uint8_t len); // Common method for CFG RST
305306

306307
// Save configuration to BBR / Flash
307308

308309
bool saveConfiguration(uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Save current configuration to flash and BBR (battery backed RAM)
309310
bool saveConfigSelective(uint32_t configMask, uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Save the selected configuration sub-sections to flash and BBR (battery backed RAM)
311+
bool cfgCfg(uint8_t *data, uint8_t len, uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Common method for CFG CFG
310312

311313
// Functions used for RTK and base station setup
312314
bool setSurveyMode(uint8_t mode, uint16_t observationTime, float requiredAccuracy, uint16_t maxWait = kUBLOXGNSSDefaultMaxWait); // Control survey in mode

0 commit comments

Comments
 (0)