From da62d21643235f5a4028d56479b0a9de3b809ae3 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Thu, 19 May 2022 13:27:05 +1200 Subject: [PATCH 1/2] Revert "Fix system discovery" This reverts commit 3d03fb0e0deabf211faa985b1c8c321b5fc20b7f. --- src/mavsdk/core/mavsdk_impl.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/mavsdk/core/mavsdk_impl.cpp b/src/mavsdk/core/mavsdk_impl.cpp index c85f6e69f5..04a1b9cd18 100644 --- a/src/mavsdk/core/mavsdk_impl.cpp +++ b/src/mavsdk/core/mavsdk_impl.cpp @@ -300,10 +300,13 @@ void MavsdkImpl::receive_message(mavlink_message_t& message, Connection* connect std::lock_guard lock(_systems_mutex); - // If we have a system with sysid 0, it is the "fake" system we built to initialize the - // connection to the remote. We can remove it now that a remote system is discovered. + // The only situation where we create a system with sysid 0 is when we initialize the connection + // to the remote. if (_systems.size() == 1 && _systems[0].first == 0) { - _systems.clear(); + LogDebug() << "New: System ID: " << static_cast(message.sysid) + << " Comp ID: " << static_cast(message.compid); + _systems[0].first = message.sysid; + _systems[0].second->system_impl()->set_system_id(message.sysid); } bool found_system = false; From 5d87759207b816c57014fe82bdac8675359f4003 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Thu, 19 May 2022 13:38:10 +1200 Subject: [PATCH 2/2] core: notify when fake system becomes real system This makes sure we notify the user when a system actually connects after it has been created in anticipation that it will eventually exist. --- src/mavsdk/core/mavsdk_impl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mavsdk/core/mavsdk_impl.cpp b/src/mavsdk/core/mavsdk_impl.cpp index 04a1b9cd18..5ae10ad7cf 100644 --- a/src/mavsdk/core/mavsdk_impl.cpp +++ b/src/mavsdk/core/mavsdk_impl.cpp @@ -307,6 +307,10 @@ void MavsdkImpl::receive_message(mavlink_message_t& message, Connection* connect << " Comp ID: " << static_cast(message.compid); _systems[0].first = message.sysid; _systems[0].second->system_impl()->set_system_id(message.sysid); + + // Even though the fake system was already discovered, we can now + // send a notification, now that it seems to really actually exist. + notify_on_discover(); } bool found_system = false;