Skip to content

Commit 63d8b60

Browse files
committed
Add flushCFGRATE. Ensure CFG RATE data is marked as stale by the set rate functions
1 parent b20579e commit 63d8b60

File tree

4 files changed

+43
-38
lines changed

4 files changed

+43
-38
lines changed

Diff for: examples/Example25_MeasurementAndNavigationRate/Example25_MeasurementAndNavigationRate.ino

-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@ void setup()
8181
while (1);
8282
}
8383

84-
// Another trick we can use is to mark the CFG RATE data as stale so we can be sure we read fresh data
85-
myGNSS.packetUBXCFGRATE->moduleQueried.moduleQueried.all = 0; // Mark all of the CFG RATE data as stale
86-
8784
// Read and print the updated measurement rate and navigation rate
8885

8986
rate = myGNSS.getMeasurementRate(); //Get the measurement rate of this module

Diff for: keywords.txt

+1
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ setMeasurementRate KEYWORD2
388388
getMeasurementRate KEYWORD2
389389
setNavigationRate KEYWORD2
390390
getNavigationRate KEYWORD2
391+
flushCFGRATE KEYWORD2
391392

392393
getGeometricDOP KEYWORD2
393394
getPositionDOP KEYWORD2

Diff for: src/SparkFun_u-blox_GNSS_Arduino_Library.cpp

+41-35
Original file line numberDiff line numberDiff line change
@@ -7387,38 +7387,25 @@ boolean SFE_UBLOX_GNSS::getNavigationFrequencyInternal(uint16_t maxWait)
73877387
if (packetUBXCFGRATE == NULL) //Bail if the RAM allocation failed
73887388
return (false);
73897389

7390-
if (packetUBXCFGRATE->automaticFlags.flags.bits.automatic && packetUBXCFGRATE->automaticFlags.flags.bits.implicitUpdate)
7391-
{
7392-
//The GPS is automatically reporting, we just check whether we got unread data
7393-
checkUbloxInternal(&packetCfg, UBX_CLASS_CFG, UBX_CFG_RATE);
7394-
return packetUBXCFGRATE->moduleQueried.moduleQueried.bits.all;
7395-
}
7396-
else if (packetUBXCFGRATE->automaticFlags.flags.bits.automatic && !packetUBXCFGRATE->automaticFlags.flags.bits.implicitUpdate)
7397-
{
7398-
//Someone else has to call checkUblox for us...
7399-
return (false);
7400-
}
7401-
else
7402-
{
7403-
//The GPS is not automatically reporting navigation rate so we have to poll explicitly
7404-
packetCfg.cls = UBX_CLASS_CFG;
7405-
packetCfg.id = UBX_CFG_RATE;
7406-
packetCfg.len = 0;
7407-
packetCfg.startingSpot = 0;
7408-
7409-
//The data is parsed as part of processing the response
7410-
sfe_ublox_status_e retVal = sendCommand(&packetCfg, maxWait);
7390+
// The CFG RATE message will never be produced automatically - that would be pointless.
7391+
// There is no setAutoCFGRATE function. We always need to poll explicitly.
7392+
packetCfg.cls = UBX_CLASS_CFG;
7393+
packetCfg.id = UBX_CFG_RATE;
7394+
packetCfg.len = 0;
7395+
packetCfg.startingSpot = 0;
74117396

7412-
if (retVal == SFE_UBLOX_STATUS_DATA_RECEIVED)
7413-
return (true);
7397+
//The data is parsed as part of processing the response
7398+
sfe_ublox_status_e retVal = sendCommand(&packetCfg, maxWait);
74147399

7415-
if (retVal == SFE_UBLOX_STATUS_DATA_OVERWRITTEN)
7416-
{
7417-
return (true);
7418-
}
7400+
if (retVal == SFE_UBLOX_STATUS_DATA_RECEIVED)
7401+
return (true);
74197402

7420-
return (false);
7403+
if (retVal == SFE_UBLOX_STATUS_DATA_OVERWRITTEN)
7404+
{
7405+
return (true);
74217406
}
7407+
7408+
return (false);
74227409
}
74237410

