-
-
Notifications
You must be signed in to change notification settings - Fork 530
/
Copy pathinfo.cpp
82 lines (64 loc) · 3.48 KB
/
info.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include "integration_test_helper.h"
#include "mavsdk.h"
#include "plugins/info/info.h"
using namespace mavsdk;
TEST(SitlTest, PX4Info)
{
Mavsdk mavsdk{Mavsdk::Configuration{Mavsdk::ComponentType::GroundStation}};
ConnectionResult ret = mavsdk.add_any_connection("udpin://0.0.0.0:14540");
ASSERT_EQ(ret, ConnectionResult::Success);
// Wait for system to connect via heartbeat.
std::this_thread::sleep_for(std::chrono::seconds(2));
ASSERT_TRUE(mavsdk.systems().size() > 0);
auto system = mavsdk.systems().at(0);
ASSERT_TRUE(system->has_autopilot());
auto info = std::make_shared<Info>(system);
// FIXME: we need to wait some time until Info has determined the version.
std::this_thread::sleep_for(std::chrono::seconds(1));
for (unsigned i = 0; i < 3; ++i) {
std::pair<Info::Result, Info::Version> version_result = info->get_version();
EXPECT_EQ(version_result.first, Info::Result::Success);
if (version_result.first == Info::Result::Success) {
std::cout << "Flight version: " << version_result.second.flight_sw_major << "."
<< version_result.second.flight_sw_minor << "."
<< version_result.second.flight_sw_patch << " ("
<< std::string(version_result.second.flight_sw_git_hash) << ")" << '\n';
std::cout << "Flight vendor version: " << version_result.second.flight_sw_vendor_major
<< "." << version_result.second.flight_sw_vendor_minor << "."
<< version_result.second.flight_sw_vendor_patch << '\n';
std::cout << "OS version: " << version_result.second.os_sw_major << "."
<< version_result.second.os_sw_minor << "."
<< version_result.second.os_sw_patch << " ("
<< std::string(version_result.second.os_sw_git_hash) << ")" << '\n';
EXPECT_NE(version_result.second.flight_sw_major, 0);
} else {
LogWarn() << "Version request result: " << version_result.first;
}
std::pair<Info::Result, Info::Product> product_result = info->get_product();
EXPECT_EQ(product_result.first, Info::Result::Success);
if (product_result.first == Info::Result::Success) {
std::cout << "Vendor: " << product_result.second.vendor_name << '\n';
std::cout << "Product: " << product_result.second.product_name << '\n';
} else {
LogWarn() << "Product request result: " << product_result.first;
}
std::pair<Info::Result, Info::Identification> identification_result =
info->get_identification();
EXPECT_EQ(identification_result.first, Info::Result::Success);
if (identification_result.first == Info::Result::Success) {
std::cout << "Hardware UID: " << identification_result.second.hardware_uid << '\n';
} else {
LogWarn() << "Identification request result: " << identification_result.first;
}
std::pair<Info::Result, Info::FlightInfo> flight_info_result =
info->get_flight_information();
EXPECT_EQ(flight_info_result.first, Info::Result::Success);
if (flight_info_result.first == Info::Result::Success) {
std::cout << flight_info_result.second << '\n';
} else {
LogWarn() << "Flight info request result: " << flight_info_result.first;
}
std::this_thread::sleep_for(std::chrono::seconds(2));
}
}