From e883dfb24c20784d1efa8a822942d99dade7fc59 Mon Sep 17 00:00:00 2001 From: Joao Mario Lago Date: Tue, 26 Nov 2024 14:50:21 -0300 Subject: [PATCH] core:services:autopilot_manager: SERVICE_NAME to config * Move SERVICE_NAME from settings.py to config.py * Update places that use SERVICE_NAME or settings.app_name to use SERVICE_NAME from config.py --- .../ardupilot_manager/autopilot_manager.py | 21 ++++++++++--------- core/services/ardupilot_manager/config.py | 5 +++++ core/services/ardupilot_manager/main.py | 2 +- core/services/ardupilot_manager/settings.py | 6 ++---- 4 files changed, 19 insertions(+), 15 deletions(-) create mode 100644 core/services/ardupilot_manager/config.py diff --git a/core/services/ardupilot_manager/autopilot_manager.py b/core/services/ardupilot_manager/autopilot_manager.py index ca69bb5888..71e6d6b5e1 100644 --- a/core/services/ardupilot_manager/autopilot_manager.py +++ b/core/services/ardupilot_manager/autopilot_manager.py @@ -12,6 +12,7 @@ from elftools.elf.elffile import ELFFile from loguru import logger +from config import SERVICE_NAME from exceptions import ( AutoPilotProcessKillFail, NoDefaultFirmwareAvailable, @@ -212,7 +213,7 @@ async def start_linux_board(self, board: LinuxFlightController) -> None: # ArduPilot process will connect as a client on the UDP server created by the mavlink router master_endpoint = Endpoint( name="Master", - owner=self.settings.app_name, + owner=SERVICE_NAME, connection_type=EndpointType.UDPServer, place="127.0.0.1", argument=8852, @@ -269,7 +270,7 @@ async def start_serial(self, board: FlightController) -> None: await self.start_mavlink_manager( Endpoint( name="Master", - owner=self.settings.app_name, + owner=SERVICE_NAME, connection_type=EndpointType.Serial, place=board.path, argument=baudrate, @@ -324,7 +325,7 @@ async def start_sitl(self) -> None: # ArduPilot SITL binary will bind TCP port 5760 (server) and the mavlink router will connect to it as a client master_endpoint = Endpoint( name="Master", - owner=self.settings.app_name, + owner=SERVICE_NAME, connection_type=EndpointType.TCPClient, place="127.0.0.1", argument=5760, @@ -353,7 +354,7 @@ async def start_mavlink_manager(self, device: Endpoint) -> None: default_endpoints = [ Endpoint( name="GCS Server Link", - owner=self.settings.app_name, + owner=SERVICE_NAME, connection_type=EndpointType.UDPServer, place="0.0.0.0", argument=14550, @@ -362,7 +363,7 @@ async def start_mavlink_manager(self, device: Endpoint) -> None: ), Endpoint( name="GCS Client Link", - owner=self.settings.app_name, + owner=SERVICE_NAME, connection_type=EndpointType.UDPClient, place="192.168.2.1", argument=14550, @@ -371,7 +372,7 @@ async def start_mavlink_manager(self, device: Endpoint) -> None: ), Endpoint( name="MAVLink2RestServer", - owner=self.settings.app_name, + owner=SERVICE_NAME, connection_type=EndpointType.UDPServer, place="127.0.0.1", argument=14001, @@ -380,7 +381,7 @@ async def start_mavlink_manager(self, device: Endpoint) -> None: ), Endpoint( name="MAVLink2Rest", - owner=self.settings.app_name, + owner=SERVICE_NAME, connection_type=EndpointType.UDPClient, place="127.0.0.1", argument=14000, @@ -390,7 +391,7 @@ async def start_mavlink_manager(self, device: Endpoint) -> None: ), Endpoint( name="Zenoh Deamon", - owner=self.settings.app_name, + owner=SERVICE_NAME, connection_type=EndpointType.Zenoh, place="0.0.0.0", argument=7117, @@ -399,7 +400,7 @@ async def start_mavlink_manager(self, device: Endpoint) -> None: ), Endpoint( name="Internal Link", - owner=self.settings.app_name, + owner=SERVICE_NAME, connection_type=EndpointType.TCPServer, place="127.0.0.1", argument=5777, @@ -409,7 +410,7 @@ async def start_mavlink_manager(self, device: Endpoint) -> None: ), Endpoint( name="Ping360 Heading", - owner=self.settings.app_name, + owner=SERVICE_NAME, connection_type=EndpointType.UDPServer, place="0.0.0.0", argument=14660, diff --git a/core/services/ardupilot_manager/config.py b/core/services/ardupilot_manager/config.py new file mode 100644 index 0000000000..d1852bb57e --- /dev/null +++ b/core/services/ardupilot_manager/config.py @@ -0,0 +1,5 @@ +# This file is used to define general configurations for the app + +SERVICE_NAME = "autopilot-manager" + +__all__ = ["SERVICE_NAME"] diff --git a/core/services/ardupilot_manager/main.py b/core/services/ardupilot_manager/main.py index 92b693d1a0..5bb73191f9 100755 --- a/core/services/ardupilot_manager/main.py +++ b/core/services/ardupilot_manager/main.py @@ -10,7 +10,7 @@ from args import CommandLineArgs from autopilot_manager import AutoPilotManager from flight_controller_detector.Detector import Detector as BoardDetector -from settings import SERVICE_NAME +from config import SERVICE_NAME logging.basicConfig(handlers=[InterceptHandler()], level=0) init_logger(SERVICE_NAME) diff --git a/core/services/ardupilot_manager/settings.py b/core/services/ardupilot_manager/settings.py index 098dcb189f..40b8ba7ae6 100644 --- a/core/services/ardupilot_manager/settings.py +++ b/core/services/ardupilot_manager/settings.py @@ -6,14 +6,12 @@ import appdirs from loguru import logger +from config import SERVICE_NAME from typedefs import SITLFrame -SERVICE_NAME = "ardupilot-manager" - class Settings: - app_name = SERVICE_NAME - settings_path = Path(appdirs.user_config_dir(app_name)) + settings_path = Path(appdirs.user_config_dir(SERVICE_NAME)) settings_file = Path.joinpath(settings_path, "settings.json") firmware_folder = Path.joinpath(settings_path, "firmware") user_firmware_folder = Path("/usr/blueos/userdata/firmware")