Skip to content

Commit

Permalink
mavlink: improve comments about message forwarding
Browse files Browse the repository at this point in the history
This removes the confusing ugly magic number of 233 introduced as part
of #7670.

Also, the convoluted if is cleaned up using 3 separate bools with some
comments to explain what's going on.

This should not change anything function-wise except that the flight
controller could now potentially also use system ID 233 and not break
forwarding.
  • Loading branch information
julianoes committed Jan 28, 2019
1 parent cced80e commit f6f415e
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/modules/mavlink/mavlink_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ Mavlink::forward_message(const mavlink_message_t *msg, Mavlink *self)
const mavlink_msg_entry_t *meta = mavlink_get_msg_entry(msg->msgid);

int target_system_id = 0;
int target_component_id = 233;
int target_component_id = 0;

// might be nullptr if message is unknown
if (meta) {
Expand All @@ -557,11 +557,21 @@ Mavlink::forward_message(const mavlink_message_t *msg, Mavlink *self)
}
}

// Broadcast or addressing this system and not trying to talk
// to the autopilot component -> pass on to other components
if ((target_system_id == 0 || target_system_id == self->get_system_id())
&& (target_component_id == 0 || target_component_id != self->get_component_id())
&& !(!self->forward_heartbeats_enabled() && msg->msgid == MAVLINK_MSG_ID_HEARTBEAT)) {
// We forward messages targetted at the same system, or addressed to all systems, or
// if not target system is set.
const bool target_system_id_ok =
(target_system_id == 0 || target_system_id == self->get_system_id());

// We forward messages that are targetting another component, or are addressed to all
// components, or if the target component is not set.
const bool target_component_id_ok =
(target_component_id == 0 || target_component_id != self->get_component_id());

// We don't forward heartbeats unless it's specifically enabled.
const bool heartbeat_check_ok =
(msg->msgid != MAVLINK_MSG_ID_HEARTBEAT || self->forward_heartbeats_enabled())

if (target_system_id_ok && target_component_id_ok && heartbeat_check_ok) {

inst->pass_message(msg);
}
Expand Down

0 comments on commit f6f415e

Please sign in to comment.