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

Mavlink File Transfer Protocol (FTP) #658

Merged
merged 42 commits into from
Jul 6, 2014
Merged

Mavlink File Transfer Protocol (FTP) #658

merged 42 commits into from
Jul 6, 2014

Conversation

LorenzMeier
Copy link
Member

The FTP protocol is pretty simple; it’s all in the mavlink_ftp* files on the mavlink-ftp branch. Right now everything is exchanged inside ENCPASULATED_DATA packets.

Everything is run by the master (QGC in this case); the slave simply responds to packets in order as they arrive. There’s buffering in the server for a little overlap (two packets in the queue at a time) but it’s a tradeoff between memory and link latency so I didn’t want to get ahead of myself bumping it up.

The mavlink receiver thread copies an incoming request verbatim from the mavlink buffer into a request queue, and queues a low-priority work item to handle the packet. This avoids trying to do file I/O on the mavlink receiver thread, as well as avoiding yet another worker thread. The worker is responsible for directly queueing replies, which are sent with the same sequence number as the request.

The opcodes defined/implemented in the server are:

Reset
Clears all state held by the server; closes all open files, etc.
Sends an Ack reply with no data.

List (path, offset)
Opens the directory (path), seeks to (offset) and fills the result buffer with nul-separated filenames. Sends
an Ack packet with the result buffer on success, or a Nak packet with an error code on error.
The directory is closed after the operation, so this leaves no state on the server.

Open (path)
Opens the file (path) and allocates a session number. The file must exist.
Sends an Ack packet with the allocated session number on success, or a Nak packet with an
error code on error.
The file remains open after the operation, and must eventually be closed by Reset or Terminate.

Read (session, offset, size)
Seeks to (offset) in the file opened in (session) and reads (size) bytes into the result buffer.
Sends an Ack packet with the result buffer on success, or a Nak packet with an error code on
error. For short reads or reads beyond the end of a file, the (size) field in the Ack packet will
indicate the actual number of bytes read.
Reads can be issued to any offset in the file for any number of bytes, so reconstructing portions
of the file to deal with lost packets should be easy.
For best download performance, try to keep two Read packets in flight.

Create (path)
Creates the file (path) and allocates a session number. The file must not exist, but all parent
directories must exist.
Sends an Ack packet with the allocated session number on success, or a Nak packet with an
error code on error.
The file remains open after the operation, and must eventually be closed by Reset or Terminate.

Write (session, offset, size)
Attempts to append (size) bytes from the request to the file opened in (session). The (offset) value
must exactly match the current size of the file, i.e. writes can only append.
Sends an Ack reply with no data on success, or a Nak packet with an error code on error.
The kErrNotAppend error (7) indicates that the offset value does not match the size of the file. There
are two likely causes of this - a lost Write request, and a lost Ack reply for a successful write.
On detecting a missed Ack, rewind the upload to the first Ack lost and begin sending again; ignore
any kErrNotAppend errors (since you may be overlapping Writes that were received but not acked)
until you have received another ack.

Terminate (session)
Closes the file associated with (session) and frees the session ID for re-use.

Remove (path)
Currently not implemented; we will probably want to be careful about what we allow to be deleted…

I would expect that you can run all of the protocol from an asynchronous state machine; once you have
initiated a process, you can kick the state machine from either packet reception or a timeout event.

none and others added 24 commits June 7, 2014 11:09
Conflicts:
	qgroundcontrol.pro
…rn user about missing config and take him to config view if necessary
Also changes for Ack timeouts and unit testing
These changes prevent random encapsulated data packets as being thought
to be images.
Mavlink FTP implementation List command
LorenzMeier added a commit that referenced this pull request Jul 6, 2014
Mavlink File Transfer Protocol (FTP)
@LorenzMeier LorenzMeier merged commit 2517768 into master Jul 6, 2014
@LorenzMeier LorenzMeier deleted the mavlink-ftp branch July 6, 2014 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants