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 mavftp library and example code that uses it #957

Merged
merged 2 commits into from
Sep 4, 2024

Conversation

amilcarlucas
Copy link
Contributor

@amilcarlucas amilcarlucas commented Jul 11, 2024

Like spoken on the dev call this adds a mavftp library and an example script that uses it to:

  • get parameter values
  • get default parameter values
  • put a lua script file
  • get the latest .bin log file

This is the --help of the main mavftp.py application, it supports a similar syntax to the MAVProxy embedded mavftp functionality:

usage: mavftp.py [-h] [--baudrate BAUDRATE] [--device DEVICE] [--source-system SOURCE_SYSTEM] [--loglevel LOGLEVEL] [--debug DEBUG] [--pkt_loss_tx PKT_LOSS_TX]
                 [--pkt_loss_rx PKT_LOSS_RX] [--max_backlog MAX_BACKLOG] [--burst_read_size BURST_READ_SIZE] [--write_size WRITE_SIZE] [--write_qsize WRITE_QSIZE]
                 [--retry_time RETRY_TIME]
                 {get,getparams,put,list,mkdir,rmdir,rm,rename,crc} ...

MAVFTP - MAVLink File Transfer Protocol. A tool to do file operations between a ground control station and a drone using the MAVLink protocol.

positional arguments:
  {get,getparams,put,list,mkdir,rmdir,rm,rename,crc}
    get                 Get a file from the remote flight controller.
    getparams           Get and decode parameters from the remote flight controller.
    put                 Put a file to the remote flight controller.
    list                List files in a directory on the remote flight controller.
    mkdir               Create a directory on the remote flight controller.
    rmdir               Remove a directory on the remote flight controller.
    rm                  Remove a file on the remote flight controller.
    rename              Rename a file or directory on the remote flight controller.
    crc                 Calculate the CRC of a file on the remote flight controller.

optional arguments:
  -h, --help            show this help message and exit
  --baudrate BAUDRATE   master port baud rate. Defaults to 115200
  --device DEVICE       serial device. For windows use COMx where x is the port number. For Unix use /dev/ttyUSBx where x is the port number. Defaults to autodetection
  --source-system SOURCE_SYSTEM
                        MAVLink source system for this GCS. Defaults to 250
  --loglevel LOGLEVEL   log level. Defaults to INFO
  --debug DEBUG         Debug level 0 for none, 2 for max verbosity. Defaults to 0
  --pkt_loss_tx PKT_LOSS_TX
                        Packet loss on TX. Defaults to 0
  --pkt_loss_rx PKT_LOSS_RX
                        Packet loss on RX. Defaults to 0
  --max_backlog MAX_BACKLOG
                        Max backlog. Defaults to 5
  --burst_read_size BURST_READ_SIZE
                        Burst read size. Defaults to 80
  --write_size WRITE_SIZE
                        Write size. Defaults to 80
  --write_qsize WRITE_QSIZE
                        Write queue size. Defaults to 5
  --retry_time RETRY_TIME
                        Retry time. Defaults to 0.5

To test the example do:

python3 -m examples.mavftp_example --loglevel DEBUG

@amilcarlucas
Copy link
Contributor Author

@tridge I did some small pylint fixes on top of your changes. Thanks.

@amilcarlucas
Copy link
Contributor Author

I will add a put to upload a .lua script to the example and add code to download the lastest .bin log file.
Once that is done I think this can go in

@amilcarlucas
Copy link
Contributor Author

amilcarlucas commented Aug 7, 2024

@peterbarker looks like there is no pylint running here. Should I add that?

@amilcarlucas amilcarlucas changed the title Add mavftp example code Add mavftp library and example code that uses it Aug 7, 2024
@amilcarlucas amilcarlucas force-pushed the mavftp_example branch 2 times, most recently from c1114ac to 1ae2cf8 Compare August 8, 2024 22:32
@amilcarlucas amilcarlucas removed the WIP label Aug 8, 2024
@amilcarlucas
Copy link
Contributor Author

Please do not squash the two commits

@amilcarlucas amilcarlucas marked this pull request as ready for review August 10, 2024 19:37
@amilcarlucas amilcarlucas force-pushed the mavftp_example branch 3 times, most recently from 03596d3 to 6f8b19a Compare August 12, 2024 14:57
@amilcarlucas
Copy link
Contributor Author

Tested on CubeBlack. All operations work fine. But sometimes operations after a cmd_get do not work. So I still have some work to do.

@amilcarlucas amilcarlucas force-pushed the mavftp_example branch 2 times, most recently from 6205678 to cf438d9 Compare August 13, 2024 12:36
@tridge tridge removed the DevCallEU label Aug 14, 2024
@amilcarlucas
Copy link
Contributor Author

amilcarlucas commented Sep 1, 2024

OK, got it to work. It has much improved error handling.

Also added some tests

The library can be called directly and it is a mavftp application
  the application contains documented argparse arguments
Add a example that uses the library
@tridge tridge merged commit 50a291a into ArduPilot:master Sep 4, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants