Skip to content
Snippets Groups Projects
Commit b17c0a11 authored by Julian Oes's avatar Julian Oes Committed by Daniel Agar
Browse files

mavlink: improve comments about message forwarding (#11323)

This removes the confusing ugly magic number of 233 introduced as part
of https://github.com/PX4/Firmware/pull/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.
parent 3d3a98c8
No related branches found
No related tags found
No related merge requests found
......@@ -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) {
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment