Skip to content

Commit

Permalink
Merge pull request #2164 from mavlink/mavsdk-server-default-to-autopilot
Browse files Browse the repository at this point in the history
Mavsdk server default to autopilot
  • Loading branch information
julianoes authored Oct 21, 2023
2 parents a9c1981 + edf5960 commit b29239d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/mavsdk/core/lazy_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ template<typename Plugin> class LazyPlugin {
if (_mavsdk.systems().empty()) {
return nullptr;
}
_plugin = std::make_unique<Plugin>(_mavsdk.systems()[0]);
_plugin = std::make_unique<Plugin>(_mavsdk.first_autopilot(0).value());
}
return _plugin.get();
}
Expand Down
1 change: 1 addition & 0 deletions src/mavsdk/core/mocks/system_mock.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace testing {
class MockSystem {
public:
MOCK_CONST_METHOD0(is_connected, bool()){};
MOCK_CONST_METHOD0(has_autopilot, bool()){};
};

} // namespace testing
Expand Down
15 changes: 8 additions & 7 deletions src/mavsdk_server/src/connection_initiator.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ template<typename Mavsdk> class ConnectionInitiator {

mavsdk.subscribe_on_new_system([this, &mavsdk]() {
std::lock_guard<std::mutex> guard(_mutex);
const auto system = mavsdk.systems().at(0);

if (!_is_discovery_finished && system->is_connected()) {
LogInfo() << "System discovered";

_is_discovery_finished = true;
_discovery_promise->set_value(true);
for (auto system : mavsdk.systems()) {
if (!_is_discovery_finished && system->has_autopilot() && system->is_connected()) {
LogInfo() << "System discovered";

_is_discovery_finished = true;
_discovery_promise->set_value(true);
break;
}
}
});

Expand Down
3 changes: 3 additions & 0 deletions src/mavsdk_server/test/connection_initiator_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ TEST(ConnectionInitiator, startHangsUntilSystemDiscovered)
EXPECT_CALL(mavsdk, systems()).WillOnce(testing::Return(systems));

EXPECT_CALL(*system, is_connected()).WillOnce(testing::Return(true));
EXPECT_CALL(*system, has_autopilot()).WillOnce(testing::Return(true));

auto async_future = std::async(std::launch::async, [&initiator, &mavsdk]() {
initiator.start(mavsdk, ARBITRARY_CONNECTION_URL);
Expand All @@ -80,6 +81,7 @@ TEST(ConnectionInitiator, connectionDetectedIfDiscoverCallbackCalledBeforeWait)
EXPECT_CALL(mavsdk, systems()).WillOnce(testing::Return(systems));

EXPECT_CALL(*system, is_connected()).WillOnce(testing::Return(true));
EXPECT_CALL(*system, has_autopilot()).WillOnce(testing::Return(true));

initiator.start(mavsdk, ARBITRARY_CONNECTION_URL);
change_callback();
Expand All @@ -99,6 +101,7 @@ TEST(ConnectionInitiator, doesNotCrashIfDiscoverCallbackCalledMoreThanOnce)
EXPECT_CALL(mavsdk, systems()).WillRepeatedly(testing::Return(systems));

EXPECT_CALL(*system, is_connected()).WillRepeatedly(testing::Return(true));
EXPECT_CALL(*system, has_autopilot()).WillOnce(testing::Return(true));

initiator.start(mavsdk, ARBITRARY_CONNECTION_URL);
change_callback();
Expand Down

0 comments on commit b29239d

Please sign in to comment.