-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Also modified protocol to better support eof’s on list and read commands.
Mavlink FTP: List and Download commands working end to end
Also added selection from tree view for downloading
Changed FTP to tree view
LorenzMeier
added a commit
that referenced
this pull request
Jul 6, 2014
Mavlink File Transfer Protocol (FTP)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.