41 #include <px4_platform_common/getopt.h> 42 #include <px4_platform_common/log.h> 49 #include <px4_platform_common/module.h> 56 #define MAX_NOTE_ITERATION 50 83 bool string_input =
false;
84 const char *tune_string =
nullptr;
87 const char *myoptarg =
nullptr;
91 tune_control.
volume = tune_control_s::VOLUME_LEVEL_DEFAULT;
93 while ((ch = px4_getopt(argc, argv,
"f:d:t:m:s:", &myoptind, &myoptarg)) != EOF) {
96 value = (uint16_t)(strtol(myoptarg,
nullptr, 0));
98 if (value > 0 && value < 22000) {
109 tune_control.
duration = (uint32_t)(strtol(myoptarg,
nullptr, 0));
113 value = (uint8_t)(strtol(myoptarg,
nullptr, 0));
127 tune_string = myoptarg;
130 if (tune_string[0] !=
'M') {
138 value = (uint8_t)(strtol(myoptarg,
nullptr, 0));
140 if (value <= tune_control_s::VOLUME_LEVEL_MAX) {
141 tune_control.
volume = value;
144 tune_control.
volume = tune_control_s::VOLUME_LEVEL_MAX;
156 if (myoptind >= argc) {
161 unsigned frequency, duration, silence;
163 int exit_counter = 0;
165 if (!strcmp(argv[myoptind],
"play")) {
167 PX4_INFO(
"Start playback...");
170 while (tunes.
get_next_note(frequency, duration, silence, volume) > 0) {
172 tune_control.
frequency = (uint16_t)frequency;
173 tune_control.
duration = (uint32_t)duration;
174 tune_control.
silence = (uint32_t)silence;
175 tune_control.
volume = (uint8_t)volume;
177 px4_usleep(duration + silence);
186 PX4_INFO(
"Playback finished.");
189 if (tune_control.
tune_id == 0) {
193 PX4_INFO(
"Publishing standard tune %d", tune_control.
tune_id);
197 }
else if (!strcmp(argv[myoptind],
"libtest")) {
200 if (ret == -EINVAL) {
201 PX4_WARN(
"Tune ID not recognized.");
204 while (tunes.
get_next_note(frequency, duration, silence, volume) > 0) {
205 PX4_INFO(
"frequency: %d, duration %d, silence %d, volume %d",
206 frequency, duration, silence, volume);
217 }
else if (!strcmp(argv[myoptind],
"stop")) {
218 PX4_INFO(
"Stopping playback...");
242 PRINT_MODULE_DESCRIPTION(
246 Command-line tool to control & test the (external) tunes. 248 Tunes are used to provide audible notification and warnings (e.g. when the system arms, gets position lock, etc.). 249 The tool requires that a driver is running that can handle the tune_control uorb topic. 251 Information about the tune format and predefined system tunes can be found here: 252 https://github.com/PX4/Firmware/blob/master/src/lib/tunes/tune_definition.desc 257 $ tune_control play -t 2 260 PRINT_MODULE_USAGE_NAME("tune_control",
"system");
261 PRINT_MODULE_USAGE_COMMAND_DESCR(
"play",
"Play system tune or single note.");
262 PRINT_MODULE_USAGE_PARAM_INT(
't', 1, 1, 21,
"Play predefined system tune",
true);
263 PRINT_MODULE_USAGE_PARAM_INT(
'f', -1, 0, 22,
"Frequency of note in Hz (0-22kHz)",
true);
264 PRINT_MODULE_USAGE_PARAM_INT(
'd', -1, 1, 21,
"Duration of note in us",
true);
265 PRINT_MODULE_USAGE_PARAM_INT(
's', 40, 0, 100,
"Volume level (loudness) of the note (0-100)",
true);
266 PRINT_MODULE_USAGE_PARAM_STRING(
'm',
nullptr, R
"(<string> - e.g. "MFT200e8a8a")", 267 "Melody in string form",
true);
268 PRINT_MODULE_USAGE_COMMAND_DESCR(
"libtest",
"Test library");
269 PRINT_MODULE_USAGE_COMMAND_DESCR(
"stop",
"Stop playback (use for repeated tunes)");
int get_next_note(unsigned &frequency, unsigned &duration, unsigned &silence)
Get next note in the current tune, which has been provided by either set_control or play_string...
High-resolution timer with callouts and timekeeping.
orb_advert_t orb_advertise_queue(const struct orb_metadata *meta, const void *data, unsigned int queue_size)
Library for parsing tunes from melody-strings or dedicated tune messages.
__EXPORT int tune_control_main(int argc, char *argv[])
#define ORB_ID(_name)
Generates a pointer to the uORB metadata structure for a given topic.
static void publish_tune_control(tune_control_s &tune_control)
static orb_advert_t tune_control_pub
int set_control(const tune_control_s &tune_control)
Set tune to be played using the message.
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
int orb_publish(const struct orb_metadata *meta, orb_advert_t handle, const void *data)
#define MAX_NOTE_ITERATION
static tune_control_s tune_control
unsigned int get_default_tunes_size() const
Get the number of default tunes.
__EXPORT hrt_abstime hrt_absolute_time(void)
Get absolute time in [us] (does not wrap).
void set_string(const char *const string, uint8_t volume)
Set tune to be played using a string.
unsigned int get_maximum_update_interval()