mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-01 10:19:59 +00:00
More explicit guards for attempting to set RTC (#4452)
* Guard against timesources from the mesh if we have good time * Trunk * Consider phone time in the past 24 hours authoritative as well * Rename * GPS can be null * Declaration * Remove RemoteHardware * Explicitly remove GPS * Exclude GPS earlier for RAK2560
This commit is contained in:
parent
7740b4bccd
commit
464f270b12
@ -12,6 +12,7 @@ build_flags =
|
||||
-flto
|
||||
-Isrc/platform/stm32wl -g
|
||||
-DMESHTASTIC_MINIMIZE_BUILD
|
||||
-DMESHTASTIC_EXCLUDE_GPS
|
||||
-DDEBUG_MUTE
|
||||
; -DVECT_TAB_OFFSET=0x08000000
|
||||
-DconfigUSE_CMSIS_RTOS_V2=1
|
||||
@ -21,7 +22,7 @@ build_flags =
|
||||
-fdata-sections
|
||||
|
||||
build_src_filter =
|
||||
${arduino_base.build_src_filter} -<platform/esp32/> -<nimble/> -<mesh/api/> -<mesh/wifi/> -<mesh/http/> -<modules/esp32> -<mesh/eth/> -<input> -<buzz> -<platform/nrf52> -<platform/portduino> -<platform/rp2040> -<mesh/raspihttp>
|
||||
${arduino_base.build_src_filter} -<platform/esp32/> -<nimble/> -<mesh/api/> -<mesh/wifi/> -<mesh/http/> -<modules/esp32> -<mesh/eth/> -<input> -<buzz> -<modules/RemoteHardwareModule.cpp> -<platform/nrf52> -<platform/portduino> -<platform/rp2040> -<mesh/raspihttp>
|
||||
|
||||
board_upload.offset_address = 0x08000000
|
||||
upload_protocol = stlink
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <time.h>
|
||||
|
||||
static RTCQuality currentQuality = RTCQualityNone;
|
||||
uint32_t lastSetFromPhoneNtpOrGps = 0;
|
||||
|
||||
RTCQuality getRTCQuality()
|
||||
{
|
||||
@ -121,6 +122,9 @@ bool perhapsSetRTC(RTCQuality q, const struct timeval *tv, bool forceUpdate)
|
||||
if (shouldSet) {
|
||||
currentQuality = q;
|
||||
lastSetMsec = now;
|
||||
if (currentQuality >= RTCQualityNTP) {
|
||||
lastSetFromPhoneNtpOrGps = now;
|
||||
}
|
||||
|
||||
// This delta value works on all platforms
|
||||
timeStartMsec = now;
|
||||
|
@ -24,6 +24,8 @@ enum RTCQuality {
|
||||
|
||||
RTCQuality getRTCQuality();
|
||||
|
||||
extern uint32_t lastSetFromPhoneNtpOrGps;
|
||||
|
||||
/// If we haven't yet set our RTC this boot, set it from a GPS derived time
|
||||
bool perhapsSetRTC(RTCQuality q, const struct timeval *tv, bool forceUpdate = false);
|
||||
bool perhapsSetRTC(RTCQuality q, struct tm &t);
|
||||
|
@ -90,7 +90,6 @@ bool PositionModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, mes
|
||||
// will always be an equivalent or lesser RTCQuality (RTCQualityNTP or RTCQualityNet).
|
||||
force = true;
|
||||
#endif
|
||||
|
||||
// Set from phone RTC Quality to RTCQualityNTP since it should be approximately so
|
||||
trySetRtc(p, isLocal, force);
|
||||
}
|
||||
@ -126,14 +125,26 @@ void PositionModule::alterReceivedProtobuf(meshtastic_MeshPacket &mp, meshtastic
|
||||
|
||||
void PositionModule::trySetRtc(meshtastic_Position p, bool isLocal, bool forceUpdate)
|
||||
{
|
||||
if (hasQualityTimesource() && !isLocal) {
|
||||
LOG_DEBUG("Ignoring time from mesh because we have a GPS, RTC, or Phone/NTP time source in the past day\n");
|
||||
return;
|
||||
}
|
||||
struct timeval tv;
|
||||
uint32_t secs = p.time;
|
||||
|
||||
tv.tv_sec = secs;
|
||||
tv.tv_usec = 0;
|
||||
|
||||
perhapsSetRTC(isLocal ? RTCQualityNTP : RTCQualityFromNet, &tv, forceUpdate);
|
||||
}
|
||||
|
||||
bool PositionModule::hasQualityTimesource()
|
||||
{
|
||||
bool setFromPhoneOrNtpToday = (millis() - lastSetFromPhoneNtpOrGps) <= (SEC_PER_DAY * 1000UL);
|
||||
bool hasGpsOrRtc = (gps && gps->isConnected()) || (rtc_found.address != ScanI2C::ADDRESS_NONE.address);
|
||||
return hasGpsOrRtc || setFromPhoneOrNtpToday;
|
||||
}
|
||||
|
||||
meshtastic_MeshPacket *PositionModule::allocReply()
|
||||
{
|
||||
if (precision == 0) {
|
||||
|
@ -60,6 +60,7 @@ class PositionModule : public ProtobufModule<meshtastic_Position>, private concu
|
||||
void trySetRtc(meshtastic_Position p, bool isLocal, bool forceUpdate = false);
|
||||
uint32_t precision;
|
||||
void sendLostAndFoundText();
|
||||
bool hasQualityTimesource();
|
||||
|
||||
const uint32_t minimumTimeThreshold =
|
||||
Default::getConfiguredOrDefaultMsScaled(config.position.broadcast_smart_minimum_interval_secs, 30, numOnlineNodes);
|
||||
|
@ -6,6 +6,7 @@ board_check = true
|
||||
build_flags = ${nrf52840_base.build_flags} -Ivariants/rak2560 -D RAK_4631
|
||||
-L "${platformio.libdeps_dir}/${this.__env__}/bsec2/src/cortex-m4/fpv4-sp-d16-hard"
|
||||
-DGPS_POWER_TOGGLE ; comment this line to disable triple press function on the user button to turn off gps entirely.
|
||||
-DMESHTASTIC_EXCLUDE_GPS=1
|
||||
-DHAS_RAKPROT=1 ; Define if RAk OneWireSerial is used (disables GPS)
|
||||
build_src_filter = ${nrf52_base.build_src_filter} +<../variants/rak2560> +<mesh/eth/> +<mesh/api/> +<mqtt/>
|
||||
lib_deps =
|
||||
|
@ -227,7 +227,7 @@ SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG
|
||||
// #define GPS_TX_PIN PIN_SERIAL2_TX
|
||||
// #define PIN_GPS_EN PIN_3V3_EN
|
||||
// Disable GPS
|
||||
#define MESHTASTIC_EXCLUDE_GPS 1
|
||||
// #define MESHTASTIC_EXCLUDE_GPS 1
|
||||
// Define pin to enable GPS toggle (set GPIO to LOW) via user button triple press
|
||||
|
||||
// RAK12002 RTC Module
|
||||
|
Loading…
Reference in New Issue
Block a user