Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Autopilot manager: Add fallback for first available router in case of invalid preferred one #2933

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions core/services/ardupilot_manager/ArduPilotManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,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