mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-20 16:56:17 +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:
parent
4258372201
commit
3e5a18f594
@ -114,7 +114,7 @@ NodeDB::NodeDB()
|
||||
uint32_t channelFileCRC = crc32Buffer(&channelFile, sizeof(channelFile));
|
||||
|
||||
int saveWhat = 0;
|
||||
bool hasUniqueId = false;
|
||||
// bool hasUniqueId = false;
|
||||
// Get device unique id
|
||||
#if defined(ARCH_ESP32) && defined(ESP_EFUSE_OPTIONAL_UNIQUE_ID)
|
||||
uint32_t unique_id[4];
|
||||
|
@ -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
|
||||
|
@ -61,6 +61,7 @@ class PositionModule : public ProtobufModule<meshtastic_Position>, private concu
|
||||
uint32_t precision;
|
||||
void sendLostAndFoundText();
|
||||
bool hasQualityTimesource();
|
||||
bool hasGPS();
|
||||
|
||||
const uint32_t minimumTimeThreshold =
|
||||
Default::getConfiguredOrDefaultMs(config.position.broadcast_smart_minimum_interval_secs, 30);
|
||||
|
Loading…
Reference in New Issue
Block a user