Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tlog back, default to while arm #3181

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

joaoantoniocardoso
Copy link
Member

@joaoantoniocardoso joaoantoniocardoso commented Feb 27, 2025

Merge after #3180

We want to default to write tlog files only while armed, but also allow the user to change it to always write tlog files, so this patch is:

  1. Changing the abstract to include the tlog condition, defaulting to only write while armed
  2. Implementing the tlog condition to both mavlink-server (via cli arg) and mavlink-router (via config file)
  3. (todo) Creating an endpoint to the rest API
  4. (todo) Adding a switch on the frontend

note: mavlink-router default is to always write, and the only option to change it is using their config file.

note: by defaulting to while armed, we are introducing a breaking change to the current behavior.

Summary by Sourcery

Introduce the ability to configure when tlog files are written (always or while armed). The default behavior is now to only write tlog files while armed. This change affects both mavlink-server and mavlink-router.

Copy link

sourcery-ai bot commented Feb 27, 2025

Reviewer's Guide by Sourcery

This pull request introduces the ability to configure when tlog files are written (always or while armed). It defaults to writing tlog files only while armed for MAVLinkServer and always for MAVLinkRouter. The tlog condition is implemented using a new TLogCondition enum and is configurable via command-line arguments for MAVLinkServer and a configuration file for MAVLinkRouter. It also updates the version of mavlink-server.

Sequence diagram for MAVLinkRouter configuration file writing

sequenceDiagram
    participant MAVLinkRouter
    MAVLinkRouter->>MAVLinkRouter: _write_configuration_file()
    MAVLinkRouter->>MAVLinkRouter: convert_tlog_condition(tlog_condition)
    alt tlog_condition is Always
        MAVLinkRouter->>MAVLinkRouter: return 'always'
    else tlog_condition is WhileArmed
        MAVLinkRouter->>MAVLinkRouter: return 'while-armed'
    end
    MAVLinkRouter->>MAVLinkRouter: config['General'] = { 'LogMode': convert_tlog_condition(self.tlog_condition()) }
    MAVLinkRouter->>MAVLinkRouter: Write config to temporary file
    MAVLinkRouter->>MAVLinkRouter: Return temporary file name
    MAVLinkRouter->>MAVLinkRouter: assemble_command with -c {config_file}
Loading

Updated class diagram for AbstractRouter and TLogCondition

classDiagram
    class AbstractRouter {
        - pathlib.Path _logdir
        - TLogCondition _tlog_condition
        + set_logdir(directory: pathlib.Path) : None
        + tlog_condition() : TLogCondition
        + set_tlog_condition(tlog_condition: TLogCondition) : None
    }
    class TLogCondition {
        <<enumeration>>
        Always
        WhileArmed
    }
    AbstractRouter -- TLogCondition : has a
Loading

File-Level Changes

Change Details Files
Introduces a new TLogCondition enum to represent when to write tlog files (always or while armed) and adds corresponding logic to AbstractRouter.
  • Added a TLogCondition enum with Always and WhileArmed options.
  • Added _tlog_condition attribute to AbstractRouter, defaulting to WhileArmed.
  • Added tlog_condition() and set_tlog_condition() methods to AbstractRouter to get and set the tlog condition.
core/services/ardupilot_manager/mavlink_proxy/AbstractRouter.py
Implements the tlog condition for MAVLinkServer by adding a when parameter to the tlogwriter endpoint.
  • Added a convert_tlog_condition function to convert the TLogCondition enum to a string.
  • Modified the endpoint construction to include the tlog_condition as a query parameter for the tlogwriter endpoint.
  • The default behavior is to only write tlog files while armed.
core/services/ardupilot_manager/mavlink_proxy/MAVLinkServer.py
Implements the tlog condition for MAVLinkRouter by writing a configuration file with the LogMode parameter set to the tlog condition.
  • Added a _write_configuration_file method to write a temporary configuration file.
  • Added a convert_tlog_condition function to convert the TLogCondition enum to a string.
  • Modified the command assembly to include the -c flag with the path to the configuration file.
  • The default behavior is to always write tlog files, and the only option to change it is using their config file.
core/services/ardupilot_manager/mavlink_proxy/MAVLinkRouter.py
Adds a set_tlog_condition method to the Manager class to set the tlog condition on the underlying tool.
  • Added a set_tlog_condition method to the Manager class that calls the set_tlog_condition method on the underlying tool.
core/services/ardupilot_manager/mavlink_proxy/Manager.py
Updates the version of mavlink-server in the bootstrap script.
  • Incremented the VERSION variable from "0.3.1" to "0.3.2".
core/tools/mavlink_server/bootstrap.sh

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@joaoantoniocardoso joaoantoniocardoso force-pushed the add_tlog_back branch 3 times, most recently from 4eebbc0 to cdc5a5f Compare February 27, 2025 20:29
@joaoantoniocardoso joaoantoniocardoso added the merge-after-stable Should be merged only after next stable release label Feb 27, 2025
@joaoantoniocardoso joaoantoniocardoso force-pushed the add_tlog_back branch 4 times, most recently from 14a6429 to 6b1b2dd Compare February 27, 2025 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge-after-stable Should be merged only after next stable release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant