Skip to content

Commit

Permalink
core: autopilot-manager: Isolate mavlink_proxy
Browse files Browse the repository at this point in the history
* Isolate mavlink_proxy type definitions and exceptions in its own
  module
  • Loading branch information
JoaoMario109 committed Oct 3, 2024
1 parent 35dd883 commit 855c4f5
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 56 deletions.
5 changes: 2 additions & 3 deletions core/services/ardupilot_manager/ArduPilotManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@

from exceptions import (
ArdupilotProcessKillFail,
EndpointAlreadyExists,
NoDefaultFirmwareAvailable,
NoPreferredBoardSet,
)
from firmware.FirmwareManagement import FirmwareManager
from flight_controller_detector.Detector import Detector as BoardDetector
from flight_controller_detector.linux.linux_boards import LinuxFlightController
from mavlink_proxy.Endpoint import Endpoint
from mavlink_proxy.Endpoint import Endpoint, EndpointType
from mavlink_proxy.exceptions import EndpointAlreadyExists
from mavlink_proxy.Manager import Manager as MavlinkManager
from settings import Settings
from typedefs import (
EndpointType,
Firmware,
FlightController,
FlightControllerFlags,
Expand Down
32 changes: 0 additions & 32 deletions core/services/ardupilot_manager/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,37 +63,5 @@ class NoDefaultFirmwareAvailable(RuntimeError):
"""Default firmware file is not available."""


class EndpointCreationFail(RuntimeError):
"""Failed to add endpoint."""


class EndpointDeleteFail(RuntimeError):
"""Failed to delete endpoint."""


class EndpointUpdateFail(RuntimeError):
"""Failed to update endpoint."""


class MavlinkRouterStartFail(RuntimeError):
"""Failed to initiate Mavlink router."""


class NoMasterMavlinkEndpoint(ValueError):
"""No master Mavlink endpoint set."""


class EndpointAlreadyExists(ValueError):
"""Mavlink endpoint already exists."""


class DuplicateEndpointName(ValueError):
"""Another mavlink endpoint with same name already exists."""


class EndpointDontExist(ValueError):
"""Given Mavlink endpoint do not exist."""


class NoPreferredBoardSet(RuntimeError):
"""No preferred board is set yet."""
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from loguru import logger

from exceptions import (
from mavlink_proxy.exceptions import (
DuplicateEndpointName,
EndpointAlreadyExists,
EndpointDontExist,
Expand Down
11 changes: 10 additions & 1 deletion core/services/ardupilot_manager/mavlink_proxy/Endpoint.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
from enum import Enum
from typing import Any, Dict, Iterable, Optional, Type

import validators
from pydantic import constr, root_validator
from pydantic.dataclasses import dataclass

from typedefs import EndpointType

class EndpointType(str, Enum):
"""Supported Mavlink endpoint types."""

UDPServer = "udpin"
UDPClient = "udpout"
TCPServer = "tcpin"
TCPClient = "tcpout"
Serial = "serial"


@dataclass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from typing import Optional

from mavlink_proxy.AbstractRouter import AbstractRouter
from mavlink_proxy.Endpoint import Endpoint
from typedefs import EndpointType
from mavlink_proxy.Endpoint import Endpoint, EndpointType


class MAVLinkRouter(AbstractRouter):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from typing import Optional

from mavlink_proxy.AbstractRouter import AbstractRouter
from mavlink_proxy.Endpoint import Endpoint
from typedefs import EndpointType
from mavlink_proxy.Endpoint import Endpoint, EndpointType


class MAVLinkServer(AbstractRouter):
Expand Down
3 changes: 1 addition & 2 deletions core/services/ardupilot_manager/mavlink_proxy/MAVP2P.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from typing import Optional

from mavlink_proxy.AbstractRouter import AbstractRouter
from mavlink_proxy.Endpoint import Endpoint
from typedefs import EndpointType
from mavlink_proxy.Endpoint import Endpoint, EndpointType


class MAVP2P(AbstractRouter):
Expand Down
3 changes: 1 addition & 2 deletions core/services/ardupilot_manager/mavlink_proxy/MAVProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
from typing import Optional

from mavlink_proxy.AbstractRouter import AbstractRouter
from mavlink_proxy.Endpoint import Endpoint
from typedefs import EndpointType
from mavlink_proxy.Endpoint import Endpoint, EndpointType


class MAVProxy(AbstractRouter):
Expand Down
2 changes: 1 addition & 1 deletion core/services/ardupilot_manager/mavlink_proxy/Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import mavlink_proxy.MAVLinkServer
import mavlink_proxy.MAVP2P
import mavlink_proxy.MAVProxy
from exceptions import (
from mavlink_proxy.exceptions import (
EndpointCreationFail,
EndpointDeleteFail,
EndpointUpdateFail,
Expand Down
23 changes: 23 additions & 0 deletions core/services/ardupilot_manager/mavlink_proxy/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class DuplicateEndpointName(ValueError):
"""Another mavlink endpoint with same name already exists."""

class EndpointAlreadyExists(ValueError):
"""Mavlink endpoint already exists."""

class EndpointDontExist(ValueError):
"""Given Mavlink endpoint do not exist."""

class MavlinkRouterStartFail(RuntimeError):
"""Failed to initiate Mavlink router."""

class NoMasterMavlinkEndpoint(ValueError):
"""No master Mavlink endpoint set."""

class EndpointCreationFail(RuntimeError):
"""Failed to add endpoint."""

class EndpointDeleteFail(RuntimeError):
"""Failed to delete endpoint."""

class EndpointUpdateFail(RuntimeError):
"""Failed to update endpoint."""
3 changes: 1 addition & 2 deletions core/services/ardupilot_manager/mavlink_proxy/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
sys.path.append(str(pathlib.Path(__file__).absolute().parent.parent))

from mavlink_proxy.AbstractRouter import AbstractRouter
from mavlink_proxy.Endpoint import Endpoint
from mavlink_proxy.Endpoint import Endpoint, EndpointType
from mavlink_proxy.MAVLinkRouter import MAVLinkRouter
from mavlink_proxy.MAVP2P import MAVP2P
from mavlink_proxy.MAVProxy import MAVProxy
from typedefs import EndpointType

_, slave_port = pty.openpty()
serial_port_name = os.ttyname(slave_port)
Expand Down
9 changes: 1 addition & 8 deletions core/services/ardupilot_manager/typedefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,7 @@ class FirmwareFormat(str, Enum):
ELF = "ELF"


class EndpointType(str, Enum):
"""Supported Mavlink endpoint types."""

UDPServer = "udpin"
UDPClient = "udpout"
TCPServer = "tcpin"
TCPClient = "tcpout"
Serial = "serial"



class Serial(BaseModel):
Expand Down

0 comments on commit 855c4f5

Please sign in to comment.