Skip to content

Commit 591a241

Browse files
authored
Merge pull request #1868 from mavlink/pr-add-command-ack
create ack packet and send it
2 parents 508640a + 3a2a040 commit 591a241

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

src/mavsdk/plugins/mavlink_passthrough/include/plugins/mavlink_passthrough/mavlink_passthrough.h

+16
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,22 @@ class MavlinkPassthrough : public PluginBase {
135135
*/
136136
Result send_command_int(const CommandInt& command);
137137

138+
/**
139+
* @brief Create a command_ack.
140+
*
141+
* @param target_sysid Target system ID where to send command_ack to.
142+
* @param target_compid Target component ID where to send command_ack to.
143+
* @param command Command to respond to.
144+
* @param result Result of command.
145+
*
146+
* @return message to send.
147+
*/
148+
mavlink_message_t make_command_ack_message(
149+
const uint8_t target_sysid,
150+
const uint8_t target_compid,
151+
const uint16_t command,
152+
MAV_RESULT result);
153+
138154
/**
139155
* @brief Callback type for message subscriptions.
140156
*/

src/mavsdk/plugins/mavlink_passthrough/mavlink_passthrough.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ MavlinkPassthrough::Result MavlinkPassthrough::send_command_long(const CommandLo
3030
return _impl->send_command_long(command);
3131
}
3232

33+
mavlink_message_t MavlinkPassthrough::make_command_ack_message(
34+
const uint8_t target_sysid,
35+
const uint8_t target_compid,
36+
const uint16_t command,
37+
MAV_RESULT result)
38+
{
39+
return _impl->make_command_ack_message(target_sysid, target_compid, command, result);
40+
}
41+
3342
MavlinkPassthrough::MessageHandle
3443
MavlinkPassthrough::subscribe_message(uint16_t message_id, const MessageCallback& callback)
3544
{

src/mavsdk/plugins/mavlink_passthrough/mavlink_passthrough_impl.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,30 @@ MavlinkPassthroughImpl::send_command_int(const MavlinkPassthrough::CommandInt& c
8282
_parent->send_command(command_internal));
8383
}
8484

85+
mavlink_message_t MavlinkPassthroughImpl::make_command_ack_message(
86+
const uint8_t target_sysid,
87+
const uint8_t target_compid,
88+
const uint16_t command,
89+
MAV_RESULT result)
90+
{
91+
/* copied over from system impl */
92+
const uint8_t progress = std::numeric_limits<uint8_t>::max();
93+
const uint8_t result_param2 = 0;
94+
95+
mavlink_message_t msg{};
96+
mavlink_msg_command_ack_pack(
97+
get_our_sysid(),
98+
get_our_compid(),
99+
&msg,
100+
command,
101+
result,
102+
progress,
103+
result_param2,
104+
target_sysid,
105+
target_compid);
106+
return msg;
107+
}
108+
85109
MavlinkPassthrough::Result
86110
MavlinkPassthroughImpl::to_mavlink_passthrough_result_from_mavlink_commands_result(
87111
MavlinkCommandSender::Result result)

src/mavsdk/plugins/mavlink_passthrough/mavlink_passthrough_impl.h

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class MavlinkPassthroughImpl : public PluginImplBase {
2424
MavlinkPassthrough::Result send_message(mavlink_message_t& message);
2525
MavlinkPassthrough::Result send_command_long(const MavlinkPassthrough::CommandLong& command);
2626
MavlinkPassthrough::Result send_command_int(const MavlinkPassthrough::CommandInt& command);
27+
mavlink_message_t make_command_ack_message(
28+
const uint8_t target_sysid,
29+
const uint8_t target_compid,
30+
const uint16_t command,
31+
MAV_RESULT result);
2732

2833
MavlinkPassthrough::MessageHandle
2934
subscribe_message(uint16_t message_id, const MavlinkPassthrough::MessageCallback& callback);

0 commit comments

Comments
 (0)