mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-11 23:52:14 +00:00
Added more clear RTC handling and quality logging (#3691)
* Also refresh timestamp for "timeonly" fixed position nodes * Added more clear RTC quality handling * Fix clock drift from Phone GPS / NTP too
This commit is contained in:
parent
0406be82d2
commit
39bbf0d352
@ -104,13 +104,15 @@ bool perhapsSetRTC(RTCQuality q, const struct timeval *tv)
|
|||||||
bool shouldSet;
|
bool shouldSet;
|
||||||
if (q > currentQuality) {
|
if (q > currentQuality) {
|
||||||
shouldSet = true;
|
shouldSet = true;
|
||||||
LOG_DEBUG("Upgrading time to quality %d\n", q);
|
LOG_DEBUG("Upgrading time to quality %s\n", RtcName(q));
|
||||||
} else if (q == RTCQualityGPS && (now - lastSetMsec) > (12 * 60 * 60 * 1000UL)) {
|
} else if (q >= RTCQualityNTP && (now - lastSetMsec) > (12 * 60 * 60 * 1000UL)) {
|
||||||
// Every 12 hrs we will slam in a new GPS time, to correct for local RTC clock drift
|
// Every 12 hrs we will slam in a new GPS or Phone GPS / NTP time, to correct for local RTC clock drift
|
||||||
shouldSet = true;
|
shouldSet = true;
|
||||||
LOG_DEBUG("Reapplying external time to correct clock drift %ld secs\n", tv->tv_sec);
|
LOG_DEBUG("Reapplying external time to correct clock drift %ld secs\n", tv->tv_sec);
|
||||||
} else
|
} else {
|
||||||
shouldSet = false;
|
shouldSet = false;
|
||||||
|
LOG_DEBUG("Current RTC quality: %s. Ignoring time of RTC quality of %s\n", RtcName(currentQuality), RtcName(q));
|
||||||
|
}
|
||||||
|
|
||||||
if (shouldSet) {
|
if (shouldSet) {
|
||||||
currentQuality = q;
|
currentQuality = q;
|
||||||
@ -162,6 +164,24 @@ bool perhapsSetRTC(RTCQuality q, const struct timeval *tv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *RtcName(RTCQuality quality)
|
||||||
|
{
|
||||||
|
switch (quality) {
|
||||||
|
case RTCQualityNone:
|
||||||
|
return "None";
|
||||||
|
case RTCQualityDevice:
|
||||||
|
return "Device";
|
||||||
|
case RTCQualityFromNet:
|
||||||
|
return "Net";
|
||||||
|
case RTCQualityNTP:
|
||||||
|
return "NTP";
|
||||||
|
case RTCQualityGPS:
|
||||||
|
return "GPS";
|
||||||
|
default:
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the RTC time if the provided time is of higher quality than the current RTC time.
|
* Sets the RTC time if the provided time is of higher quality than the current RTC time.
|
||||||
*
|
*
|
||||||
|
@ -28,6 +28,9 @@ RTCQuality getRTCQuality();
|
|||||||
bool perhapsSetRTC(RTCQuality q, const struct timeval *tv);
|
bool perhapsSetRTC(RTCQuality q, const struct timeval *tv);
|
||||||
bool perhapsSetRTC(RTCQuality q, struct tm &t);
|
bool perhapsSetRTC(RTCQuality q, struct tm &t);
|
||||||
|
|
||||||
|
/// Return a string name for the quality
|
||||||
|
const char *RtcName(RTCQuality quality);
|
||||||
|
|
||||||
/// Return time since 1970 in secs. While quality is RTCQualityNone we will be returning time based at zero
|
/// Return time since 1970 in secs. While quality is RTCQualityNone we will be returning time based at zero
|
||||||
uint32_t getTime(bool local = false);
|
uint32_t getTime(bool local = false);
|
||||||
|
|
||||||
|
@ -71,14 +71,8 @@ bool PositionModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes
|
|||||||
p.time);
|
p.time);
|
||||||
|
|
||||||
if (p.time && channels.getByIndex(mp.channel).role == meshtastic_Channel_Role_PRIMARY) {
|
if (p.time && channels.getByIndex(mp.channel).role == meshtastic_Channel_Role_PRIMARY) {
|
||||||
struct timeval tv;
|
|
||||||
uint32_t secs = p.time;
|
|
||||||
|
|
||||||
tv.tv_sec = secs;
|
|
||||||
tv.tv_usec = 0;
|
|
||||||
|
|
||||||
// Set from phone RTC Quality to RTCQualityNTP since it should be approximately so
|
// Set from phone RTC Quality to RTCQualityNTP since it should be approximately so
|
||||||
perhapsSetRTC(isLocal ? RTCQualityNTP : RTCQualityFromNet, &tv);
|
trySetRtc(p, isLocal);
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeDB->updatePosition(getFrom(&mp), p);
|
nodeDB->updatePosition(getFrom(&mp), p);
|
||||||
@ -93,6 +87,16 @@ bool PositionModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes
|
|||||||
return false; // Let others look at this message also if they want
|
return false; // Let others look at this message also if they want
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PositionModule::trySetRtc(meshtastic_Position p, bool isLocal)
|
||||||
|
{
|
||||||
|
struct timeval tv;
|
||||||
|
uint32_t secs = p.time;
|
||||||
|
|
||||||
|
tv.tv_sec = secs;
|
||||||
|
tv.tv_usec = 0;
|
||||||
|
perhapsSetRTC(isLocal ? RTCQualityNTP : RTCQualityFromNet, &tv);
|
||||||
|
}
|
||||||
|
|
||||||
meshtastic_MeshPacket *PositionModule::allocReply()
|
meshtastic_MeshPacket *PositionModule::allocReply()
|
||||||
{
|
{
|
||||||
if (precision == 0) {
|
if (precision == 0) {
|
||||||
|
@ -52,6 +52,7 @@ class PositionModule : public ProtobufModule<meshtastic_Position>, private concu
|
|||||||
private:
|
private:
|
||||||
struct SmartPosition getDistanceTraveledSinceLastSend(meshtastic_PositionLite currentPosition);
|
struct SmartPosition getDistanceTraveledSinceLastSend(meshtastic_PositionLite currentPosition);
|
||||||
meshtastic_MeshPacket *allocAtakPli();
|
meshtastic_MeshPacket *allocAtakPli();
|
||||||
|
void trySetRtc(meshtastic_Position p, bool isLocal);
|
||||||
uint32_t precision;
|
uint32_t precision;
|
||||||
void sendLostAndFoundText();
|
void sendLostAndFoundText();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user