sforkowany z mirror/meshtastic-firmware
bug #376 wip - we now kill gps power when it is supposed to be asleep
rodzic
b072eec4ac
commit
3c1c11e439
|
@ -3,14 +3,14 @@ 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
|
||||
|
||||
handle loss of lock at end of wake (gotLocThisTime)
|
||||
|
||||
if not sharing location, don't even power up the GPS
|
||||
|
||||
if we go to sleep without getting a location set hasValidLocation to false
|
||||
|
|
|
@ -95,9 +95,13 @@ uint32_t getValidTime()
|
|||
|
||||
bool GPS::setup()
|
||||
{
|
||||
setAwake(true); // Wake GPS power before doing any init
|
||||
bool ok = setupGPS();
|
||||
|
||||
if (ok)
|
||||
notifySleepObserver.observe(¬ifySleep);
|
||||
|
||||
return true;
|
||||
return ok;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -175,7 +179,6 @@ 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();
|
||||
bool mustPublishUpdate = false;
|
||||
|
||||
if ((now - lastSleepStartMsec) > getSleepTime() && !isAwake) {
|
||||
// We now want to be awake - so wake up the GPS
|
||||
|
|
|
@ -79,6 +79,9 @@ class GPS
|
|||
void forceWake(bool on);
|
||||
|
||||
protected:
|
||||
/// Do gps chipset specific init, return true for success
|
||||
virtual bool setupGPS() = 0;
|
||||
|
||||
/// If possible force the GPS into sleep/low power mode
|
||||
virtual void sleep() {}
|
||||
|
||||
|
@ -134,7 +137,6 @@ class GPS
|
|||
* Tell users we have new GPS readings
|
||||
*/
|
||||
void publishUpdate();
|
||||
|
||||
};
|
||||
|
||||
extern GPS *gps;
|
||||
|
|
|
@ -10,14 +10,13 @@ static int32_t toDegInt(RawDegrees d)
|
|||
return r;
|
||||
}
|
||||
|
||||
bool NMEAGPS::setup()
|
||||
bool NMEAGPS::setupGPS()
|
||||
{
|
||||
#ifdef PIN_GPS_PPS
|
||||
// pulse per second
|
||||
// FIXME - move into shared GPS code
|
||||
pinMode(PIN_GPS_PPS, INPUT);
|
||||
#endif
|
||||
GPS::setup();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ class NMEAGPS : public GPS
|
|||
TinyGPSPlus reader;
|
||||
|
||||
public:
|
||||
virtual bool setup();
|
||||
virtual bool setupGPS();
|
||||
|
||||
protected:
|
||||
/** Subclasses should look for serial rx characters here and feed it to their GPS parser
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "UBloxGPS.h"
|
||||
#include "error.h"
|
||||
#include "sleep.h"
|
||||
#include <assert.h>
|
||||
|
||||
UBloxGPS::UBloxGPS() {}
|
||||
|
@ -22,7 +23,7 @@ bool UBloxGPS::tryConnect()
|
|||
return isConnected;
|
||||
}
|
||||
|
||||
bool UBloxGPS::setup()
|
||||
bool UBloxGPS::setupGPS()
|
||||
{
|
||||
if (_serial_gps) {
|
||||
#ifdef GPS_RX_PIN
|
||||
|
@ -33,12 +34,6 @@ bool UBloxGPS::setup()
|
|||
// _serial_gps.setRxBufferSize(1024); // the default is 256
|
||||
}
|
||||
|
||||
#ifdef GPS_POWER_EN
|
||||
pinMode(GPS_POWER_EN, OUTPUT);
|
||||
digitalWrite(GPS_POWER_EN, 1);
|
||||
delay(200); // Give time for the GPS to startup after we gave power
|
||||
#endif
|
||||
|
||||
ublox.enableDebugging(Serial);
|
||||
|
||||
// try a second time, the ublox lib serial parsing is buggy?
|
||||
|
@ -49,15 +44,11 @@ bool UBloxGPS::setup()
|
|||
if (isConnected) {
|
||||
DEBUG_MSG("Connected to UBLOX GPS successfully\n");
|
||||
|
||||
GPS::setup();
|
||||
|
||||
if (!setUBXMode())
|
||||
recordCriticalError(UBloxInitFailed); // Don't halt the boot if saving the config fails, but do report the bug
|
||||
|
||||
return true;
|
||||
} else {
|
||||
// Note: we do not call superclass setup in this case, because we dont want sleep observer registered
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -134,7 +125,8 @@ void UBloxGPS::whileActive()
|
|||
*/
|
||||
bool UBloxGPS::lookForTime()
|
||||
{
|
||||
if (fixType >= 2 && ublox.getT(maxWait())) {
|
||||
if (fixType >= 2) {
|
||||
if (ublox.moduleQueried.gpsSecond) {
|
||||
/* Convert to unix time
|
||||
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January
|
||||
1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).
|
||||
|
@ -150,8 +142,11 @@ bool UBloxGPS::lookForTime()
|
|||
perhapsSetRTC(t);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
ublox.getT(maxWait()); // ask for new time data - hopefully ready when we come back
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -165,7 +160,8 @@ bool UBloxGPS::lookForLocation()
|
|||
bool foundLocation = false;
|
||||
|
||||
// we only notify if position has changed due to a new fix
|
||||
if ((fixType >= 3 && fixType <= 4) && ublox.getP(maxWait())) // rd fixes only
|
||||
if ((fixType >= 3 && fixType <= 4)) {
|
||||
if (ublox.moduleQueried.latitude) // rd fixes only
|
||||
{
|
||||
latitude = ublox.getLatitude(0);
|
||||
longitude = ublox.getLongitude(0);
|
||||
|
@ -178,6 +174,10 @@ bool UBloxGPS::lookForLocation()
|
|||
// Also: apparently when the GPS is initially reporting lock it can output a bogus latitude > 90 deg!
|
||||
foundLocation =
|
||||
(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.getP(maxWait());
|
||||
}
|
||||
}
|
||||
|
||||
return foundLocation;
|
||||
|
@ -193,10 +193,14 @@ bool UBloxGPS::whileIdle()
|
|||
/// Note: ublox doesn't need a wake method, because as soon as we send chars to the GPS it will wake up
|
||||
void UBloxGPS::sleep()
|
||||
{
|
||||
if (isConnected) {
|
||||
DEBUG_MSG("FIXME, enter low power mode\n");
|
||||
|
||||
// won't work on 6M
|
||||
// ublox.powerOff();
|
||||
}
|
||||
setGPSPower(false);
|
||||
}
|
||||
|
||||
void UBloxGPS::wake()
|
||||
{
|
||||
setGPSPower(true);
|
||||
// Give time for the GPS to boot
|
||||
delay(200);
|
||||
}
|
|
@ -17,11 +17,6 @@ class UBloxGPS : public GPS
|
|||
public:
|
||||
UBloxGPS();
|
||||
|
||||
/**
|
||||
* Returns true if we succeeded
|
||||
*/
|
||||
virtual bool setup();
|
||||
|
||||
/**
|
||||
* Reset our GPS back to factory settings
|
||||
*
|
||||
|
@ -30,6 +25,11 @@ class UBloxGPS : public GPS
|
|||
bool factoryReset();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Returns true if we succeeded
|
||||
*/
|
||||
virtual bool setupGPS();
|
||||
|
||||
/** Subclasses should look for serial rx characters here and feed it to their GPS parser
|
||||
*
|
||||
* Return true if we received a valid message from the GPS
|
||||
|
@ -57,6 +57,7 @@ class UBloxGPS : public GPS
|
|||
|
||||
/// If possible force the GPS into sleep/low power mode
|
||||
virtual void sleep();
|
||||
virtual void wake();
|
||||
|
||||
private:
|
||||
/// Attempt to connect to our GPS, returns false if no gps is present
|
||||
|
|
Ładowanie…
Reference in New Issue