diff options
author | Vladimir Ermakov <vooon341@gmail.com> | 2014-09-17 13:04:21 +0400 |
---|---|---|
committer | Vladimir Ermakov <vooon341@gmail.com> | 2014-09-17 13:04:21 +0400 |
commit | 72887e14d9964cf12f8ca0a48d0d185f8d469ecb (patch) | |
tree | 53f7291a3a3562b5c50a2193ca1a0ec5aa097699 /src/modules | |
parent | 60c63f48729f028ec9f5b6de93da91873d152bfd (diff) | |
download | px4-firmware-72887e14d9964cf12f8ca0a48d0d185f8d469ecb.tar.gz px4-firmware-72887e14d9964cf12f8ca0a48d0d185f8d469ecb.tar.bz2 px4-firmware-72887e14d9964cf12f8ca0a48d0d185f8d469ecb.zip |
FTP: Implement write command.
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/mavlink/mavlink_ftp.cpp | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/src/modules/mavlink/mavlink_ftp.cpp b/src/modules/mavlink/mavlink_ftp.cpp index b17036c8e..695dcb0dc 100644 --- a/src/modules/mavlink/mavlink_ftp.cpp +++ b/src/modules/mavlink/mavlink_ftp.cpp @@ -470,29 +470,36 @@ MavlinkFTP::_workRead(PayloadHeader* payload) MavlinkFTP::ErrorCode MavlinkFTP::_workWrite(PayloadHeader* payload) { -#if 0 - // NYI: Coming soon - auto hdr = req->header(); - - // look up session - auto session = getSession(hdr->session); - if (session == nullptr) { - return kErrNoSession; + int session_index = payload->session; + + if (!_valid_session(session_index)) { + return kErrInvalidSession; } - // append to file - int result = session->append(hdr->offset, &hdr->data[0], hdr->size); + // Seek to the specified position +#ifdef MAVLINK_FTP_DEBUG + warnx("seek %d", payload->offset); +#endif + if (lseek(_session_fds[session_index], payload->offset, SEEK_SET) < 0) { + // Unable to see to the specified location + warnx("seek fail"); + return kErrFailErrno; + } - if (result < 0) { - // XXX might also be no space, I/O, etc. - return kErrNotAppend; + int bytes_written = ::write(_session_fds[session_index], &payload->data[0], payload->size); + if (bytes_written < 0) { + // Negative return indicates error other than eof + warnx("write fail %d", bytes_written); + return kErrFailErrno; } - hdr->size = result; + // need to decide how to indicate how much data was written + // current: old code set hdr->size + payload->size = bytes_written; + //payload->size = sizeof(uint32_t); + //*((uint32_t*)payload->data) = bytes_written; + return kErrNone; -#else - return kErrUnknownCommand; -#endif } /// @brief Responds to a RemoveFile command |