74247411
// PRIVATE: Allocate RAM for packetUBXCFGRATE and initialize it
@@ -7431,10 +7418,10 @@ boolean SFE_UBLOX_GNSS::initPacketUBXCFGRATE()
74317418
_debugSerial->println(F("initPacketUBXCFGRATE: PANIC! RAM allocation failed!"));
74327419
return (false);
74337420
}
7434-
packetUBXCFGRATE->automaticFlags.flags.all = 0;
7435-
packetUBXCFGRATE->callbackPointer = NULL;
7436-
packetUBXCFGRATE->callbackData = NULL;
7437-
packetUBXCFGRATE->moduleQueried.moduleQueried.all = 0;
7421+
packetUBXCFGRATE->automaticFlags.flags.all = 0; // Redundant
7422+
packetUBXCFGRATE->callbackPointer = NULL; // Redundant
7423+
packetUBXCFGRATE->callbackData = NULL; // Redundant
7424+
packetUBXCFGRATE->moduleQueried.moduleQueried.all = 0; // Mark all data as stale/read
74387425
return (true);
74397426
}
74407427

@@ -9114,7 +9101,11 @@ boolean SFE_UBLOX_GNSS::setNavigationFrequency(uint8_t navFreq, uint16_t maxWait
91149101
payloadCfg[0] = measurementRate & 0xFF; //measRate LSB
91159102
payloadCfg[1] = measurementRate >> 8; //measRate MSB
91169103

9117-
return ((sendCommand(&packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
9104+
boolean result = ((sendCommand(&packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
9105+
9106+
flushCFGRATE(); // Mark the polled measurement and navigation rate data as stale
9107+
9108+
return (result);
91189109
}
91199110

91209111
//Get the rate at which the module is outputting nav solutions
@@ -9155,7 +9146,11 @@ boolean SFE_UBLOX_GNSS::setMeasurementRate(uint16_t rate, uint16_t maxWait)
91559146
payloadCfg[0] = rate & 0xFF; //measRate LSB
91569147
payloadCfg[1] = rate >> 8; //measRate MSB
91579148

9158-
return ((sendCommand(&packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
9149+
boolean result = ((sendCommand(&packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
9150+
9151+
flushCFGRATE(); // Mark the polled measurement and navigation rate data as stale
9152+
9153+
return (result);
91599154
}
91609155

91619156
//Return the elapsed time between GNSS measurements in milliseconds, which defines the rate
@@ -9190,7 +9185,11 @@ boolean SFE_UBLOX_GNSS::setNavigationRate(uint16_t rate, uint16_t maxWait)
91909185
payloadCfg[2] = rate & 0xFF; //navRate LSB
91919186
payloadCfg[3] = rate >> 8; //navRate MSB
91929187

9193-
return ((sendCommand(&packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
9188+
boolean result = ((sendCommand(&packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK
9189+
9190+
flushCFGRATE(); // Mark the polled measurement and navigation rate data as stale
9191+
9192+
return (result);
91949193
}
91959194

91969195
//Return the ratio between the number of measurements and the number of navigation solutions. Unit is cycles
@@ -9208,6 +9207,13 @@ uint16_t SFE_UBLOX_GNSS::getNavigationRate(uint16_t maxWait)
92089207
return (packetUBXCFGRATE->data.navRate);
92099208
}
92109209

9210+
//Mark the CFG RATE data as read/stale
9211+
void SFE_UBLOX_GNSS::flushCFGRATE()
9212+
{
9213+
if (packetUBXCFGRATE == NULL) return; // Bail if RAM has not been allocated (otherwise we could be writing anywhere!)
9214+
packetUBXCFGRATE->moduleQueried.moduleQueried.all = 0; //Mark all datums as stale (read before)
9215+
}
9216+
92119217
// ***** DOP Helper Functions
92129218

92139219
uint16_t SFE_UBLOX_GNSS::getGeometricDOP(uint16_t maxWait)

Diff for: src/SparkFun_u-blox_GNSS_Arduino_Library.h

+1
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,7 @@ class SFE_UBLOX_GNSS
936936
uint16_t getMeasurementRate(uint16_t maxWait = defaultMaxWait); //Return the elapsed time between GNSS measurements in milliseconds
937937
boolean setNavigationRate(uint16_t rate, uint16_t maxWait = defaultMaxWait); //Set the ratio between the number of measurements and the number of navigation solutions. Unit is cycles. Max is 127
938938
uint16_t getNavigationRate(uint16_t maxWait = defaultMaxWait); //Return the ratio between the number of measurements and the number of navigation solutions. Unit is cycles
939+
void flushCFGRATE(); // Mark the measurement and navigation rate data as stale - used by the set rate functions
939940

940941
// Helper functions for DOP
941942

0 commit comments

Comments
 (0)