Skip to content

Commit

Permalink
mavlink_ftp_client: retry download if the other component already has…
Browse files Browse the repository at this point in the history
… an ongoing transfer
  • Loading branch information
bkueng committed Apr 5, 2024
1 parent f3ba565 commit e6061f7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions src/mavsdk/core/mavlink_ftp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ServerResult>(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) {
Expand Down Expand Up @@ -1177,11 +1186,11 @@ void MavlinkFtpClient::send_mavlink_ftp_message(const PayloadHeader& payload, ui
});
}

void MavlinkFtpClient::start_timer()
void MavlinkFtpClient::start_timer(std::optional<double> 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()
Expand Down
2 changes: 1 addition & 1 deletion src/mavsdk/core/mavlink_ftp_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class MavlinkFtpClient {
static ClientResult result_from_nak(PayloadHeader* payload);

void timeout();
void start_timer();
void start_timer(std::optional<double> duration_s = {});
void stop_timer();

ClientResult calc_local_file_crc32(const std::string& path, uint32_t& csum);
Expand Down

0 comments on commit e6061f7

Please sign in to comment.