From 412530df83f71cdf8d4173f51c3ac63d6b88efa9 Mon Sep 17 00:00:00 2001 From: portersky <24420859+portersky@users.noreply.github.com> Date: Mon, 15 Jun 2026 00:24:14 +0200 Subject: [PATCH] fix: drop slow startup ping, log connect time verify_connection retried DEVICE_INFO pings up to 3x2s, blocking startup for ~6s even when the module just needs more time to come up. The main loop already pings every 5s and shows DEVICE_INFO in the type breakdown, so the upfront check added latency without useful signal. Log how long opening the port took instead. --- tools/telemetry.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/tools/telemetry.c b/tools/telemetry.c index df16a98..a03b082 100644 --- a/tools/telemetry.c +++ b/tools/telemetry.c @@ -5,7 +5,6 @@ #include #include "celrs/crsf.h" -#include "celrs/crsf_param.h" #include "celrs/crsf_telemetry.h" #include "celrs/logger.h" #include "celrs/serial.h" @@ -56,6 +55,11 @@ static void sleep_ms(int ms) { #endif } +/* Milliseconds elapsed since a clock() reading - used to time startup. */ +static double elapsed_ms(clock_t start) { + return (double)(clock() - start) * 1000.0 / CLOCKS_PER_SEC; +} + /* --------------------------------------------------------------------------- */ /* ANSI helpers - all go to stdout so dashboard owns it */ /* --------------------------------------------------------------------------- */ @@ -422,20 +426,11 @@ static int list_ports(void) { return 0; } -/* Send a ping and wait for DEVICE_INFO to verify the module responds. */ -static int verify_connection(cel_serial_port* port) { - /* The module may take a few seconds to respond to the first ping, - * so retry a few times before giving up. */ - for (int attempt = 0; attempt < 3; attempt++) { - if (cel_crsf_param_ping(port, 2.0f) == 0) return 0; - } - cel_log_warn("No DEVICE_INFO response - module may not be connected"); - return -1; -} - int main(int argc, char const* argv[]) { char const* port_path = NULL; int baud_rate = 0; /* 0 = auto-probe */ + char msg[256]; + clock_t t_startup = clock(); for (int i = 1; i < argc; i++) { if (strcmp(argv[i], "--list") == 0) { @@ -450,10 +445,13 @@ int main(int argc, char const* argv[]) { /* Auto-detect port if not specified */ if (port_path == NULL) { + clock_t t = clock(); char detected[256]; if (cel_serial_find_elrs_port(detected, sizeof(detected)) == 0) { port_path = detected; - cel_log_info("Auto-detected ELRS port"); + snprintf(msg, sizeof(msg), "Auto-detected ELRS port (%.0f ms)", + elapsed_ms(t)); + cel_log_info(msg); } else { cel_log_err("No ELRS-like port found. Use --list to see ports."); return 1; @@ -477,15 +475,10 @@ int main(int argc, char const* argv[]) { return 1; } - char msg[256]; - snprintf(msg, sizeof(msg), "Connected to %s (%d baud)", port_path, actual_baud); + snprintf(msg, sizeof(msg), "Connected to %s (%d baud) in %.0f ms", + port_path, actual_baud, elapsed_ms(t_startup)); cel_log_info(msg); - /* Verify module responds to CRSF ping */ - if (verify_connection(port) != 0) { - cel_log_warn("Continuing anyway - telemetry may not arrive"); - } - /* Create CRSF stream for incremental parsing */ cel_crsf_stream* stream = cel_crsf_stream_create(); if (stream == NULL) {