Skip to content

Commit cdc5a5f

Browse files
core/services/ardupilot_manager/mavlink_proxy: Implement TlogCondition to mavlink-router via conf file
1 parent 4c0aa38 commit cdc5a5f

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

core/services/ardupilot_manager/mavlink_proxy/MAVLinkRouter.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import configparser
12
import re
23
import subprocess
4+
import tempfile
35
from typing import Optional
46

5-
from mavlink_proxy.AbstractRouter import AbstractRouter
7+
from mavlink_proxy.AbstractRouter import AbstractRouter, TLogCondition
68
from mavlink_proxy.Endpoint import Endpoint, EndpointType
79

810

@@ -21,6 +23,22 @@ def _get_version(self) -> Optional[str]:
2123

2224
return None
2325

26+
def _write_configuration_file(self) -> str:
27+
def convert_tlog_condition(tlog_condition: TLogCondition) -> str:
28+
match tlog_condition:
29+
case TLogCondition.Always:
30+
return "always"
31+
case TLogCondition.WhileArmed:
32+
return "while-armed"
33+
return ""
34+
35+
config = configparser.ConfigParser()
36+
config["General"] = {"LogMode": convert_tlog_condition(self.tlog_condition())}
37+
38+
with tempfile.NamedTemporaryFile("w", suffix=".conf", delete=False) as temp_file:
39+
config.write(temp_file, space_around_delimiters=True)
40+
return temp_file.name
41+
2442
def assemble_command(self, master_endpoint: Endpoint) -> str:
2543
# Convert endpoint format to mavlink-router format
2644
def convert_endpoint(endpoint: Endpoint) -> str:
@@ -63,7 +81,7 @@ def convert_endpoint(endpoint: Endpoint) -> str:
6381
f"Master endpoint of type {master_endpoint.connection_type} not supported on MavlinkRouter."
6482
)
6583

66-
return f"{self.binary()} {convert_endpoint(master_endpoint)} {endpoints} -l {self.logdir()} -T {self.logdir()}"
84+
return f"{self.binary()} {convert_endpoint(master_endpoint)} {endpoints} -l {self.logdir()} -T {self.logdir()} -c {self._write_configuration_file()}"
6785

6886
@staticmethod
6987
def name() -> str:

0 commit comments

Comments
 (0)