40 #include <px4_platform_common/module.h> 41 #include <px4_platform_common/getopt.h> 56 unsigned topic_interval)
59 if (topic_instance == -1 && num_msgs == 1) {
70 PX4_INFO_RAW(
"\nTOPIC: %s\n", id->
o_name);
75 }
else if (instances > 1) {
76 PX4_INFO_RAW(
"\nTOPIC: %s %d instances\n", id->
o_name, instances);
80 PX4_INFO_RAW(
"\nInstance %d:\n", i);
89 PX4_INFO_RAW(
"never published\n");
94 if (topic_instance == -1) {
99 PX4_INFO_RAW(
"never published\n");
106 unsigned msgs_received = 0;
108 struct pollfd fds[2] {};
111 fds[0].events = POLLIN;
114 fds[1].events = POLLIN;
116 while (msgs_received < num_msgs) {
121 if (fds[0].revents & POLLIN) {
123 int ret =
read(0, &c, 1);
139 if (fds[1].revents & POLLIN) {
142 PX4_INFO_RAW(
"\nTOPIC: %s instance %d #%d\n", id->
o_name, topic_instance, msgs_received);
144 int ret = cb(
id, sub);
147 PX4_ERR(
"listener callback failed (%i)", ret);
152 PX4_INFO_RAW(
"Waited for %.1f seconds without a message. Giving up.\n", (
double)
MESSAGE_TIMEOUT_S);
170 char *topic_name = argv[1];
172 int topic_instance = -1;
173 unsigned topic_rate = 0;
174 unsigned num_msgs = 0;
178 const char *myoptarg =
nullptr;
180 while ((ch = px4_getopt(argc, argv,
"i:r:n:", &myoptind, &myoptarg)) != EOF) {
184 topic_instance = strtol(myoptarg,
nullptr, 0);
188 topic_rate = strtol(myoptarg,
nullptr, 0);
192 num_msgs = strtol(myoptarg,
nullptr, 0);
203 if (topic_rate != 0) {
204 num_msgs = 30 * topic_rate;
220 PRINT_MODULE_DESCRIPTION(
222 Utility to listen on uORB topics and print the data to the console. 224 The listener can be exited any time by pressing Ctrl+C, Esc, or Q. 227 PRINT_MODULE_USAGE_NAME("listener",
"command");
228 PRINT_MODULE_USAGE_ARG(
"<topic_name>",
"uORB topic name",
false);
231 PRINT_MODULE_USAGE_PARAM_INT(
'n', 1, 0, 100,
"Number of messages",
true);
232 PRINT_MODULE_USAGE_PARAM_INT(
'r', 0, 0, 1000,
"Subscription rate (unlimited if 0)",
true);
int(* listener_print_topic_cb)(const orb_id_t &orb_id, int subscription)
int orb_set_interval(int handle, unsigned interval)
void listener(listener_print_topic_cb cb, const orb_id_t &id, unsigned num_msgs, int topic_instance, unsigned topic_interval)
int orb_exists(const struct orb_metadata *meta, int instance)
__EXPORT int listener_main(int argc, char *argv[])
static void read(bootloader_app_shared_t *pshared)
int orb_subscribe(const struct orb_metadata *meta)
static constexpr float MESSAGE_TIMEOUT_S
int orb_unsubscribe(int handle)
void listener_generated(char *topic_name, int topic_instance, int topic_rate, int num_msgs)
int orb_subscribe_multi(const struct orb_metadata *meta, unsigned instance)
#define ORB_MULTI_MAX_INSTANCES
Maximum number of multi topic instances.