-
-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1649 from dayjaby/log_files_improvements
log_files: add blocking download_file; add erase log file function
- Loading branch information
Showing
13 changed files
with
2,224 additions
and
185 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
cmake_minimum_required(VERSION 3.10.2) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
project(logfile_download) | ||
|
||
add_executable(logfile_download | ||
logfile_download.cpp | ||
) | ||
|
||
find_package(MAVSDK REQUIRED) | ||
|
||
target_link_libraries(logfile_download | ||
MAVSDK::mavsdk | ||
) | ||
|
||
if(NOT MSVC) | ||
add_compile_options(logfile_download PRIVATE -Wall -Wextra) | ||
else() | ||
add_compile_options(logfile_download PRIVATE -WX -W2) | ||
endif() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// | ||
// Example how to download logfiles with MAVSDK. | ||
// | ||
|
||
#include <mavsdk/mavsdk.h> | ||
#include <mavsdk/plugins/log_files/log_files.h> | ||
|
||
#include <chrono> | ||
#include <functional> | ||
#include <future> | ||
#include <iostream> | ||
#include <iomanip> | ||
#include <cstring> | ||
#include <thread> | ||
|
||
using namespace mavsdk; | ||
using std::chrono::seconds; | ||
using std::this_thread::sleep_for; | ||
|
||
void usage(const std::string& bin_name) | ||
{ | ||
std::cerr << "Usage : " << bin_name << " <connection_url> [--rm]\n" | ||
<< '\n' | ||
<< "Connection URL format should be :\n" | ||
<< " For TCP : tcp://[server_host][:server_port]\n" | ||
<< " For UDP : udp://[bind_host][:bind_port]\n" | ||
<< " For Serial : serial:///path/to/serial/dev[:baudrate]\n" | ||
<< "For example, to connect to the simulator use URL: udp://:14540\n" | ||
<< '\n' | ||
<< "To remove log files after all downloads completed,\n" | ||
<< "please add the --rm argument" << std::endl; | ||
} | ||
|
||
std::shared_ptr<System> get_system(Mavsdk& mavsdk) | ||
{ | ||
std::cerr << "Waiting to discover system...\n"; | ||
auto prom = std::promise<std::shared_ptr<System>>{}; | ||
auto fut = prom.get_future(); | ||
|
||
// We wait for new systems to be discovered, once we find one that has an | ||
// autopilot, we decide to use it. | ||
mavsdk.subscribe_on_new_system([&mavsdk, &prom]() { | ||
auto system = mavsdk.systems().back(); | ||
|
||
// Unsubscribe again as we only want to find one system. | ||
mavsdk.subscribe_on_new_system(nullptr); | ||
prom.set_value(system); | ||
}); | ||
|
||
// We usually receive heartbeats at 1Hz, therefore we should find a | ||
// system after around 3 seconds max, surely. | ||
if (fut.wait_for(seconds(3)) == std::future_status::timeout) { | ||
std::cerr << "No autopilot found.\n"; | ||
return {}; | ||
} | ||
|
||
// Get discovered system now. | ||
return fut.get(); | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
if (argc > 3) { | ||
usage(argv[0]); | ||
return 1; | ||
} | ||
|
||
/* parse arguments */ | ||
bool remove_log_files = false; | ||
|
||
for (int i = 2; i < argc; ++i) { | ||
if (argv[i] == "--rm") { | ||
remove_log_files = true; | ||
} | ||
} | ||
|
||
Mavsdk mavsdk; | ||
ConnectionResult connection_result = mavsdk.add_any_connection(argv[1]); | ||
|
||
if (connection_result != ConnectionResult::Success) { | ||
std::cerr << "Connection failed: " << connection_result << std::endl; | ||
return 1; | ||
} | ||
|
||
auto system = get_system(mavsdk); | ||
if (!system) { | ||
return 1; | ||
} | ||
|
||
// Instantiate plugins. | ||
|
||
auto log_files = LogFiles{system}; | ||
|
||
auto get_entries_result = log_files.get_entries(); | ||
if (get_entries_result.first == LogFiles::Result::Success) { | ||
bool download_failure = false; | ||
for (auto entry : get_entries_result.second) { | ||
std::cerr << "Got log file with ID " << entry.id << " and date " << entry.date | ||
<< std::endl; | ||
auto result = | ||
log_files.download_log_file(entry, std::string("log-") + entry.date + ".ulg"); | ||
if (result.first != LogFiles::Result::Success) { | ||
download_failure = true; | ||
std::cerr << "LogFiles::download_log_file failed: " << result.first << std::endl; | ||
} | ||
} | ||
if (!download_failure && remove_log_files) { | ||
/* | ||
* If you want to be sure the log has been deleted, call get_entries again | ||
* that there are no log files present anymore | ||
* | ||
* TODO: provide a more reliable solution | ||
*/ | ||
log_files.erase_all_log_files(); | ||
} | ||
} else { | ||
std::cerr << "LogFiles::get_entries failed: " << get_entries_result.first << std::endl; | ||
return 1; | ||
} | ||
|
||
return 0; | ||
} |
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
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
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
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
84 changes: 84 additions & 0 deletions
84
src/mavsdk_server/src/generated/log_files/log_files.grpc.pb.cc
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.