Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gimbal: fix unregister message subscription #2208

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/mavsdk/plugins/gimbal/gimbal_protocol_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ GimbalProtocolV2::GimbalProtocolV2(
_gimbal_manager_compid(gimbal_manager_compid)
{}

GimbalProtocolV2::~GimbalProtocolV2()
{
if (_is_mavlink_manager_status_registered) {
_is_mavlink_manager_status_registered = false;

_system_impl.unregister_mavlink_message_handler(MAVLINK_MSG_ID_GIMBAL_MANAGER_STATUS, this);
Comment on lines +24 to +26
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it matters, but I'm always more comfortable setting the boolean after the fact (i.e. inverting those lines). So that it reads "now that I unregistered, I update the boolean that holds the registration state".

Probably just a nitpick though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The advantage of that way is that the check and set are right after each other and less likely to drift apart from each other and get lost.

Best case, it should not be a two step approach but one. Actually, we don't need this variable. We can just unregister and if we haven't registered it's silently ignored...

}
}

void GimbalProtocolV2::process_gimbal_manager_status(const mavlink_message_t& message)
{
Gimbal::ControlMode new_control_mode;
Expand Down
2 changes: 1 addition & 1 deletion src/mavsdk/plugins/gimbal/gimbal_protocol_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class GimbalProtocolV2 : public GimbalProtocolBase {
const mavlink_gimbal_manager_information_t& information,
uint8_t gimbal_manager_sysid,
uint8_t gimbal_manager_compid);
~GimbalProtocolV2() override = default;
~GimbalProtocolV2() override;

Gimbal::Result set_pitch_and_yaw(float pitch_deg, float yaw_deg) override;
void set_pitch_and_yaw_async(
Expand Down