mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-15 17:42:12 +00:00
bug #376 wip - we now kill gps power when it is supposed to be asleep
This commit is contained in:
parent
b072eec4ac
commit
3c1c11e439
@ -3,14 +3,14 @@ gps todo - bug 376
|
|||||||
for taiwan region:
|
for taiwan region:
|
||||||
bin/run.sh --set region 8
|
bin/run.sh --set region 8
|
||||||
|
|
||||||
|
after sleep we declare success without real new data
|
||||||
|
|
||||||
handle the various GPS modes
|
handle the various GPS modes
|
||||||
|
|
||||||
fix poll interval for sending commands to ublox
|
fix poll interval for sending commands to ublox
|
||||||
|
|
||||||
handle maxint parameters
|
handle maxint parameters
|
||||||
|
|
||||||
handle loss of lock at end of wake (gotLocThisTime)
|
|
||||||
|
|
||||||
if not sharing location, don't even power up the GPS
|
if not sharing location, don't even power up the GPS
|
||||||
|
|
||||||
if we go to sleep without getting a location set hasValidLocation to false
|
if we go to sleep without getting a location set hasValidLocation to false
|
||||||
|
@ -95,9 +95,13 @@ uint32_t getValidTime()
|
|||||||
|
|
||||||
bool GPS::setup()
|
bool GPS::setup()
|
||||||
{
|
{
|
||||||
notifySleepObserver.observe(¬ifySleep);
|
setAwake(true); // Wake GPS power before doing any init
|
||||||
|
bool ok = setupGPS();
|
||||||
|
|
||||||
return true;
|
if (ok)
|
||||||
|
notifySleepObserver.observe(¬ifySleep);
|
||||||
|
|
||||||
|
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
|
// If we are overdue for an update, turn on the GPS and at least publish the current status
|
||||||
uint32_t now = millis();
|
uint32_t now = millis();
|
||||||
bool mustPublishUpdate = false;
|
|
||||||
|
|
||||||
if ((now - lastSleepStartMsec) > getSleepTime() && !isAwake) {
|
if ((now - lastSleepStartMsec) > getSleepTime() && !isAwake) {
|
||||||
// We now want to be awake - so wake up the GPS
|
// We now want to be awake - so wake up the GPS
|
||||||
|
@ -79,6 +79,9 @@ class GPS
|
|||||||
void forceWake(bool on);
|
void forceWake(bool on);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/// Do gps chipset specific init, return true for success
|
||||||
|
virtual bool setupGPS() = 0;
|
||||||
|
|
||||||
/// If possible force the GPS into sleep/low power mode
|
/// If possible force the GPS into sleep/low power mode
|
||||||
virtual void sleep() {}
|
virtual void sleep() {}
|
||||||
|
|
||||||
@ -134,7 +137,6 @@ class GPS
|
|||||||
* Tell users we have new GPS readings
|
* Tell users we have new GPS readings
|
||||||
*/
|
*/
|
||||||
void publishUpdate();
|
void publishUpdate();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern GPS *gps;
|
extern GPS *gps;
|
||||||
|
@ -10,14 +10,13 @@ static int32_t toDegInt(RawDegrees d)
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NMEAGPS::setup()
|
bool NMEAGPS::setupGPS()
|
||||||
{
|
{
|
||||||
#ifdef PIN_GPS_PPS
|
#ifdef PIN_GPS_PPS
|
||||||
// pulse per second
|
// pulse per second
|
||||||
// FIXME - move into shared GPS code
|
// FIXME - move into shared GPS code
|
||||||
pinMode(PIN_GPS_PPS, INPUT);
|
pinMode(PIN_GPS_PPS, INPUT);
|
||||||
#endif
|
#endif
|
||||||
GPS::setup();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ class NMEAGPS : public GPS
|
|||||||
TinyGPSPlus reader;
|
TinyGPSPlus reader;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual bool setup();
|
virtual bool setupGPS();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/** Subclasses should look for serial rx characters here and feed it to their GPS parser
|
/** Subclasses should look for serial rx characters here and feed it to their GPS parser
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "UBloxGPS.h"
|
#include "UBloxGPS.h"
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
#include "sleep.h"
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
UBloxGPS::UBloxGPS() {}
|
UBloxGPS::UBloxGPS() {}
|
||||||
@ -22,7 +23,7 @@ bool UBloxGPS::tryConnect()
|
|||||||
return isConnected;
|
return isConnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UBloxGPS::setup()
|
bool UBloxGPS::setupGPS()
|
||||||
{
|
{
|
||||||
if (_serial_gps) {
|
if (_serial_gps) {
|
||||||
#ifdef GPS_RX_PIN
|
#ifdef GPS_RX_PIN
|
||||||
@ -33,12 +34,6 @@ bool UBloxGPS::setup()
|
|||||||
// _serial_gps.setRxBufferSize(1024); // the default is 256
|
// _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);
|
ublox.enableDebugging(Serial);
|
||||||
|
|
||||||
// try a second time, the ublox lib serial parsing is buggy?
|
// try a second time, the ublox lib serial parsing is buggy?
|
||||||
@ -49,15 +44,11 @@ bool UBloxGPS::setup()
|
|||||||
if (isConnected) {
|
if (isConnected) {
|
||||||
DEBUG_MSG("Connected to UBLOX GPS successfully\n");
|
DEBUG_MSG("Connected to UBLOX GPS successfully\n");
|
||||||
|
|
||||||
GPS::setup();
|
|
||||||
|
|
||||||
if (!setUBXMode())
|
if (!setUBXMode())
|
||||||
recordCriticalError(UBloxInitFailed); // Don't halt the boot if saving the config fails, but do report the bug
|
recordCriticalError(UBloxInitFailed); // Don't halt the boot if saving the config fails, but do report the bug
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// Note: we do not call superclass setup in this case, because we dont want sleep observer registered
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,24 +125,28 @@ void UBloxGPS::whileActive()
|
|||||||
*/
|
*/
|
||||||
bool UBloxGPS::lookForTime()
|
bool UBloxGPS::lookForTime()
|
||||||
{
|
{
|
||||||
if (fixType >= 2 && ublox.getT(maxWait())) {
|
if (fixType >= 2) {
|
||||||
/* Convert to unix time
|
if (ublox.moduleQueried.gpsSecond) {
|
||||||
The Unix epoch (or Unix time or POSIX time or Unix timestamp) is the number of seconds that have elapsed since January
|
/* Convert to unix time
|
||||||
1, 1970 (midnight UTC/GMT), not counting leap seconds (in ISO 8601: 1970-01-01T00:00:00Z).
|
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).
|
||||||
struct tm t;
|
*/
|
||||||
t.tm_sec = ublox.getSecond(0);
|
struct tm t;
|
||||||
t.tm_min = ublox.getMinute(0);
|
t.tm_sec = ublox.getSecond(0);
|
||||||
t.tm_hour = ublox.getHour(0);
|
t.tm_min = ublox.getMinute(0);
|
||||||
t.tm_mday = ublox.getDay(0);
|
t.tm_hour = ublox.getHour(0);
|
||||||
t.tm_mon = ublox.getMonth(0) - 1;
|
t.tm_mday = ublox.getDay(0);
|
||||||
t.tm_year = ublox.getYear(0) - 1900;
|
t.tm_mon = ublox.getMonth(0) - 1;
|
||||||
t.tm_isdst = false;
|
t.tm_year = ublox.getYear(0) - 1900;
|
||||||
perhapsSetRTC(t);
|
t.tm_isdst = false;
|
||||||
return true;
|
perhapsSetRTC(t);
|
||||||
} else {
|
return true;
|
||||||
return false;
|
} else {
|
||||||
|
ublox.getT(maxWait()); // ask for new time data - hopefully ready when we come back
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -165,19 +160,24 @@ bool UBloxGPS::lookForLocation()
|
|||||||
bool foundLocation = false;
|
bool foundLocation = false;
|
||||||
|
|
||||||
// we only notify if position has changed due to a new fix
|
// 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);
|
latitude = ublox.getLatitude(0);
|
||||||
altitude = ublox.getAltitudeMSL(0) / 1000; // in mm convert to meters
|
longitude = ublox.getLongitude(0);
|
||||||
dop = ublox.getPDOP(0); // PDOP (an accuracy metric) is reported in 10^2 units so we have to scale down when we use it
|
altitude = ublox.getAltitudeMSL(0) / 1000; // in mm convert to meters
|
||||||
heading = ublox.getHeading(0);
|
dop = ublox.getPDOP(0); // PDOP (an accuracy metric) is reported in 10^2 units so we have to scale down when we use it
|
||||||
numSatellites = ublox.getSIV(0);
|
heading = ublox.getHeading(0);
|
||||||
|
numSatellites = ublox.getSIV(0);
|
||||||
|
|
||||||
// bogus lat lon is reported as 0 or 0 (can be bogus just for one)
|
// bogus lat lon is reported as 0 or 0 (can be bogus just for one)
|
||||||
// Also: apparently when the GPS is initially reporting lock it can output a bogus latitude > 90 deg!
|
// Also: apparently when the GPS is initially reporting lock it can output a bogus latitude > 90 deg!
|
||||||
foundLocation =
|
foundLocation =
|
||||||
(latitude != 0) && (longitude != 0) && (latitude <= 900000000 && latitude >= -900000000) && (numSatellites > 0);
|
(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;
|
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
|
/// 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()
|
void UBloxGPS::sleep()
|
||||||
{
|
{
|
||||||
if (isConnected) {
|
// won't work on 6M
|
||||||
DEBUG_MSG("FIXME, enter low power mode\n");
|
// ublox.powerOff();
|
||||||
|
setGPSPower(false);
|
||||||
// won't work on 6M
|
}
|
||||||
// ublox.powerOff();
|
|
||||||
}
|
void UBloxGPS::wake()
|
||||||
|
{
|
||||||
|
setGPSPower(true);
|
||||||
|
// Give time for the GPS to boot
|
||||||
|
delay(200);
|
||||||
}
|
}
|
@ -17,11 +17,6 @@ class UBloxGPS : public GPS
|
|||||||
public:
|
public:
|
||||||
UBloxGPS();
|
UBloxGPS();
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if we succeeded
|
|
||||||
*/
|
|
||||||
virtual bool setup();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reset our GPS back to factory settings
|
* Reset our GPS back to factory settings
|
||||||
*
|
*
|
||||||
@ -30,6 +25,11 @@ class UBloxGPS : public GPS
|
|||||||
bool factoryReset();
|
bool factoryReset();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/**
|
||||||
|
* Returns true if we succeeded
|
||||||
|
*/
|
||||||
|
virtual bool setupGPS();
|
||||||
|
|
||||||
/** Subclasses should look for serial rx characters here and feed it to their GPS parser
|
/** 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
|
* 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
|
/// If possible force the GPS into sleep/low power mode
|
||||||
virtual void sleep();
|
virtual void sleep();
|
||||||
|
virtual void wake();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Attempt to connect to our GPS, returns false if no gps is present
|
/// Attempt to connect to our GPS, returns false if no gps is present
|
||||||
|
Loading…
Reference in New Issue
Block a user