mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-11-13 16:01:36 +08:00
mavlink: Safely avoid send the same vehicle_command and vehicle_command_ack back
The previous approach was checking system id and component id but it will not work in 100% of cases as external devices can send MAVLink message with the right system id but with broadcast component id.
This commit is contained in:
committed by
Lorenz Meier
parent
89a428fbfe
commit
7c268f4fa1
@@ -473,6 +473,8 @@ MavlinkReceiver::handle_message_command_long(mavlink_message_t *msg)
|
||||
|
||||
vcmd.confirmation = cmd_mavlink.confirmation;
|
||||
|
||||
vcmd.from_external = 1;
|
||||
|
||||
if (_cmd_pub == nullptr) {
|
||||
_cmd_pub = orb_advertise_queue(ORB_ID(vehicle_command), &vcmd, vehicle_command_s::ORB_QUEUE_LENGTH);
|
||||
|
||||
@@ -581,6 +583,8 @@ MavlinkReceiver::handle_message_command_int(mavlink_message_t *msg)
|
||||
|
||||
vcmd.source_component = msg->compid;
|
||||
|
||||
vcmd.from_external = 1;
|
||||
|
||||
if (_cmd_pub == nullptr) {
|
||||
_cmd_pub = orb_advertise_queue(ORB_ID(vehicle_command), &vcmd, vehicle_command_s::ORB_QUEUE_LENGTH);
|
||||
|
||||
@@ -624,6 +628,7 @@ MavlinkReceiver::handle_message_command_ack(mavlink_message_t *msg)
|
||||
command_ack.command = ack.command;
|
||||
command_ack.result = ack.result;
|
||||
command_ack.timestamp = hrt_absolute_time();
|
||||
command_ack.from_external = 1;
|
||||
|
||||
if (_command_ack_pub == nullptr) {
|
||||
_command_ack_pub = orb_advertise_queue(ORB_ID(vehicle_command_ack), &command_ack,
|
||||
@@ -779,6 +784,7 @@ MavlinkReceiver::handle_message_set_mode(mavlink_message_t *msg)
|
||||
vcmd.source_component = msg->compid;
|
||||
vcmd.confirmation = 1;
|
||||
vcmd.timestamp = hrt_absolute_time();
|
||||
vcmd.from_external = 1;
|
||||
|
||||
if (_cmd_pub == nullptr) {
|
||||
_cmd_pub = orb_advertise_queue(ORB_ID(vehicle_command), &vcmd, vehicle_command_s::ORB_QUEUE_LENGTH);
|
||||
|
||||
Reference in New Issue
Block a user