diff --git a/src/modules/mavlink/mavlink_ftp.cpp b/src/modules/mavlink/mavlink_ftp.cpp index 3809847f902..6ee90602259 100644 --- a/src/modules/mavlink/mavlink_ftp.cpp +++ b/src/modules/mavlink/mavlink_ftp.cpp @@ -48,6 +48,8 @@ using namespace time_literals; constexpr const char MavlinkFTP::_root_dir[]; +constexpr const char MavlinkFTP::_mav_log_prefix[]; +constexpr const char MavlinkFTP::_mav_log_dir[]; MavlinkFTP::MavlinkFTP(Mavlink &mavlink) : _mavlink(mavlink) @@ -310,6 +312,20 @@ MavlinkFTP::_reply(mavlink_file_transfer_protocol_t *ftp_req) } void MavlinkFTP::_constructPath(char *dst, int dst_len, const char *path) const { + // MAVLink FTP virtual directory: paths starting with "@MAV_LOG" + // are remapped to the flight-stack log root directory. + const char *p = path; + + if (strncmp(p, _mav_log_prefix, _mav_log_prefix_len) == 0 + && (p[_mav_log_prefix_len] == '\0' || p[_mav_log_prefix_len] == '/')) { + strncpy(dst, _mav_log_dir, dst_len); + dst[dst_len - 1] = '\0'; + int used = strlen(dst); + strncpy(dst + used, p + _mav_log_prefix_len, dst_len - used); + dst[dst_len - 1] = '\0'; + return; + } + strncpy(dst, _root_dir, dst_len); int root_dir_len = _root_dir_len; diff --git a/src/modules/mavlink/mavlink_ftp.h b/src/modules/mavlink/mavlink_ftp.h index eb0c0b88235..41cc18dcfd8 100644 --- a/src/modules/mavlink/mavlink_ftp.h +++ b/src/modules/mavlink/mavlink_ftp.h @@ -195,6 +195,13 @@ private: static constexpr const char _root_dir[] = PX4_ROOTFSDIR; static constexpr const int _root_dir_len = sizeof(_root_dir) - 1; + // Virtual directory prefix for log files as defined by the MAVLink FTP spec. + // Paths that start with this prefix are mapped to the flight-stack log root. + static constexpr const char _mav_log_prefix[] = "@MAV_LOG"; + static constexpr const int _mav_log_prefix_len = sizeof(_mav_log_prefix) - 1; + static constexpr const char _mav_log_dir[] = CONFIG_BOARD_ROOT_PATH "/log"; + static constexpr const int _mav_log_dir_len = sizeof(_mav_log_dir) - 1; + bool _last_reply_valid = false; uint8_t _last_reply[MAVLINK_MSG_ID_FILE_TRANSFER_PROTOCOL_LEN - MAVLINK_MSG_FILE_TRANSFER_PROTOCOL_FIELD_PAYLOAD_LEN + sizeof(PayloadHeader) + sizeof(uint32_t)];