From 635e189007c2f98629d1efe97fb67c1f60a6ecde Mon Sep 17 00:00:00 2001 From: geeksville Date: Sat, 22 Feb 2020 20:05:38 -0800 Subject: [PATCH] GPS sleep mode WIP - alas this thread will have to be back burner for a while because my TX wire on my ONLY T-BEAM broke while I was soldering a jtag connector - so I can only RX from the GPS. My other 5 boards are still delayed due to corona virus. So I'll work on other features for now --- TODO.md | 2 ++ src/GPS.cpp | 48 +++++++++++++++++++++++++----------------------- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/TODO.md b/TODO.md index 3189208e..5a18227a 100644 --- a/TODO.md +++ b/TODO.md @@ -2,6 +2,8 @@ Items to complete before the first alpha release. +* turn on gps https://github.com/sparkfun/SparkFun_Ublox_Arduino_Library/blob/master/examples/Example18_PowerSaveMode/Example18_PowerSaveMode.ino +* switch gps to 38400 baud https://github.com/sparkfun/SparkFun_Ublox_Arduino_Library/blob/master/examples/Example11_ResetModule/Example2_FactoryDefaultsviaSerial/Example2_FactoryDefaultsviaSerial.ino * have state machine properly enter deep sleep based on loss of mesh and phone comms * have gps implement canSleep(), print nmea for debugging and discard buffers on the way into sleep * implement CustomRF95::canSleep diff --git a/src/GPS.cpp b/src/GPS.cpp index ce6fff31..14b34699 100644 --- a/src/GPS.cpp +++ b/src/GPS.cpp @@ -27,6 +27,7 @@ void GPS::setup() _serial_gps.begin(GPS_BAUDRATE, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN); ublox.enableDebugging(Serial); +#if 0 // note: the lib's implementation has the wrong docs for what the return val is // it is not a bool, it returns zero for success bool errCode = ublox.begin(_serial_gps); @@ -38,9 +39,10 @@ void GPS::setup() assert(ok); ok = ublox.setAutoPVT(true); assert(ok); - // ublox.saveConfiguration(); + // ublox.saveConfiguration(); assert(ok); #endif +#endif } void GPS::readFromRTC() @@ -97,7 +99,6 @@ bool GPS::canSleep() void GPS::prepareSleep() { // discard all rx serial bytes so we don't try to parse them when we come back - } void GPS::doTask() @@ -105,34 +106,35 @@ void GPS::doTask() #ifdef GPS_RX_PIN // Consume all characters that have arrived - ublox.checkUblox(); //See if new data is available. Process bytes as they come in. +#if 0 + ublox.checkUblox(); //See if new data is available. Process bytes as they come in. if (ublox.getPVT()) { // we only notify if position has changed if (!timeSetFromGPS) - { - struct timeval tv; + { + struct timeval tv; - DEBUG_MSG("Got time from GPS month=%d, year=%d\n", ublox.getMonth(), ublox.getYear()); + DEBUG_MSG("Got time from GPS month=%d, year=%d\n", ublox.getMonth(), ublox.getYear()); - /* Convert to unix time + /* 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). */ - struct tm t; - t.tm_sec = ublox.getSecond(); - t.tm_min = ublox.getMinute(); - t.tm_hour = ublox.getHour(); - t.tm_mday = ublox.getDay(); - t.tm_mon = ublox.getMonth() - 1; - t.tm_year = ublox.getYear() - 1900; - t.tm_isdst = false; - time_t res = mktime(&t); - tv.tv_sec = res; - tv.tv_usec = 0; // time.centisecond() * (10 / 1000); + struct tm t; + t.tm_sec = ublox.getSecond(); + t.tm_min = ublox.getMinute(); + t.tm_hour = ublox.getHour(); + t.tm_mday = ublox.getDay(); + t.tm_mon = ublox.getMonth() - 1; + t.tm_year = ublox.getYear() - 1900; + t.tm_isdst = false; + time_t res = mktime(&t); + tv.tv_sec = res; + tv.tv_usec = 0; // time.centisecond() * (10 / 1000); - // FIXME - // perhapsSetRTC(&tv); - } + // FIXME + // perhapsSetRTC(&tv); + } DEBUG_MSG("new gps pos\n"); latitude = ublox.getLatitude() * 10e-7; @@ -144,7 +146,8 @@ void GPS::doTask() } else // we didn't get a location update, go back to sleep and hope the characters show up wantNewLocation = true; -#endif +#endif +#endif // Once we have sent a location once we only poll the GPS rarely, otherwise check back every 100ms until we have something over the serial setPeriod(hasValidLocation && !wantNewLocation ? 30 * 1000 : 100); @@ -156,4 +159,3 @@ void GPS::startLock() wantNewLocation = true; setPeriod(1); } -