Skip to content

Commit

Permalink
info: prevent a few potential lockups
Browse files Browse the repository at this point in the history
These happened when a system was re-discovered.

Signed-off-by: Julian Oes <[email protected]>
  • Loading branch information
julianoes committed Apr 17, 2024
1 parent d5a73f9 commit 4d16950
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/mavsdk/plugins/info/info_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void InfoImpl::enable()

if (!_flight_info_subscriptions.empty()) {
// We're hoping to get flight information regularly to update flight time.
_system_impl->set_msg_rate(MAVLINK_MSG_ID_FLIGHT_INFORMATION, 1.0);
_system_impl->set_msg_rate_async(MAVLINK_MSG_ID_FLIGHT_INFORMATION, 1.0, nullptr);
}
}

Expand Down Expand Up @@ -321,20 +321,20 @@ void InfoImpl::wait_for_identification() const
Info::FlightInformationHandle
InfoImpl::subscribe_flight_information(const Info::FlightInformationCallback& callback)
{
std::lock_guard<std::mutex> lock(_mutex);

// Make sure we get the message regularly.
_system_impl->set_msg_rate(MAVLINK_MSG_ID_FLIGHT_INFORMATION, 1.0);
_system_impl->set_msg_rate_async(MAVLINK_MSG_ID_FLIGHT_INFORMATION, 1.0, nullptr);

std::lock_guard<std::mutex> lock(_mutex);

return _flight_info_subscriptions.subscribe(callback);
}

void InfoImpl::unsubscribe_flight_information(Info::FlightInformationHandle handle)
{
std::lock_guard<std::mutex> lock(_mutex);

// Reset message to default
_system_impl->set_msg_rate(MAVLINK_MSG_ID_FLIGHT_INFORMATION, 0.0);
_system_impl->set_msg_rate_async(MAVLINK_MSG_ID_FLIGHT_INFORMATION, 0.0, nullptr);

std::lock_guard<std::mutex> lock(_mutex);

_flight_info_subscriptions.unsubscribe(handle);
}
Expand Down

0 comments on commit 4d16950

Please sign in to comment.