diff --git a/src/mavsdk/core/mavlink_ftp_client.cpp b/src/mavsdk/core/mavlink_ftp_client.cpp index 6a2d4c7ed..c4f2fab96 100644 --- a/src/mavsdk/core/mavlink_ftp_client.cpp +++ b/src/mavsdk/core/mavlink_ftp_client.cpp @@ -204,10 +204,19 @@ void MavlinkFtpClient::process_mavlink_ftp_message(const mavlink_message_t& msg) } } else if (payload->opcode == RSP_NAK) { - LogWarn() << "FTP: NAK received"; - stop_timer(); - item.callback(result_from_nak(payload), {}); - work_queue_guard.pop_front(); + const ServerResult sr = static_cast(payload->data[0]); + // In case there's no session available, there's another transfer in progress + // for the given component. Back off and try again later. + if (sr == ERR_NO_SESSIONS_AVAILABLE) { + payload->seq_number = 0; // Ignore this response + start_timer(3.0); + LogDebug() << "No session available, retrying..."; + } else { + LogWarn() << "FTP: NAK received"; + stop_timer(); + item.callback(result_from_nak(payload), {}); + work_queue_guard.pop_front(); + } } }, [&](UploadItem& item) { @@ -1177,11 +1186,11 @@ void MavlinkFtpClient::send_mavlink_ftp_message(const PayloadHeader& payload, ui }); } -void MavlinkFtpClient::start_timer() +void MavlinkFtpClient::start_timer(std::optional duration_s) { _system_impl.unregister_timeout_handler(_timeout_cookie); _system_impl.register_timeout_handler( - [this]() { timeout(); }, _system_impl.timeout_s(), &_timeout_cookie); + [this]() { timeout(); }, duration_s.value_or(_system_impl.timeout_s()), &_timeout_cookie); } void MavlinkFtpClient::stop_timer() diff --git a/src/mavsdk/core/mavlink_ftp_client.h b/src/mavsdk/core/mavlink_ftp_client.h index 8562f7095..b85c93484 100644 --- a/src/mavsdk/core/mavlink_ftp_client.h +++ b/src/mavsdk/core/mavlink_ftp_client.h @@ -299,7 +299,7 @@ class MavlinkFtpClient { static ClientResult result_from_nak(PayloadHeader* payload); void timeout(); - void start_timer(); + void start_timer(std::optional duration_s = {}); void stop_timer(); ClientResult calc_local_file_crc32(const std::string& path, uint32_t& csum);