Skip to content

Commit

Permalink
core: autopilot_manager: Add fallback router init
Browse files Browse the repository at this point in the history
* Make autopilot manager fallback to first avbailable router when
  unable to start current preferred router
  • Loading branch information
JoaoMario109 authored and joaoantoniocardoso committed Oct 8, 2024
1 parent 8159f8a commit 05c99de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 14 additions & 4 deletions core/services/ardupilot_manager/autopilot_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,20 @@ def __init__(self) -> None:
async def setup(self) -> None:
# This is the logical continuation of __init__(), extracted due to its async nature
self.configuration = deepcopy(self.settings.content)
self.mavlink_manager = MavlinkManager(self.load_preferred_router())
if not self.load_preferred_router():
await self.set_preferred_router(self.mavlink_manager.available_interfaces()[0].name())
logger.info(f"Setting {self.mavlink_manager.available_interfaces()[0].name()} as preferred router.")

self.mavlink_manager = MavlinkManager()
preferred_router = self.load_preferred_router()
try:
self.mavlink_manager = MavlinkManager(preferred_router)
except ValueError as error:
logger.warning(
f"Failed to start MavlinkManager[{preferred_router}]. Falling back to the first available router. Error details: {error}"
)
preferred_router = None

if not preferred_router:
await self.set_preferred_router(self.mavlink_manager.tool.name())
logger.info(f"Setting {self.mavlink_manager.tool.name()} as preferred router.")
self.mavlink_manager.set_logdir(self.settings.log_path)

self._load_endpoints()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def get_interface(name: str) -> Type["AbstractRouter"]:
for interface in AbstractRouter.__subclasses__():
if interface.is_ok() and interface.name() == name:
return interface
raise RuntimeError("Interface is not ok or does not exist.")
raise ValueError("Interface is not ok or does not exist.")

def binary(self) -> Optional[str]:
return self._binary
Expand Down

0 comments on commit 05c99de

Please sign in to comment.