Skip to content

Commit c69e622

Browse files
core/services/ardupilot_manager/mavlink_proxy: Add TLogCondition
1 parent 9d287c5 commit c69e622

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

core/services/ardupilot_manager/mavlink_proxy/AbstractRouter.py

+15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import shlex
55
import shutil
66
import tempfile
7+
from enum import Enum
78
from typing import Any, List, Optional, Set, Type
89

910
from loguru import logger
@@ -18,6 +19,13 @@
1819
)
1920

2021

22+
class TLogCondition(str, Enum):
23+
"""When to write tlog files."""
24+
25+
Always = "always"
26+
WhileArmed = "while_armed"
27+
28+
2129
class AbstractRouter(metaclass=abc.ABCMeta):
2230
def __init__(self) -> None:
2331
self._endpoints: Set[Endpoint] = set()
@@ -28,6 +36,7 @@ def __init__(self) -> None:
2836
# to avoid any problem in __del__
2937
self._binary = shutil.which(self.binary_name())
3038
self._logdir = pathlib.Path(tempfile.gettempdir())
39+
self._tlog_condition = TLogCondition.WhileArmed
3140
self._version = self._get_version()
3241

3342
@staticmethod
@@ -182,6 +191,12 @@ def set_logdir(self, directory: pathlib.Path) -> None:
182191
raise ValueError(f"Logging directory {directory} does not exist.")
183192
self._logdir = directory
184193

194+
def tlog_condition(self) -> TLogCondition:
195+
return self._tlog_condition
196+
197+
def set_tlog_condition(self, tlog_condition: TLogCondition) -> None:
198+
self._tlog_condition = tlog_condition
199+
185200
def add_endpoint(self, endpoint: Endpoint) -> None:
186201
self._validate_endpoint(endpoint)
187202

core/services/ardupilot_manager/mavlink_proxy/Manager.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import mavlink_proxy.MAVLinkServer
1111
import mavlink_proxy.MAVP2P
1212
import mavlink_proxy.MAVProxy
13-
from mavlink_proxy.AbstractRouter import AbstractRouter
13+
from mavlink_proxy.AbstractRouter import AbstractRouter, TLogCondition
1414
from mavlink_proxy.Endpoint import Endpoint
1515
from mavlink_proxy.exceptions import (
1616
EndpointAlreadyExists,
@@ -171,6 +171,9 @@ def router_name(self) -> str:
171171
def set_logdir(self, log_dir: pathlib.Path) -> None:
172172
self.tool.set_logdir(log_dir)
173173

174+
def set_tlog_condition(self, tlog_condtion: TLogCondition) -> None:
175+
self.tool.set_tlog_condition(tlog_condtion)
176+
174177
async def auto_restart_router(self) -> None:
175178
"""Auto-restart Mavlink router process if it dies."""
176179
while True:

0 commit comments

Comments
 (0)