mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-27 02:06:27 +08:00
Update the test_tone() unit test to use orb_advertise() and orb_publish() instead of IOCTL() and alphabetize tests_main.h.
This commit is contained in:
@@ -40,63 +40,53 @@
|
|||||||
|
|
||||||
#include <drivers/drv_hrt.h>
|
#include <drivers/drv_hrt.h>
|
||||||
#include <drivers/drv_tone_alarm.h>
|
#include <drivers/drv_tone_alarm.h>
|
||||||
|
#include <lib/tunes/tunes.h>
|
||||||
#include <px4_posix.h>
|
#include <px4_posix.h>
|
||||||
|
#include <uORB/topics/tune_control.h>
|
||||||
|
|
||||||
#include "tests_main.h"
|
#include "tests_main.h"
|
||||||
|
|
||||||
|
|
||||||
int test_tone(int argc, char *argv[])
|
int test_tone(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int fd, result;
|
int result = PX4_ERROR;
|
||||||
unsigned long tone;
|
tune_control_s tune_control = {};
|
||||||
|
tune_control.tune_id = static_cast<int>(TuneID::NOTIFY_NEGATIVE);
|
||||||
|
|
||||||
fd = px4_open(TONE_ALARM0_DEVICE_PATH, O_WRONLY);
|
orb_advert_t tune_control_pub = orb_advertise(ORB_ID(tune_control), &tune_control);
|
||||||
|
|
||||||
if (fd < 0) {
|
if (argc == 1) {
|
||||||
printf("failed opening " TONE_ALARM0_DEVICE_PATH "\n");
|
PX4_INFO("Volume silenced for testing predefined tunes 0-20.");
|
||||||
goto out;
|
tune_control.strength = 0;
|
||||||
|
|
||||||
|
for (size_t i = 0; i <= 20; i++) {
|
||||||
|
tune_control.tune_id = i;
|
||||||
|
result = orb_publish(ORB_ID(tune_control), tune_control_pub, &tune_control);
|
||||||
|
|
||||||
|
if (result != PX4_OK) {
|
||||||
|
PX4_INFO("Error publishing TuneID: %d", tune_control.tune_id);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tune_control.tune_id = static_cast<int>(TuneID::NOTIFY_POSITIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
tone = 1;
|
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
tone = atoi(argv[1]);
|
if (tune_control.tune_id <= 20) {
|
||||||
}
|
tune_control.tune_id = atoi(argv[1]);
|
||||||
|
PX4_INFO("Testing TuneID: %d", tune_control.tune_id);
|
||||||
if (tone == 0) {
|
|
||||||
result = px4_ioctl(fd, TONE_SET_ALARM, TONE_STOP_TUNE);
|
|
||||||
|
|
||||||
if (result < 0) {
|
|
||||||
printf("failed clearing alarms\n");
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
printf("Alarm stopped.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
result = px4_ioctl(fd, TONE_SET_ALARM, TONE_STOP_TUNE);
|
|
||||||
|
|
||||||
if (result < 0) {
|
|
||||||
printf("failed clearing alarms\n");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = px4_ioctl(fd, TONE_SET_ALARM, tone);
|
|
||||||
|
|
||||||
if (result < 0) {
|
|
||||||
printf("failed setting alarm %lu\n", tone);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
printf("Alarm %lu (disable with: tests tone 0)\n", tone);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
if (argc == 3) {
|
||||||
|
Tunes tunes{};
|
||||||
if (fd >= 0) {
|
tunes.set_string(argv[2], 40);
|
||||||
px4_close(fd);
|
PX4_INFO("Testing custom tune.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
tune_control.strength = 40;
|
||||||
|
result = orb_publish(ORB_ID(tune_control), tune_control_pub, &tune_control);
|
||||||
|
|
||||||
|
orb_unadvertise(tune_control_pub);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,9 +45,9 @@ __BEGIN_DECLS
|
|||||||
|
|
||||||
extern int test_adc(int argc, char *argv[]);
|
extern int test_adc(int argc, char *argv[]);
|
||||||
extern int test_autodeclination(int argc, char *argv[]);
|
extern int test_autodeclination(int argc, char *argv[]);
|
||||||
extern int test_hysteresis(int argc, char *argv[]);
|
|
||||||
extern int test_bezierQuad(int argc, char *argv[]);
|
extern int test_bezierQuad(int argc, char *argv[]);
|
||||||
extern int test_bson(int argc, char *argv[]);
|
extern int test_bson(int argc, char *argv[]);
|
||||||
|
extern int test_controlmath(int argc, char *argv[]);
|
||||||
extern int test_conv(int argc, char *argv[]);
|
extern int test_conv(int argc, char *argv[]);
|
||||||
extern int test_dataman(int argc, char *argv[]);
|
extern int test_dataman(int argc, char *argv[]);
|
||||||
extern int test_file(int argc, char *argv[]);
|
extern int test_file(int argc, char *argv[]);
|
||||||
@@ -55,6 +55,7 @@ extern int test_file2(int argc, char *argv[]);
|
|||||||
extern int test_float(int argc, char *argv[]);
|
extern int test_float(int argc, char *argv[]);
|
||||||
extern int test_hott_telemetry(int argc, char *argv[]);
|
extern int test_hott_telemetry(int argc, char *argv[]);
|
||||||
extern int test_hrt(int argc, char *argv[]);
|
extern int test_hrt(int argc, char *argv[]);
|
||||||
|
extern int test_hysteresis(int argc, char *argv[]);
|
||||||
extern int test_int(int argc, char *argv[]);
|
extern int test_int(int argc, char *argv[]);
|
||||||
extern int test_jig_voltages(int argc, char *argv[]);
|
extern int test_jig_voltages(int argc, char *argv[]);
|
||||||
extern int test_led(int argc, char *argv[]);
|
extern int test_led(int argc, char *argv[]);
|
||||||
@@ -67,6 +68,7 @@ extern int test_microbench_uorb(int argc, char *argv[]);
|
|||||||
extern int test_mixer(int argc, char *argv[]);
|
extern int test_mixer(int argc, char *argv[]);
|
||||||
extern int test_mount(int argc, char *argv[]);
|
extern int test_mount(int argc, char *argv[]);
|
||||||
extern int test_param(int argc, char *argv[]);
|
extern int test_param(int argc, char *argv[]);
|
||||||
|
extern int test_parameters(int argc, char *argv[]);
|
||||||
extern int test_perf(int argc, char *argv[]);
|
extern int test_perf(int argc, char *argv[]);
|
||||||
extern int test_ppm(int argc, char *argv[]);
|
extern int test_ppm(int argc, char *argv[]);
|
||||||
extern int test_ppm_loopback(int argc, char *argv[]);
|
extern int test_ppm_loopback(int argc, char *argv[]);
|
||||||
@@ -75,6 +77,7 @@ extern int test_search_min(int argc, char *argv[]);
|
|||||||
extern int test_sensors(int argc, char *argv[]);
|
extern int test_sensors(int argc, char *argv[]);
|
||||||
extern int test_servo(int argc, char *argv[]);
|
extern int test_servo(int argc, char *argv[]);
|
||||||
extern int test_sleep(int argc, char *argv[]);
|
extern int test_sleep(int argc, char *argv[]);
|
||||||
|
extern int test_smooth_z(int argc, char *argv[]);
|
||||||
extern int test_time(int argc, char *argv[]);
|
extern int test_time(int argc, char *argv[]);
|
||||||
extern int test_tone(int argc, char *argv[]);
|
extern int test_tone(int argc, char *argv[]);
|
||||||
extern int test_uart_baudchange(int argc, char *argv[]);
|
extern int test_uart_baudchange(int argc, char *argv[]);
|
||||||
@@ -82,10 +85,7 @@ extern int test_uart_break(int argc, char *argv[]);
|
|||||||
extern int test_uart_console(int argc, char *argv[]);
|
extern int test_uart_console(int argc, char *argv[]);
|
||||||
extern int test_uart_loopback(int argc, char *argv[]);
|
extern int test_uart_loopback(int argc, char *argv[]);
|
||||||
extern int test_uart_send(int argc, char *argv[]);
|
extern int test_uart_send(int argc, char *argv[]);
|
||||||
extern int test_parameters(int argc, char *argv[]);
|
|
||||||
extern int test_versioning(int argc, char *argv[]);
|
extern int test_versioning(int argc, char *argv[]);
|
||||||
extern int test_smooth_z(int argc, char *argv[]);
|
|
||||||
extern int test_controlmath(int argc, char *argv[]);
|
|
||||||
|
|
||||||
/* external */
|
/* external */
|
||||||
extern int commander_tests_main(int argc, char *argv[]);
|
extern int commander_tests_main(int argc, char *argv[]);
|
||||||
|
|||||||
Reference in New Issue
Block a user