Skip to content

Commit d785058

Browse files
committed
WIP - Adding Plat/Firwm
1 parent f6a1d18 commit d785058

File tree

12 files changed

+1211754
-0
lines changed

12 files changed

+1211754
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
2+
import abc
3+
from typing import List, Optional, Type
4+
5+
from loguru import logger
6+
7+
from autopilot.exceptions import InvalidEnvironmentImplementation
8+
from autopilot.firmware import AutopilotFirmware
9+
from flight_controller import FlightController
10+
from mavlink_proxy.Endpoint import Endpoint, EndpointType
11+
from mavlink_proxy.exceptions import EndpointAlreadyExists
12+
from mavlink_proxy.Manager import Manager as MavlinkManager
13+
14+
15+
class AutopilotEnvironment(abc.ABC):
16+
def __init__(self, owner: str) -> None:
17+
self.owner = owner
18+
self.mavlink_manager: Optional[MavlinkManager] = None
19+
20+
@classmethod
21+
def all(cls) -> List[str]:
22+
return [subclass.__name__ for subclass in cls.__subclasses__()]
23+
24+
@classmethod
25+
def get(cls, name: str) -> Type["AutopilotEnvironment"]:
26+
for subclass in cls.__subclasses__():
27+
if subclass.__name__ == name:
28+
return subclass()
29+
raise InvalidEnvironmentImplementation(f"{name} is not a valid environment implementation class")
30+
31+
async def start_mavlink_manager(self, device: Endpoint) -> None:
32+
default_endpoints = [
33+
Endpoint(
34+
name="GCS Server Link",
35+
owner=self.owner,
36+
connection_type=EndpointType.UDPServer,
37+
place="0.0.0.0",
38+
argument=14550,
39+
persistent=True,
40+
enabled=False,
41+
),
42+
Endpoint(
43+
name="GCS Client Link",
44+
owner=self.owner,
45+
connection_type=EndpointType.UDPClient,
46+
place="192.168.2.1",
47+
argument=14550,
48+
persistent=True,
49+
enabled=True,
50+
),
51+
Endpoint(
52+
name="MAVLink2RestServer",
53+
owner=self.owner,
54+
connection_type=EndpointType.UDPServer,
55+
place="127.0.0.1",
56+
argument=14001,
57+
persistent=True,
58+
protected=True,
59+
),
60+
Endpoint(
61+
name="MAVLink2Rest",
62+
owner=self.owner,
63+
connection_type=EndpointType.UDPClient,
64+
place="127.0.0.1",
65+
argument=14000,
66+
persistent=True,
67+
protected=True,
68+
overwrite_settings=True,
69+
),
70+
Endpoint(
71+
name="Internal Link",
72+
owner=self.owner,
73+
connection_type=EndpointType.TCPServer,
74+
place="127.0.0.1",
75+
argument=5777,
76+
persistent=True,
77+
protected=True,
78+
overwrite_settings=True,
79+
),
80+
Endpoint(
81+
name="Ping360 Heading",
82+
owner=self.owner,
83+
connection_type=EndpointType.UDPServer,
84+
place="0.0.0.0",
85+
argument=14660,
86+
persistent=True,
87+
protected=True,
88+
),
89+
]
90+
for endpoint in default_endpoints:
91+
try:
92+
self.mavlink_manager.add_endpoint(endpoint)
93+
except EndpointAlreadyExists:
94+
pass
95+
except Exception as error:
96+
logger.warning(str(error))
97+
await self.mavlink_manager.start(device)
98+
99+
@abc.abstractmethod
100+
async def start(self) -> None:
101+
raise NotImplementedError
102+
103+
@abc.abstractmethod
104+
async def stop(self) -> None:
105+
raise NotImplementedError
106+
107+
@abc.abstractmethod
108+
async def restart(self) -> None:
109+
raise NotImplementedError
110+
111+
@abc.abstractmethod
112+
async def setup(self) -> None:
113+
raise NotImplementedError
114+
115+
@abc.abstractmethod
116+
def boards(self, firmware: AutopilotFirmware) -> Optional[FlightController]:
117+
raise NotImplementedError
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from autopilot.environment import AutopilotEnvironment
2+
3+
class LinuxAutopilotEnvironment(AutopilotEnvironment):
4+
pass
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from typing import Optional
2+
from autopilot.environment import AutopilotEnvironment
3+
from autopilot.firmware import AutopilotFirmware
4+
from flight_controller import FlightController
5+
from mavlink_proxy.Endpoint import Endpoint, EndpointType
6+
7+
class SerialEnvironment(AutopilotEnvironment):
8+
def __init__(self, owner: str, board: FlightController) -> None:
9+
self.board: FlightController = board
10+
super().__init__(owner)
11+
12+
async def start(self) -> None:
13+
if not self.board.path:
14+
raise ValueError(f"Could not find device path for board {self.board.name}.")
15+
16+
baudrate = 115200
17+
is_px4 = "px4" in self.board.name.lower()
18+
if is_px4:
19+
baudrate = 57600
20+
await self.start_mavlink_manager(
21+
Endpoint(
22+
name="Master",
23+
owner=self.owner,
24+
connection_type=EndpointType.Serial,
25+
place=self.board.path,
26+
argument=baudrate,
27+
protected=True,
28+
)
29+
)
30+
if is_px4:
31+
# PX4 needs at least one initial heartbeat to start sending data
32+
await self.vehicle_manager.burst_heartbeat()
33+
34+
def stop(self) -> None:
35+
raise NotImplementedError
36+
37+
def restart(self) -> None:
38+
raise NotImplementedError
39+
40+
def setup(self) -> None:
41+
raise NotImplementedError
42+
43+
def boards(self, firmware: AutopilotFirmware) -> Optional[FlightController]:
44+
raise NotImplementedError

core/services/ardupilot_manager/autopilot/environments/sitl.py

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
class InvalidEnvironmentImplementation(ValueError):
3+
"""Required platform implementation class does not exists"""
4+
5+
class InvalidFirmwareImplementation(ValueError):
6+
"""Required firmware implementation class does not exists"""
7+
8+
class InvalidAutopilotManifestData(ValueError):
9+
"""Invalid manifest data"""
10+
11+
class InvalidAutopilotManifestURL(ValueError):
12+
"""Invalid manifest URL"""
13+
14+
class ManifestDataFetchFailed(RuntimeError):
15+
"""Failed to fetch manifest data"""
16+
17+
class BackendIsOffline(RuntimeError):
18+
"""Backend is offline"""
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from typing import List, Optional, Type
2+
3+
from autopilot.exceptions import InvalidFirmwareImplementation
4+
from flight_controller import FlightController
5+
6+
7+
class AutopilotFirmware:
8+
@classmethod
9+
def all(cls) -> List[str]:
10+
return [subclass.__name__ for subclass in cls.__subclasses__()]
11+
12+
@classmethod
13+
def get(cls, name: str) -> Optional[Type["AutopilotFirmware"]]:
14+
for subclass in cls.__subclasses__():
15+
if subclass.__name__ == name:
16+
return subclass()
17+
raise InvalidFirmwareImplementation(f"{name} is not a valid firmware implementation class")
18+
19+
def supported_boards(self) -> List[FlightController]:
20+
raise NotImplementedError
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from autopilot.firmware import AutopilotFirmware
2+
3+
4+
class ArdupilotFirmware(AutopilotFirmware):
5+
pass

0 commit comments

Comments
 (0)