From dcfd2f1579f1949f2b40b19f0ced52e9018788e4 Mon Sep 17 00:00:00 2001 From: Simone Guscetti <simone@px4.io> Date: Fri, 17 Feb 2017 15:02:12 +0100 Subject: [PATCH] tune_control: add max iteration count for the string and lib test calls --- src/systemcmds/tune_control/tune_control.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/systemcmds/tune_control/tune_control.cpp b/src/systemcmds/tune_control/tune_control.cpp index aa00da467a..c3c92a503e 100644 --- a/src/systemcmds/tune_control/tune_control.cpp +++ b/src/systemcmds/tune_control/tune_control.cpp @@ -48,6 +48,8 @@ #include <drivers/drv_hrt.h> +#define MAX_NOTE_ITERATION 50 + static void usage(void); static orb_advert_t tune_control_pub = nullptr; @@ -202,6 +204,7 @@ tune_control_main(int argc, char *argv[]) } unsigned frequency, duration, silence; + int exit_counter = 0; if (!strcmp(argv[myoptind], "play")) { if (string_input) { @@ -213,9 +216,15 @@ tune_control_main(int argc, char *argv[]) tune_control.duration = (uint32_t)duration; publish_tune_control(tune_control); usleep(duration + silence); + exit_counter++; + + // exit if the loop is doing more thatn 50 iteration + if (exit_counter > MAX_NOTE_ITERATION) { + break; + } } - PX4_INFO("Playback finished.") + PX4_INFO("Playback finished."); } else { if (tune_control.tune_id == 0) { @@ -230,6 +239,12 @@ tune_control_main(int argc, char *argv[]) while (tunes.parse_cmd(tune_control, frequency, duration, silence) > 0) { PX4_INFO("frequency: %d, duration %d, silence %d", frequency, duration, silence); usleep(500000); + exit_counter++; + + // exit if the loop is doing more thatn 50 iteration + if (exit_counter > MAX_NOTE_ITERATION) { + break; + } } } else { -- GitLab