From eacdd36a0a37db59b83219f2864a4937a588e29f Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Mon, 4 Nov 2019 11:39:35 +0100 Subject: [PATCH] mavlink: add support for PLAY_TUNE_V2 --- src/modules/mavlink/mavlink_receiver.cpp | 27 +++++++++++++++++++++++- src/modules/mavlink/mavlink_receiver.h | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/modules/mavlink/mavlink_receiver.cpp b/src/modules/mavlink/mavlink_receiver.cpp index 2c0ba892933b..8ebcf6bf5bde 100644 --- a/src/modules/mavlink/mavlink_receiver.cpp +++ b/src/modules/mavlink/mavlink_receiver.cpp @@ -238,6 +238,10 @@ MavlinkReceiver::handle_message(mavlink_message_t *msg) handle_message_play_tune(msg); break; + case MAVLINK_MSG_ID_PLAY_TUNE_V2: + handle_message_play_tune_v2(msg); + break; + case MAVLINK_MSG_ID_OBSTACLE_DISTANCE: handle_message_obstacle_distance(msg); break; @@ -1762,13 +1766,34 @@ MavlinkReceiver::handle_message_play_tune(mavlink_message_t *msg) if ((mavlink_system.sysid == play_tune.target_system || play_tune.target_system == 0) && (mavlink_system.compid == play_tune.target_component || play_tune.target_component == 0)) { - // Let's make sure the input is 0 terminated and we don't ever overrun it. + // Let's make sure the input is 0 terminated, so we don't ever overrun it. play_tune.tune2[sizeof(play_tune.tune2) - 1] = '\0'; publish_tune(play_tune.tune); } } +void +MavlinkReceiver::handle_message_play_tune_v2(mavlink_message_t *msg) +{ + mavlink_play_tune_v2_t play_tune_v2; + mavlink_msg_play_tune_v2_decode(msg, &play_tune_v2); + + if ((mavlink_system.sysid == play_tune_v2.target_system || play_tune_v2.target_system == 0) && + (mavlink_system.compid == play_tune_v2.target_component || play_tune_v2.target_component == 0)) { + + if (play_tune_v2.format != TUNE_FORMAT_QBASIC1_1) { + PX4_ERR("Tune format %d not supported", play_tune_v2.format); + return; + } + + // Let's make sure the input is 0 terminated, so we don't ever overrun it. + play_tune_v2.tune[sizeof(play_tune_v2.tune) - 1] = '\0'; + + publish_tune(play_tune_v2.tune); + } +} + void MavlinkReceiver::publish_tune(const char *tune) { diff --git a/src/modules/mavlink/mavlink_receiver.h b/src/modules/mavlink/mavlink_receiver.h index 5f2e4f3595ed..7ba25f22166e 100644 --- a/src/modules/mavlink/mavlink_receiver.h +++ b/src/modules/mavlink/mavlink_receiver.h @@ -159,6 +159,7 @@ class MavlinkReceiver : public ModuleParams void handle_message_optical_flow_rad(mavlink_message_t *msg); void handle_message_ping(mavlink_message_t *msg); void handle_message_play_tune(mavlink_message_t *msg); + void handle_message_play_tune_v2(mavlink_message_t *msg); void handle_message_radio_status(mavlink_message_t *msg); void handle_message_rc_channels_override(mavlink_message_t *msg); void handle_message_serial_control(mavlink_message_t *msg);