mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-24 17:32:18 +00:00
set rtc from gps time
This commit is contained in:
parent
67e0f5c184
commit
d9a875082c
1
TODO.md
1
TODO.md
@ -39,6 +39,7 @@ Items to complete before the first beta release.
|
|||||||
# Low power consumption tasks
|
# Low power consumption tasks
|
||||||
General ideas to hit the power draws our spreadsheet predicts. Do the easy ones before beta, the last 15% can be done after 1.0.
|
General ideas to hit the power draws our spreadsheet predicts. Do the easy ones before beta, the last 15% can be done after 1.0.
|
||||||
|
|
||||||
|
* (possibly bad idea - better to have lora radio always listen - check spreadsheet) have every node wake at the same tick and do their position syncs then go back to deep sleep
|
||||||
* lower BT announce interval to save battery
|
* lower BT announce interval to save battery
|
||||||
* change to use RXcontinuous mode and config to drop packets with bad CRC (see section 6.4 of datasheet) - I think this is already the case
|
* change to use RXcontinuous mode and config to drop packets with bad CRC (see section 6.4 of datasheet) - I think this is already the case
|
||||||
* have mesh service run in a thread that stays blocked until a packet arrives from the RF95
|
* have mesh service run in a thread that stays blocked until a packet arrives from the RF95
|
||||||
|
29
src/GPS.cpp
29
src/GPS.cpp
@ -7,7 +7,7 @@
|
|||||||
HardwareSerial _serial_gps(GPS_SERIAL_NUM);
|
HardwareSerial _serial_gps(GPS_SERIAL_NUM);
|
||||||
uint32_t timeStartMsec; // Once we have a GPS lock, this is where we hold the initial msec clock that corresponds to that time
|
uint32_t timeStartMsec; // Once we have a GPS lock, this is where we hold the initial msec clock that corresponds to that time
|
||||||
uint64_t zeroOffset; // GPS based time in millis since 1970 - only updated once on initial lock
|
uint64_t zeroOffset; // GPS based time in millis since 1970 - only updated once on initial lock
|
||||||
bool timeSetFromGPS; // We only reset our time once per wake
|
bool timeSetFromGPS; // We only reset our time once per wake
|
||||||
|
|
||||||
GPS gps;
|
GPS gps;
|
||||||
|
|
||||||
@ -16,6 +16,15 @@ GPS::GPS() : PeriodicTask(30 * 1000)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GPS::setup()
|
void GPS::setup()
|
||||||
|
{
|
||||||
|
readFromRTC();
|
||||||
|
|
||||||
|
#ifdef GPS_RX_PIN
|
||||||
|
_serial_gps.begin(GPS_BAUDRATE, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPS::readFromRTC()
|
||||||
{
|
{
|
||||||
struct timeval tv; /* btw settimeofday() is helpfull here too*/
|
struct timeval tv; /* btw settimeofday() is helpfull here too*/
|
||||||
|
|
||||||
@ -27,10 +36,6 @@ void GPS::setup()
|
|||||||
timeStartMsec = now;
|
timeStartMsec = now;
|
||||||
zeroOffset = tv.tv_sec * 1000LL + tv.tv_usec / 1000LL;
|
zeroOffset = tv.tv_sec * 1000LL + tv.tv_usec / 1000LL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef GPS_RX_PIN
|
|
||||||
_serial_gps.begin(GPS_BAUDRATE, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for the time being we need to rapidly read from the serial port to prevent overruns
|
// for the time being we need to rapidly read from the serial port to prevent overruns
|
||||||
@ -47,14 +52,18 @@ void GPS::loop()
|
|||||||
if (!timeSetFromGPS && time.isValid() && date.isValid())
|
if (!timeSetFromGPS && time.isValid() && date.isValid())
|
||||||
{
|
{
|
||||||
timeSetFromGPS = true;
|
timeSetFromGPS = true;
|
||||||
timeStartMsec = millis();
|
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
// FIXME, this is a shit not right version of the standard def of unix time!!!
|
// FIXME, this is a shit not right version of the standard def of unix time!!!
|
||||||
zeroOffset = 1000LL * (time.second() + time.minute() * 60 + time.hour() * 60 * 60 +
|
tv.tv_sec = time.second() + time.minute() * 60 + time.hour() * 60 * 60 +
|
||||||
24 * 60 * 60 * (date.month() * 31 + date.day() + 365 * (date.year() - 1970))) +
|
24 * 60 * 60 * (date.month() * 31 + date.day() + 365 * (date.year() - 1970));
|
||||||
time.centisecond() * 10;
|
|
||||||
|
|
||||||
DEBUG_MSG("Setting time zero %lld\n", zeroOffset);
|
tv.tv_usec = time.centisecond() * (10 / 1000);
|
||||||
|
|
||||||
|
DEBUG_MSG("Setting RTC %ld secs\n", tv.tv_sec);
|
||||||
|
settimeofday(&tv, NULL);
|
||||||
|
readFromRTC();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,9 @@ public:
|
|||||||
virtual void loop();
|
virtual void loop();
|
||||||
|
|
||||||
virtual void doTask();
|
virtual void doTask();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void readFromRTC();
|
||||||
};
|
};
|
||||||
|
|
||||||
extern GPS gps;
|
extern GPS gps;
|
||||||
|
@ -43,8 +43,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
// Select which board is being used. If the outside build environment has sent a choice, just use that
|
// Select which board is being used. If the outside build environment has sent a choice, just use that
|
||||||
#if !defined(T_BEAM_V10) && !defined(HELTEC_LORA32)
|
#if !defined(T_BEAM_V10) && !defined(HELTEC_LORA32)
|
||||||
//#define T_BEAM_V10 // AKA Rev1 (second board released)
|
#define T_BEAM_V10 // AKA Rev1 (second board released)
|
||||||
#define HELTEC_LORA32
|
//#define HELTEC_LORA32
|
||||||
|
|
||||||
#define HW_VERSION_US // We encode the hardware freq range in the hw version string, so sw update can eventually install the correct build
|
#define HW_VERSION_US // We encode the hardware freq range in the hw version string, so sw update can eventually install the correct build
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user