From 736642455fba0342888ce7457af20aafbde414ea Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Tue, 6 Oct 2020 05:34:56 +0800 Subject: [PATCH] bug #376 wip - we now respect the new gps_operating_mode pref. --- docs/software/gps-todo.txt | 10 +--------- src/Power.cpp | 2 +- src/gps/GPS.cpp | 39 ++++++++++++++++++++++++++++++-------- src/gps/GPS.h | 2 ++ src/gps/UBloxGPS.cpp | 7 ++++++- src/sleep.cpp | 3 ++- 6 files changed, 43 insertions(+), 20 deletions(-) diff --git a/docs/software/gps-todo.txt b/docs/software/gps-todo.txt index dc74f8df..872fd922 100644 --- a/docs/software/gps-todo.txt +++ b/docs/software/gps-todo.txt @@ -3,17 +3,9 @@ gps todo - bug 376 for taiwan region: bin/run.sh --set region 8 -after sleep we declare success without real new data - -handle the various GPS modes - fix poll interval for sending commands to ublox -handle maxint parameters - -if not sharing location, don't even power up the GPS - -if we go to sleep without getting a location set hasValidLocation to false +change defaults to 2 min properly handle time only modes diff --git a/src/Power.cpp b/src/Power.cpp index f6ae1c69..bb89dda6 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -172,7 +172,7 @@ bool Power::axp192Init() DEBUG_MSG("----------------------------------------\n"); axp.setPowerOutPut(AXP192_LDO2, AXP202_ON); // LORA radio - axp.setPowerOutPut(AXP192_LDO3, AXP202_ON); // GPS main power + // axp.setPowerOutPut(AXP192_LDO3, AXP202_ON); // GPS main power - now turned on in setGpsPower axp.setPowerOutPut(AXP192_DCDC2, AXP202_ON); axp.setPowerOutPut(AXP192_EXTEN, AXP202_ON); axp.setPowerOutPut(AXP192_DCDC1, AXP202_ON); diff --git a/src/gps/GPS.cpp b/src/gps/GPS.cpp index 188d4e98..2f8e636e 100644 --- a/src/gps/GPS.cpp +++ b/src/gps/GPS.cpp @@ -130,15 +130,32 @@ void GPS::setAwake(bool on) } } +GpsOperation GPS::getGpsOp() const +{ + auto op = radioConfig.preferences.gps_operation; + + if (op == GpsOperation_GpsOpUnset) + op = (radioConfig.preferences.location_share == LocationSharing_LocDisabled) ? GpsOperation_GpsOpTimeOnly + : GpsOperation_GpsOpMobile; + + return op; +} + /** Get how long we should stay looking for each aquisition in msecs */ uint32_t GPS::getWakeTime() const { uint32_t t = radioConfig.preferences.gps_attempt_time; - // fixme check modes + auto op = getGpsOp(); + if ((timeSetFromGPS && op == GpsOperation_GpsOpTimeOnly) || (op == GpsOperation_GpsOpDisabled)) + t = UINT32_MAX; // Sleep forever now + + if (t == UINT32_MAX) + return t; // already maxint + if (t == 0) - t = 30; + t = 2 * 60; // default to 2 mins t *= 1000; // msecs @@ -151,9 +168,12 @@ uint32_t GPS::getSleepTime() const { uint32_t t = radioConfig.preferences.gps_update_interval; + if (t == UINT32_MAX) + return t; // already maxint + // fixme check modes if (t == 0) - t = 30; + t = 30; // 2 mins t *= 1000; @@ -180,7 +200,8 @@ void GPS::loop() // If we are overdue for an update, turn on the GPS and at least publish the current status uint32_t now = millis(); - if ((now - lastSleepStartMsec) > getSleepTime() && !isAwake) { + auto sleepTime = getSleepTime(); + if (!isAwake && sleepTime != UINT32_MAX && (now - lastSleepStartMsec) > sleepTime) { // We now want to be awake - so wake up the GPS setAwake(true); } @@ -195,10 +216,12 @@ void GPS::loop() bool gotLoc = lookForLocation(); // We've been awake too long - force sleep - bool tooLong = (now - lastWakeStartMsec) > getWakeTime(); + auto wakeTime = getWakeTime(); + bool tooLong = wakeTime != UINT32_MAX && (now - lastWakeStartMsec) > wakeTime; // Once we get a location we no longer desperately want an update - if (gotLoc || tooLong) { + // or if we got a time and we are in GpsOpTimeOnly mode + if (gotLoc || tooLong || (gotTime && getGpsOp() == GpsOperation_GpsOpTimeOnly)) { if (gotLoc) hasValidLocation = true; @@ -216,8 +239,8 @@ void GPS::loop() void GPS::forceWake(bool on) { if (on) { - DEBUG_MSG("Looking for GPS lock\n"); - lastSleepStartMsec = 0; // Force an update ASAP + DEBUG_MSG("llowing GPS lock\n"); + // lastSleepStartMsec = 0; // Force an update ASAP wakeAllowed = true; } else { wakeAllowed = false; diff --git a/src/gps/GPS.h b/src/gps/GPS.h index d4abfd11..3a7279c2 100644 --- a/src/gps/GPS.h +++ b/src/gps/GPS.h @@ -133,6 +133,8 @@ class GPS */ uint32_t getSleepTime() const; + GpsOperation getGpsOp() const; + /** * Tell users we have new GPS readings */ diff --git a/src/gps/UBloxGPS.cpp b/src/gps/UBloxGPS.cpp index dbe55da4..e34513d2 100644 --- a/src/gps/UBloxGPS.cpp +++ b/src/gps/UBloxGPS.cpp @@ -167,7 +167,10 @@ bool UBloxGPS::lookForLocation() longitude = ublox.getLongitude(0); altitude = ublox.getAltitudeMSL(0) / 1000; // in mm convert to meters dop = ublox.getPDOP(0); // PDOP (an accuracy metric) is reported in 10^2 units so we have to scale down when we use it - heading = ublox.getHeading(0); + + // Note: heading is only currently implmented in the ublox for the 8m chipset - therefore + // don't read it here - it will generate an ignored getPVT command on the 6ms + // heading = ublox.getHeading(0); numSatellites = ublox.getSIV(0); // bogus lat lon is reported as 0 or 0 (can be bogus just for one) @@ -176,6 +179,8 @@ bool UBloxGPS::lookForLocation() (latitude != 0) && (longitude != 0) && (latitude <= 900000000 && latitude >= -900000000) && (numSatellites > 0); } else { // Ask for a new position fix - hopefully it will have results ready by next time + ublox.getSIV(maxWait()); + ublox.getPDOP(maxWait()); ublox.getP(maxWait()); } } diff --git a/src/sleep.cpp b/src/sleep.cpp index 731273c9..e96fe512 100644 --- a/src/sleep.cpp +++ b/src/sleep.cpp @@ -176,7 +176,8 @@ void doDeepSleep(uint64_t msecToWake) // axp.setPowerOutPut(AXP192_LDO2, AXP202_OFF); // LORA radio - setGPSPower(false); + // now done by UBloxGPS.cpp + // setGPSPower(false); } #endif