fix: accelerate LoRa time bootstrap
This commit is contained in:
+12
-3
@@ -34,6 +34,7 @@ static SenderStatus g_sender_statuses[NUM_SENDERS];
|
||||
static bool g_ap_mode = false;
|
||||
static WifiMqttConfig g_cfg;
|
||||
static uint32_t g_last_timesync_ms = 0;
|
||||
static uint32_t g_receiver_startup_timesync_last_ms = 0;
|
||||
static constexpr uint32_t TIME_SYNC_OFFSET_MS = 15000;
|
||||
static uint32_t g_boot_ms = 0;
|
||||
static FaultCounters g_sender_faults = {};
|
||||
@@ -1338,6 +1339,14 @@ static void receiver_loop() {
|
||||
uint32_t now_ms = millis();
|
||||
if (!g_ap_mode) {
|
||||
bool burst_sent = false;
|
||||
const char *burst_mode = "burst";
|
||||
if (time_is_synced() && now_ms - g_boot_ms < TIME_SYNC_BURST_DURATION_MS &&
|
||||
(g_receiver_startup_timesync_last_ms == 0 ||
|
||||
now_ms - g_receiver_startup_timesync_last_ms >= TIME_SYNC_BURST_INTERVAL_MS)) {
|
||||
g_receiver_startup_timesync_last_ms = now_ms;
|
||||
burst_sent = true;
|
||||
burst_mode = "startup";
|
||||
}
|
||||
for (uint8_t i = 0; i < NUM_SENDERS; ++i) {
|
||||
TimeSyncBurstState &state = g_timesync_burst[i];
|
||||
if (state.active) {
|
||||
@@ -1356,10 +1365,10 @@ static void receiver_loop() {
|
||||
display_set_last_error(g_receiver_last_error, g_receiver_last_error_utc, g_receiver_last_error_ms);
|
||||
}
|
||||
if (SERIAL_DEBUG_MODE) {
|
||||
serial_debug_printf("timesync: tx burst");
|
||||
serial_debug_printf("timesync: tx %s", burst_mode);
|
||||
}
|
||||
hil_trace_eventf("time_bootstrap", "\"stage\":\"transmit\",\"mode\":\"burst\",\"ok\":%s,\"utc\":%lu",
|
||||
time_sent ? "true" : "false", static_cast<unsigned long>(time_get_utc()));
|
||||
hil_trace_eventf("time_bootstrap", "\"stage\":\"transmit\",\"mode\":\"%s\",\"ok\":%s,\"utc\":%lu",
|
||||
burst_mode, time_sent ? "true" : "false", static_cast<unsigned long>(time_get_utc()));
|
||||
g_last_timesync_ms = now_ms;
|
||||
} else if (now_ms - g_last_timesync_ms > interval_sec * 1000UL) {
|
||||
g_last_timesync_ms = now_ms;
|
||||
|
||||
Reference in New Issue
Block a user