From c01ed6c8aac7230c98255bf897d5310c8ca3c1ae Mon Sep 17 00:00:00 2001 From: Willian Galvani Date: Mon, 13 May 2024 17:17:00 -0300 Subject: [PATCH] add board cache --- .../flight_controller_detector/Detector.py | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/core/services/ardupilot_manager/flight_controller_detector/Detector.py b/core/services/ardupilot_manager/flight_controller_detector/Detector.py index 5d0576c70c..5d99288fc0 100644 --- a/core/services/ardupilot_manager/flight_controller_detector/Detector.py +++ b/core/services/ardupilot_manager/flight_controller_detector/Detector.py @@ -10,8 +10,11 @@ class Detector: - @staticmethod - def detect_linux_board() -> Optional[FlightController]: + last_detected_linux_board: Optional[FlightController] = None + misses = 0 # tracker for the number of times a Linux board was not detected in a row + + @classmethod + def detect_linux_board(cls) -> Optional[FlightController]: """Returns Linux board if connected. Check for connection using the sensors on the I²C and SPI buses. @@ -50,12 +53,20 @@ def is_argonot_r1_connected() -> bool: logger.debug("Trying to detect Linux board.") if is_navigator_r5_connected(): logger.debug("Navigator R5 detected.") - return FlightController(name="Navigator", manufacturer="Blue Robotics", platform=Platform.Navigator) + board = FlightController(name="Navigator", manufacturer="Blue Robotics", platform=Platform.Navigator) if is_argonot_r1_connected(): logger.debug("Argonot R1 detected.") - return FlightController(name="Argonot", manufacturer="SymbyTech", platform=Platform.Argonot) + board = FlightController(name="Argonot", manufacturer="SymbyTech", platform=Platform.Argonot) + if board: + cls.misses = 0 + cls.last_detected_linux_board = board + return board logger.debug("No Linux board detected.") - return None + cls.misses += 1 + if cls.misses > 3: + cls.last_detected_linux_board = None + logger.debug(f"Returning ached Linux board: {cls.last_detected_linux_board}") + return cls.last_detected_linux_board @staticmethod def is_serial_bootloader(port: SysFS) -> bool: