|
| 1 | +# AP_Filesystem: The ArduPilot virtual filesystem layer |
| 2 | + |
| 3 | +AP_Filesystem is a filesystem abstraction for ArduPilot that gives |
| 4 | +ArduPilot access to both local filesystems on the flight controller |
| 5 | +and a set of virtual filesystem abstractions. |
| 6 | + |
| 7 | +This document is primarily intended to document the VFS interfaces |
| 8 | +available to ground station authors via the MAVLink FTP transport. |
| 9 | + |
| 10 | +## MAVLink FTP |
| 11 | + |
| 12 | +ArduPilot implements the FILE_TRANSFER_PROTOCOL MAVLink message to |
| 13 | +allow for remote file operations. This protocol allows a GCS to |
| 14 | +transfer files to and from a flight controller. It also allows the GCS |
| 15 | +to access some special purpose VFS interfaces for efficient access to |
| 16 | +flight controller data using a file API. |
| 17 | + |
| 18 | +The VFS interfaces that don't represent local filesystem objects on |
| 19 | +the flight controller are prefixed with an '@' symbol. Currently there |
| 20 | +are two interfaces, the @PARAM interface and the @SYS interface. |
| 21 | + |
| 22 | +## The @PARAM VFS |
| 23 | + |
| 24 | +The @PARAM VFS allows a GCS to very efficiently download full or |
| 25 | +partial parameter list from the flight controller. Currently the |
| 26 | +@PARAM filesystem offers only a single file, called @PARAM/param.pck, |
| 27 | +which is a packed representation of the full parameter |
| 28 | +list. Downloading the full parameter list via this interface is a lot |
| 29 | +faster than using the traditional mavlink parameter messages. |
| 30 | + |
| 31 | +The file format of the @PARAM/param.pck file is as follows |
| 32 | + |
| 33 | +### File header |
| 34 | + |
| 35 | +There is a 6 byte header, consisting of 3 uint16_t values |
| 36 | +``` |
| 37 | + uint16_t magic # 0x671b |
| 38 | + uint16_t num_params |
| 39 | + uint16_t total_params |
| 40 | +``` |
| 41 | +The magic value is used to give the version of the packing format. It |
| 42 | +should have a value of 0x671b. The num_params is how many parameters |
| 43 | +will be sent (may be less than total if client requests a subset, see |
| 44 | +query strings below). The total_params is the total number of |
| 45 | +parameters the flight controller has. |
| 46 | + |
| 47 | +The header is little-endian. |
| 48 | + |
| 49 | +### Parameter Block |
| 50 | + |
| 51 | +After the header comes a series of variable length parameter blocks, one per |
| 52 | +parameter. The format is: |
| 53 | + |
| 54 | +``` |
| 55 | + uint8_t type:4; // AP_Param type NONE=0, INT8=1, INT16=2, INT32=3, FLOAT=4 |
| 56 | + uint8_t flags:4; // for future use |
| 57 | + uint8_t common_len:4; // number of name bytes in common with previous entry, 0..15 |
| 58 | + uint8_t name_len:4; // non-common length of param name -1 (0..15) |
| 59 | + uint8_t name[name_len]; // name |
| 60 | + uint8_t data[]; // value, length given by variable type |
| 61 | +``` |
| 62 | + |
| 63 | +There may be any number of leading zero pad bytes before the start of |
| 64 | +the parameter block. The pad bytes are added to ensure that a |
| 65 | +parameter value does not cross a MAVLink FTP block boundary. This |
| 66 | +padding prevents a re-fetch of a missing block from potentially |
| 67 | +leading to a corrupt value. |
| 68 | + |
| 69 | +The packing format avoids sending common leading characters of |
| 70 | +parameter names from the previous parameter. It does this by sending a |
| 71 | +common_len field which says how many characters should be copied from |
| 72 | +the previous parameter. This is always zero in the first block in the |
| 73 | +file. |
| 74 | + |
| 75 | +The name_len field is the number of non-common characters, minus one. |
| 76 | + |
| 77 | +### Query Strings |
| 78 | + |
| 79 | +The file name @PARAM/param.pck can optionally be extended with query |
| 80 | +string elements to change the result. For example: |
| 81 | + |
| 82 | + - @PARAM/param.pck?start=50&count=10 |
| 83 | + |
| 84 | +that means to download 10 parameters starting with parameter number |
| 85 | +50. |
| 86 | + |
| 87 | +### Parameter Client Examples |
| 88 | + |
| 89 | +The script Tools/scripts/param_unpack.py can be used to unpack a |
| 90 | +param.pck file. Additionally the MAVProxy mavproxy_param.py module |
| 91 | +implements parameter download via ftp. |
| 92 | + |
| 93 | +## The @SYS VFS |
| 94 | + |
| 95 | +The @SYS VFS gives access to flight controller internals. For now the |
| 96 | +only file that is accessible is @SYS/threads.txt which gives |
| 97 | +information on the remaining stack space for all threads. This file is |
| 98 | +only accessible for ChibiOS builds. |
0 commit comments