From 0c576c974562329629bdc77bcc266a032cb499ba Mon Sep 17 00:00:00 2001 From: PaulZC Date: Tue, 30 Mar 2021 08:43:54 +0100 Subject: [PATCH] Adding set/getNavigationRate and set/getMeasurementRate --- keywords.txt | 4 ++ src/SparkFun_u-blox_GNSS_Arduino_Library.cpp | 75 +++++++++++++++++++- src/SparkFun_u-blox_GNSS_Arduino_Library.h | 8 ++- 3 files changed, 84 insertions(+), 3 deletions(-) diff --git a/keywords.txt b/keywords.txt index 3fcff79..21b59a5 100644 --- a/keywords.txt +++ b/keywords.txt @@ -369,6 +369,10 @@ logHNRPVT KEYWORD2 setNavigationFrequency KEYWORD2 getNavigationFrequency KEYWORD2 +setMeasurementRate KEYWORD2 +getMeasurementRate KEYWORD2 +setNavigationRate KEYWORD2 +getNavigationRate KEYWORD2 getGeometricDOP KEYWORD2 getPositionDOP KEYWORD2 diff --git a/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp b/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp index 93fe714..491116f 100644 --- a/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp +++ b/src/SparkFun_u-blox_GNSS_Arduino_Library.cpp @@ -8569,7 +8569,7 @@ boolean SFE_UBLOX_GNSS::setNavigationFrequency(uint8_t navFreq, uint16_t maxWait //Adjust the I2C polling timeout based on update rate i2cPollingWait = 1000 / (((int)navFreq) * 4); //This is the number of ms to wait between checks for new I2C data - //Query the module for the latest lat/long + //Query the module packetCfg.cls = UBX_CLASS_CFG; packetCfg.id = UBX_CFG_RATE; packetCfg.len = 0; @@ -8606,6 +8606,79 @@ uint8_t SFE_UBLOX_GNSS::getNavigationFrequency(uint16_t maxWait) return (measurementRate); } +//Set the elapsed time between GNSS measurements in milliseconds, which defines the rate +boolean SFE_UBLOX_GNSS::setMeasurementRate(uint16_t rate, uint16_t maxWait) +{ + //Adjust the I2C polling timeout based on update rate + i2cPollingWait = rate / 4; //This is the number of ms to wait between checks for new I2C data + + //Query the module + packetCfg.cls = UBX_CLASS_CFG; + packetCfg.id = UBX_CFG_RATE; + packetCfg.len = 0; + packetCfg.startingSpot = 0; + + //This will load the payloadCfg array with current settings of the given register + if (sendCommand(&packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK + return (false); //If command send fails then bail + + //payloadCfg is now loaded with current bytes. Change only the ones we need to + payloadCfg[0] = rate & 0xFF; //measRate LSB + payloadCfg[1] = rate >> 8; //measRate MSB + + return ((sendCommand(&packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK +} + +//Return the elapsed time between GNSS measurements in milliseconds, which defines the rate +uint16_t SFE_UBLOX_GNSS::getMeasurementRate(uint16_t maxWait) +{ + if (packetUBXCFGRATE == NULL) initPacketUBXCFGRATE(); //Check that RAM has been allocated for the RATE data + if (packetUBXCFGRATE == NULL) //Bail if the RAM allocation failed + return 0; + + if (packetUBXCFGRATE->moduleQueried.moduleQueried.bits.measRate == false) + getNavigationFrequencyInternal(maxWait); + packetUBXCFGRATE->moduleQueried.moduleQueried.bits.measRate = false; //Since we are about to give this to user, mark this data as stale + packetUBXCFGRATE->moduleQueried.moduleQueried.bits.all = false; + + return (packetUBXCFGRATE->data.measRate); +} + +//Set the ratio between the number of measurements and the number of navigation solutions. Unit is cycles. Max is 127. +boolean SFE_UBLOX_GNSS::setNavigationRate(uint16_t rate, uint16_t maxWait) +{ + //Query the module + packetCfg.cls = UBX_CLASS_CFG; + packetCfg.id = UBX_CFG_RATE; + packetCfg.len = 0; + packetCfg.startingSpot = 0; + + //This will load the payloadCfg array with current settings of the given register + if (sendCommand(&packetCfg, maxWait) != SFE_UBLOX_STATUS_DATA_RECEIVED) // We are expecting data and an ACK + return (false); //If command send fails then bail + + //payloadCfg is now loaded with current bytes. Change only the ones we need to + payloadCfg[2] = rate & 0xFF; //navRate LSB + payloadCfg[3] = rate >> 8; //navRate MSB + + return ((sendCommand(&packetCfg, maxWait)) == SFE_UBLOX_STATUS_DATA_SENT); // We are only expecting an ACK +} + +//Return the ratio between the number of measurements and the number of navigation solutions. Unit is cycles +uint16_t SFE_UBLOX_GNSS::getNavigationRate(uint16_t maxWait) +{ + if (packetUBXCFGRATE == NULL) initPacketUBXCFGRATE(); //Check that RAM has been allocated for the RATE data + if (packetUBXCFGRATE == NULL) //Bail if the RAM allocation failed + return 0; + + if (packetUBXCFGRATE->moduleQueried.moduleQueried.bits.navRate == false) + getNavigationFrequencyInternal(maxWait); + packetUBXCFGRATE->moduleQueried.moduleQueried.bits.navRate = false; //Since we are about to give this to user, mark this data as stale + packetUBXCFGRATE->moduleQueried.moduleQueried.bits.all = false; + + return (packetUBXCFGRATE->data.navRate); +} + // ***** DOP Helper Functions uint16_t SFE_UBLOX_GNSS::getGeometricDOP(uint16_t maxWait) diff --git a/src/SparkFun_u-blox_GNSS_Arduino_Library.h b/src/SparkFun_u-blox_GNSS_Arduino_Library.h index 0fc83dc..539fde8 100644 --- a/src/SparkFun_u-blox_GNSS_Arduino_Library.h +++ b/src/SparkFun_u-blox_GNSS_Arduino_Library.h @@ -894,8 +894,12 @@ public: // Helper functions for CFG RATE - boolean setNavigationFrequency(uint8_t navFreq, uint16_t maxWait = defaultMaxWait); //Set the number of nav solutions sent per second - uint8_t getNavigationFrequency(uint16_t maxWait = defaultMaxWait); //Get the number of nav solutions sent per second currently being output by module + boolean setNavigationFrequency(uint8_t navFreq, uint16_t maxWait = defaultMaxWait); //Set the number of nav solutions sent per second + uint8_t getNavigationFrequency(uint16_t maxWait = defaultMaxWait); //Get the number of nav solutions sent per second currently being output by module + boolean setMeasurementRate(uint16_t rate, uint16_t maxWait = defaultMaxWait); //Set the elapsed time between GNSS measurements in milliseconds, which defines the rate + uint16_t getMeasurementRate(uint16_t maxWait = defaultMaxWait); //Return the elapsed time between GNSS measurements in milliseconds + 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 + uint16_t getNavigationRate(uint16_t maxWait = defaultMaxWait); //Return the ratio between the number of measurements and the number of navigation solutions. Unit is cycles // Helper functions for DOP