mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-17 16:22:48 +00:00
Fix RTC time injection and consolidate position logic (#5396)
* Fix RTC time injection and consolidate position logic * Comment out unused var warning * Backerds
This commit is contained in:
@@ -146,11 +146,20 @@ bool PositionModule::hasQualityTimesource()
|
||||
#if MESHTASTIC_EXCLUDE_GPS
|
||||
bool hasGpsOrRtc = (rtc_found.address != ScanI2C::ADDRESS_NONE.address);
|
||||
#else
|
||||
bool hasGpsOrRtc = (gps && gps->isConnected()) || (rtc_found.address != ScanI2C::ADDRESS_NONE.address);
|
||||
bool hasGpsOrRtc = hasGPS() || (rtc_found.address != ScanI2C::ADDRESS_NONE.address);
|
||||
#endif
|
||||
return hasGpsOrRtc || setFromPhoneOrNtpToday;
|
||||
}
|
||||
|
||||
bool PositionModule::hasGPS()
|
||||
{
|
||||
#if MESHTASTIC_EXCLUDE_GPS
|
||||
return false;
|
||||
#else
|
||||
return gps && gps->isConnected();
|
||||
#endif
|
||||
}
|
||||
|
||||
meshtastic_MeshPacket *PositionModule::allocReply()
|
||||
{
|
||||
if (precision == 0) {
|
||||
@@ -194,10 +203,21 @@ meshtastic_MeshPacket *PositionModule::allocReply()
|
||||
p.precision_bits = precision;
|
||||
p.has_latitude_i = true;
|
||||
p.has_longitude_i = true;
|
||||
p.time = getValidTime(RTCQualityNTP) > 0 ? getValidTime(RTCQualityNTP) : localPosition.time;
|
||||
// Always use NTP / GPS time if available
|
||||
if (getValidTime(RTCQualityNTP) > 0) {
|
||||
p.time = getValidTime(RTCQualityNTP);
|
||||
} else if (rtc_found.address != ScanI2C::ADDRESS_NONE.address) {
|
||||
LOG_INFO("Use RTC time for position");
|
||||
p.time = getValidTime(RTCQualityDevice);
|
||||
} else if (getRTCQuality() < RTCQualityNTP) {
|
||||
LOG_INFO("Strip low RTCQuality (%d) time from position", getRTCQuality());
|
||||
p.time = 0;
|
||||
}
|
||||
|
||||
if (config.position.fixed_position) {
|
||||
p.location_source = meshtastic_Position_LocSource_LOC_MANUAL;
|
||||
} else {
|
||||
p.location_source = localPosition.location_source;
|
||||
}
|
||||
|
||||
if (pos_flags & meshtastic_Config_PositionConfig_PositionFlags_ALTITUDE) {
|
||||
@@ -242,20 +262,6 @@ meshtastic_MeshPacket *PositionModule::allocReply()
|
||||
p.has_ground_speed = true;
|
||||
}
|
||||
|
||||
// Strip out any time information before sending packets to other nodes - to keep the wire size small (and because other
|
||||
// nodes shouldn't trust it anyways) Note: we allow a device with a local GPS or NTP to include the time, so that devices
|
||||
// without can get time.
|
||||
if (getRTCQuality() < RTCQualityNTP) {
|
||||
LOG_INFO("Strip time %u from position", p.time);
|
||||
p.time = 0;
|
||||
} else if (rtc_found.address != ScanI2C::ADDRESS_NONE.address) {
|
||||
LOG_INFO("Use RTC time %u for position", p.time);
|
||||
p.time = getValidTime(RTCQualityDevice);
|
||||
} else {
|
||||
p.time = getValidTime(RTCQualityNTP);
|
||||
LOG_INFO("Provide time to mesh %u", p.time);
|
||||
}
|
||||
|
||||
LOG_INFO("Position reply: time=%i lat=%i lon=%i", p.time, p.latitude_i, p.longitude_i);
|
||||
|
||||
// TAK Tracker devices should send their position in a TAK packet over the ATAK port
|
||||
|
||||
Reference in New Issue
Block a user