Skip to content

Commit

Permalink
bug meshtastic#376 wip - we now respect the new gps_operating_mode pref.
Browse files Browse the repository at this point in the history
  • Loading branch information
geeksville committed Oct 5, 2020
1 parent 3c1c11e commit 7366424
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 20 deletions.
10 changes: 1 addition & 9 deletions docs/software/gps-todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/Power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
39 changes: 31 additions & 8 deletions src/gps/GPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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;

Expand All @@ -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);
}
Expand All @@ -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;

Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/gps/GPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ class GPS
*/
uint32_t getSleepTime() const;

GpsOperation getGpsOp() const;

/**
* Tell users we have new GPS readings
*/
Expand Down
7 changes: 6 additions & 1 deletion src/gps/UBloxGPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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());
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/sleep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7366424

Please sign in to comment.