diff --git a/src/modules/mavlink/mavlink_receiver.cpp b/src/modules/mavlink/mavlink_receiver.cpp index 891b58cb85..199f6b082c 100644 --- a/src/modules/mavlink/mavlink_receiver.cpp +++ b/src/modules/mavlink/mavlink_receiver.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #ifdef CONFIG_NET #include @@ -453,7 +454,6 @@ void MavlinkReceiver::handle_message_command_both(mavlink_message_t *msg, const const vehicle_command_s &vehicle_command) { bool target_ok = evaluate_target_ok(cmd_mavlink.command, cmd_mavlink.target_system, cmd_mavlink.target_component); - bool send_ack = true; uint8_t result = vehicle_command_ack_s::VEHICLE_RESULT_ACCEPTED; @@ -474,19 +474,37 @@ void MavlinkReceiver::handle_message_command_both(mavlink_message_t *msg, const _mavlink->configure_stream_threadsafe("HOME_POSITION", 0.5f); } else if (cmd_mavlink.command == MAV_CMD_SET_MESSAGE_INTERVAL) { - if (set_message_interval((int)(cmd_mavlink.param1 + 0.5f), cmd_mavlink.param2, cmd_mavlink.param3)) { + if (set_message_interval((int)roundf(cmd_mavlink.param1), cmd_mavlink.param2, cmd_mavlink.param3)) { result = vehicle_command_ack_s::VEHICLE_RESULT_FAILED; } } else if (cmd_mavlink.command == MAV_CMD_GET_MESSAGE_INTERVAL) { - get_message_interval((int)cmd_mavlink.param1); + get_message_interval((int)roundf(cmd_mavlink.param1)); } else if (cmd_mavlink.command == MAV_CMD_REQUEST_FLIGHT_INFORMATION) { send_flight_information(); } else if (cmd_mavlink.command == MAV_CMD_REQUEST_STORAGE_INFORMATION) { - if ((int)(cmd_mavlink.param2 + 0.5f) == 1) { - send_storage_information(cmd_mavlink.param1 + 0.5f); + if ((int)roundf(cmd_mavlink.param1) == 1) { + send_storage_information((int)roundf(cmd_mavlink.param1)); + } + + } else if (cmd_mavlink.command == MAV_CMD_REQUEST_MESSAGE) { + uint16_t message_id = (uint16_t)roundf(cmd_mavlink.param1); + bool stream_found = false; + + for (const auto &stream : _mavlink->get_streams()) { + if (stream->get_id() == message_id) { + stream->request_message(vehicle_command.param1, vehicle_command.param2, vehicle_command.param3, + vehicle_command.param4, vehicle_command.param5, vehicle_command.param6, vehicle_command.param7); + stream_found = true; + break; + } + } + + // TODO: Handle the case where a message is requested which could be sent, but for which there is no stream. + if (!stream_found) { + result = vehicle_command_ack_s::VEHICLE_RESULT_DENIED; } } else { diff --git a/src/modules/mavlink/mavlink_stream.h b/src/modules/mavlink/mavlink_stream.h index 15f956e5a8..fe1ac84dc7 100644 --- a/src/modules/mavlink/mavlink_stream.h +++ b/src/modules/mavlink/mavlink_stream.h @@ -92,6 +92,13 @@ public: */ virtual unsigned get_size() = 0; + /** + * This function is called in response to a MAV_CMD_REQUEST_MESSAGE command. The default implementation is to + * just reset the counter to immediately send one message. + */ + virtual void request_message(float param1 = 0.0, float param2 = 0.0, float param3 = 0.0, float param4 = 0.0, + float param5 = 0.0, float param6 = 0.0, float param7 = 0.0) { reset_last_sent(); } + /** * Get the average message size *