Repository: ArduPilot/MethodicConfigurator

Issue:
Startup delayed when no FC/SITL present due to network auto-detection retries
### Is there an existing issue for this?

- [x] I have searched the existing issues

### Description of the bug

I noticed a delay of approximately 2 seconds every time the application starts up when no flight controller is connected.

### Steps To Reproduce

1. Disconnect all Flight Controllers.
2. Ensure no SITL or MAVLink simulators are running.
3. Run the application: python3 -m ardupilot_methodic_configurator
4. Observe the console output timestamps.

### Expected behavior

The application should check the default network ports and, if the connection is refused (no available port to connect) it should move on immediately without retrying or sleeping This would make the startup feel instant.

### Screenshots / Logs


<img width="642" height="123" alt="Image" src="https://github.com/user-attachments/assets/9adc61b2-e147-44be-96e7-9163ae081101" />

### Software information

- Operating system: Linux
- arduPilot Methodic Configuration version:
- Python Version: `3.10`

### Additional context

Is this delay intended behavior? If not, I have the fix to submit.

Discussion:

Fix (patch):
diff --git a/ardupilot_methodic_configurator/backend_flightcontroller_connection.py b/ardupilot_methodic_configurator/backend_flightcontroller_connection.py
index 15f2bd8cd..23b88e258 100644
--- a/ardupilot_methodic_configurator/backend_flightcontroller_connection.py
+++ b/ardupilot_methodic_configurator/backend_flightcontroller_connection.py
@@ -195,12 +195,14 @@ def add_connection(self, connection_string: str) -> bool:
             logging_debug(_("Did not add empty connection"))
         return False
 
+    # pylint: disable=too-many-arguments,too-many-positional-arguments
     def _register_and_try_connect(
         self,
         comport: Union[mavutil.SerialPort, serial.tools.list_ports_common.ListPortInfo],
         progress_callback: Union[None, Callable[[int, int], None]],
         baudrate: int,
         log_errors: bool,
+        retries: int = 3,
     ) -> str:
         """
         Register a device in the connection list (if missing) and attempt connection.
@@ -210,6 +212,7 @@ def _register_and_try_connect(
             progress_callback: Optional callback for progress updates
             baudrate: Baud rate for serial connections
             log_errors: Whether to log errors
+            retries: Number of connection attempts (default: 3)
 
         Returns:
             str: empty string on success, or error message.
@@ -226,6 +229,7 @@ def _register_and_try_connect(
             baudrate=baudrate,
             log_errors=log_errors,
             timeout=self.CONNECTION_RETRY_TIMEOUT,
+            retries=retries,
         )
 
     def connect(
@@ -307,6 +311,7 @@ def connect(
                 progress_callback=progress_callback,
                 baudrate=self._baudrate,
                 log_errors=False,
+                retries=2,
             )
             if err == "":
                 return ""


Test changes:
diff --git a/tests/test_startup_speed.py b/tests/test_startup_speed.py
new file mode 100755
index 000000000..c74f0f191
--- /dev/null
+++ b/tests/test_startup_speed.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+
+"""
+Test for startup performance and connection logic.
+
+This file is part of ArduPilot Methodic Configurator. https://github.com/ArduPilot/MethodicConfigurator
+
+SPDX-FileCopyrightText: 2024-2026 Amilcar do Carmo Lucas <amilcar.lucas@iav.de>
+
+SPDX-License-Identifier: GPL-3.0-or-later
+"""
+
+from unittest.mock import MagicMock, patch
+
+from ardupilot_methodic_configurator.backend_flightcontroller_connection import (
+    FlightControllerConnection,
+)
+from ardupilot_methodic_configurator.data_model_flightcontroller_info import (
+    FlightControllerInfo,
+)
+
+
+@patch(
+    "ardupilot_methodic_configurator.backend_flightcontroller_connection.FlightControllerConnection._register_and_try_connect"
+)
+def test_startup_is_fast_when_no_drone_connected(mock_register_connect) -> None:
+    """
+    Scenario: User starts the application without a FC connected.
+
+    GIVEN: The application is launching and auto-detecting ports
+    WHEN: It attempts to connect to a TCP port that is closed
+    THEN: It should use a reduced retry count (2) to minimize startup delay
+    """
+    # GIVEN: A connection manager looking for devices on a network
+    info = FlightControllerInfo()
+    connection = FlightControllerConnection(info)
+
+    # Mock: Pretend we found one TCP port to check
+    connection.get_network_ports = MagicMock(return_value=["tcp:127.0.0.1:5760"])
+    # Mock: Pretend no serial ports exist (simplify the test)
+    # pylint: disable=protected-access
+    connection._auto_detect_serial = MagicMock(return_value=[])
+
+    # WHEN: The auto-connection logic runs
+    connection.connect(device="")
+
+    # THEN: The connection attempt should use retries=2 (not the default 3)
+    # Extract the arguments passed to the connection function
+    _, kwargs = mock_register_connect.call_args
+
+    # Check that 'retries' was passed explicitly
+    assert "retries" in kwargs, "FAIL: The 'retries' argument was not passed!"
+
+    # Check that it is set to 2 (Safety Compromise: 1 retry allowed)
+    actual_retries = kwargs["retries"]
+    assert actual_retries == 2, f"FAIL: Expected retries=2 for fast startup, but got {actual_retries}!"