mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-30 07:43:34 +08:00
tune_control: add max iteration count for the string and lib test calls
This commit is contained in:
committed by
Daniel Agar
parent
f7aad844a3
commit
dcfd2f1579
@@ -48,6 +48,8 @@
|
|||||||
|
|
||||||
#include <drivers/drv_hrt.h>
|
#include <drivers/drv_hrt.h>
|
||||||
|
|
||||||
|
#define MAX_NOTE_ITERATION 50
|
||||||
|
|
||||||
static void usage(void);
|
static void usage(void);
|
||||||
|
|
||||||
static orb_advert_t tune_control_pub = nullptr;
|
static orb_advert_t tune_control_pub = nullptr;
|
||||||
@@ -202,6 +204,7 @@ tune_control_main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned frequency, duration, silence;
|
unsigned frequency, duration, silence;
|
||||||
|
int exit_counter = 0;
|
||||||
|
|
||||||
if (!strcmp(argv[myoptind], "play")) {
|
if (!strcmp(argv[myoptind], "play")) {
|
||||||
if (string_input) {
|
if (string_input) {
|
||||||
@@ -213,9 +216,15 @@ tune_control_main(int argc, char *argv[])
|
|||||||
tune_control.duration = (uint32_t)duration;
|
tune_control.duration = (uint32_t)duration;
|
||||||
publish_tune_control(tune_control);
|
publish_tune_control(tune_control);
|
||||||
usleep(duration + silence);
|
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 {
|
} else {
|
||||||
if (tune_control.tune_id == 0) {
|
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) {
|
while (tunes.parse_cmd(tune_control, frequency, duration, silence) > 0) {
|
||||||
PX4_INFO("frequency: %d, duration %d, silence %d", frequency, duration, silence);
|
PX4_INFO("frequency: %d, duration %d, silence %d", frequency, duration, silence);
|
||||||
usleep(500000);
|
usleep(500000);
|
||||||
|
exit_counter++;
|
||||||
|
|
||||||
|
// exit if the loop is doing more thatn 50 iteration
|
||||||
|
if (exit_counter > MAX_NOTE_ITERATION) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user