-
-
Notifications
You must be signed in to change notification settings - Fork 523
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 #1918 from CY-1992/add-version-type
Add software version type to system info
- Loading branch information
Showing
11 changed files
with
461 additions
and
36 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(system_info) | ||
|
||
add_executable(system_info | ||
system_info.cpp | ||
) | ||
|
||
find_package(MAVSDK REQUIRED) | ||
|
||
target_link_libraries(system_info | ||
MAVSDK::mavsdk | ||
) | ||
|
||
if(NOT MSVC) | ||
add_compile_options(takeoff_and_land PRIVATE -Wall -Wextra) | ||
else() | ||
add_compile_options(takeoff_and_land 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,100 @@ | ||
// | ||
// Simple example to demonstrate how to query system info using MAVSDK. | ||
// | ||
|
||
#include <chrono> | ||
#include <cstdint> | ||
#include <mavsdk/mavsdk.h> | ||
#include <mavsdk/plugins/info/info.h> | ||
#include <iostream> | ||
#include <future> | ||
#include <memory> | ||
#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>\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"; | ||
} | ||
|
||
std::shared_ptr<System> get_system(Mavsdk& mavsdk) | ||
{ | ||
std::cout << "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::NewSystemHandle handle = mavsdk.subscribe_on_new_system([&mavsdk, &prom, &handle]() { | ||
auto system = mavsdk.systems().back(); | ||
|
||
if (system->has_autopilot()) { | ||
std::cout << "Discovered autopilot\n"; | ||
|
||
// Unsubscribe again as we only want to find one system. | ||
mavsdk.unsubscribe_on_new_system(handle); | ||
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 != 2) { | ||
usage(argv[0]); | ||
return 1; | ||
} | ||
|
||
Mavsdk mavsdk; | ||
ConnectionResult connection_result = mavsdk.add_any_connection(argv[1]); | ||
|
||
if (connection_result != ConnectionResult::Success) { | ||
std::cerr << "Connection failed: " << connection_result << '\n'; | ||
return 1; | ||
} | ||
|
||
auto system = get_system(mavsdk); | ||
if (!system) { | ||
return 1; | ||
} | ||
|
||
auto info = Info{system}; | ||
|
||
// Wait until version/firmware information has been populated from the vehicle | ||
while (info.get_identification().first == Info::Result::InformationNotReceivedYet) { | ||
std::cout << "Waiting for Version information to populate from system." << '\n'; | ||
std::this_thread::sleep_for(std::chrono::seconds(1)); | ||
} | ||
|
||
// Get the system Version struct | ||
const Info::Version& system_version = info.get_version().second; | ||
|
||
// Print out the vehicle version information. | ||
std::cout << system_version << std::endl; | ||
|
||
// Get the system Product struct | ||
const Info::Product& system_product = info.get_product().second; | ||
|
||
// Print out the vehicle product information. | ||
std::cout << system_product << std::endl; | ||
|
||
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
Oops, something went wrong.