Add timeout to ublox PMREQ command (#2851)

This commit is contained in:
Jonathan Bennett 2023-10-01 20:39:18 -05:00 committed by GitHub
parent 5ecdbd0dbb
commit 50db2d0e9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 10 deletions

View File

@ -433,7 +433,7 @@ GPS::~GPS()
notifyGPSSleepObserver.observe(&notifyGPSSleep); notifyGPSSleepObserver.observe(&notifyGPSSleep);
} }
void GPS::setGPSPower(bool on, bool standbyOnly) void GPS::setGPSPower(bool on, bool standbyOnly, uint32_t sleepTime)
{ {
LOG_INFO("Setting GPS power=%d\n", on); LOG_INFO("Setting GPS power=%d\n", on);
if (on) { if (on) {
@ -483,6 +483,10 @@ void GPS::setGPSPower(bool on, bool standbyOnly)
if (!on) { if (!on) {
if (gnssModel == GNSS_MODEL_UBLOX) { if (gnssModel == GNSS_MODEL_UBLOX) {
uint8_t msglen; uint8_t msglen;
LOG_DEBUG("Sleep Time: %i\n", sleepTime);
for (int i = 0; i < 4; i++) {
gps->_message_PMREQ[0 + i] = sleepTime >> (i * 8); // Encode the sleep time in millis into the packet
}
msglen = gps->makeUBXPacket(0x02, 0x41, 0x08, gps->_message_PMREQ); msglen = gps->makeUBXPacket(0x02, 0x41, 0x08, gps->_message_PMREQ);
gps->_serial_gps->write(gps->UBXscratch, msglen); gps->_serial_gps->write(gps->UBXscratch, msglen);
} }
@ -514,7 +518,7 @@ void GPS::setAwake(bool on)
LOG_DEBUG("WANT GPS=%d\n", on); LOG_DEBUG("WANT GPS=%d\n", on);
isAwake = on; isAwake = on;
if (!enabled) { // short circuit if the user has disabled GPS if (!enabled) { // short circuit if the user has disabled GPS
setGPSPower(false, false); setGPSPower(false, false, 0);
return; return;
} }
@ -532,12 +536,12 @@ void GPS::setAwake(bool on)
} }
if ((int32_t)getSleepTime() - averageLockTime > if ((int32_t)getSleepTime() - averageLockTime >
15 * 60 * 1000) { // 15 minutes is probably long enough to make a complete poweroff worth it. 15 * 60 * 1000) { // 15 minutes is probably long enough to make a complete poweroff worth it.
setGPSPower(on, false); setGPSPower(on, false, getSleepTime() - averageLockTime);
} else if ((int32_t)getSleepTime() - averageLockTime > 10000) { // 10 seconds is enough for standby } else if ((int32_t)getSleepTime() - averageLockTime > 10000) { // 10 seconds is enough for standby
#ifdef GPS_UC6580 #ifdef GPS_UC6580
setGPSPower(on, false); setGPSPower(on, false, getSleepTime() - averageLockTime);
#else #else
setGPSPower(on, true); setGPSPower(on, true, getSleepTime() - averageLockTime);
#endif #endif
} else if (averageLockTime > 20000) { } else if (averageLockTime > 20000) {
averageLockTime -= 1000; // eventually want to sleep again. averageLockTime -= 1000; // eventually want to sleep again.
@ -899,7 +903,7 @@ GPS *GPS::createGps()
LOG_DEBUG("Using " NMEA_MSG_GXGSA " for 3DFIX and PDOP\n"); LOG_DEBUG("Using " NMEA_MSG_GXGSA " for 3DFIX and PDOP\n");
#endif #endif
new_gps->setGPSPower(true, false); new_gps->setGPSPower(true, false, 0);
#ifdef PIN_GPS_RESET #ifdef PIN_GPS_RESET
digitalWrite(PIN_GPS_RESET, GPS_RESET_MODE); // assert for 10ms digitalWrite(PIN_GPS_RESET, GPS_RESET_MODE); // assert for 10ms

View File

@ -94,7 +94,7 @@ class GPS : private concurrency::OSThread
/** If !NULL we will use this serial port to construct our GPS */ /** If !NULL we will use this serial port to construct our GPS */
static HardwareSerial *_serial_gps; static HardwareSerial *_serial_gps;
static const uint8_t _message_PMREQ[]; static uint8_t _message_PMREQ[];
static const uint8_t _message_CFG_RXM_PSM[]; static const uint8_t _message_CFG_RXM_PSM[];
static const uint8_t _message_CFG_RXM_ECO[]; static const uint8_t _message_CFG_RXM_ECO[];
static const uint8_t _message_CFG_PM2[]; static const uint8_t _message_CFG_PM2[];
@ -132,7 +132,7 @@ class GPS : private concurrency::OSThread
// Disable the thread // Disable the thread
int32_t disable() override; int32_t disable() override;
void setGPSPower(bool on, bool standbyOnly); void setGPSPower(bool on, bool standbyOnly, uint32_t sleepTime);
/// Returns true if we have acquired GPS lock. /// Returns true if we have acquired GPS lock.
virtual bool hasLock(); virtual bool hasLock();

View File

@ -1,4 +1,4 @@
const uint8_t GPS::_message_PMREQ[] PROGMEM = { uint8_t GPS::_message_PMREQ[] PROGMEM = {
0x00, 0x00, // 4 bytes duration of request task 0x00, 0x00, // 4 bytes duration of request task
0x00, 0x00, // (milliseconds) 0x00, 0x00, // (milliseconds)
0x02, 0x00, // Task flag bitfield 0x02, 0x00, // Task flag bitfield

View File

@ -175,7 +175,7 @@ void doDeepSleep(uint32_t msecToWake, bool skipPreflight = false)
nodeDB.saveToDisk(); nodeDB.saveToDisk();
// Kill GPS power completely (even if previously we just had it in sleep mode) // Kill GPS power completely (even if previously we just had it in sleep mode)
gps->setGPSPower(false, false); gps->setGPSPower(false, false, 0);
setLed(false); setLed(false);