diff --git a/src/modules/uORB/uORBDeviceMaster.cpp b/src/modules/uORB/uORBDeviceMaster.cpp index c761ee6131bdac669329453f241733bf81b6314f..6bce477de6c22172c0cd37e6744f711b9b286cd7 100644 --- a/src/modules/uORB/uORBDeviceMaster.cpp +++ b/src/modules/uORB/uORBDeviceMaster.cpp @@ -249,13 +249,25 @@ void uORB::DeviceMaster::addNewDeviceNodes(DeviceNodeStatisticsData **first_node void uORB::DeviceMaster::showTop(char **topic_filter, int num_filters) { bool print_active_only = true; + bool only_once = false; // if true, run only once, then exit if (topic_filter && num_filters > 0) { - if (!strcmp("-a", topic_filter[0])) { - num_filters = 0; + bool show_all = false; + + for (int i = 0; i < num_filters; ++i) { + if (!strcmp("-a", topic_filter[i])) { + show_all = true; + + } else if (!strcmp("-1", topic_filter[i])) { + only_once = true; + } } - print_active_only = false; // print non-active if -a or some filter given + print_active_only = only_once ? (num_filters == 1) : false; // print non-active if -a or some filter given + + if (show_all || print_active_only) { + num_filters = 0; + } } PX4_INFO_RAW("\033[2J\n"); //clear screen @@ -278,7 +290,7 @@ void uORB::DeviceMaster::showTop(char **topic_filter, int num_filters) unlock(); #ifdef __PX4_QURT //QuRT has no poll() - int num_runs = 0; + only_once = true; #else const int stdin_fileno = 0; @@ -292,13 +304,7 @@ void uORB::DeviceMaster::showTop(char **topic_filter, int num_filters) while (!quit) { -#ifdef __PX4_QURT - - if (++num_runs > 1) { - quit = true; //just exit after one output - } - -#else +#ifndef __PX4_QURT /* Sleep 200 ms waiting for user input five times ~ 1s */ for (int k = 0; k < 5; k++) { @@ -362,6 +368,10 @@ void uORB::DeviceMaster::showTop(char **topic_filter, int num_filters) addNewDeviceNodes(&first_node, num_topics, max_topic_name_length, topic_filter, num_filters); unlock(); } + + if (only_once) { + quit = true; + } } //cleanup diff --git a/src/modules/uORB/uORBMain.cpp b/src/modules/uORB/uORBMain.cpp index 90396f8a0a8ba27895569284cf393ed1f28d7d20..2459194d38e8845f48f9fa41c9e803dc27e7db82 100644 --- a/src/modules/uORB/uORBMain.cpp +++ b/src/modules/uORB/uORBMain.cpp @@ -78,6 +78,7 @@ $ uorb top PRINT_MODULE_USAGE_COMMAND_DESCR("status", "Print topic statistics"); PRINT_MODULE_USAGE_COMMAND_DESCR("top", "Monitor topic publication rates"); PRINT_MODULE_USAGE_PARAM_FLAG('a', "print all instead of only currently publishing topics", true); + PRINT_MODULE_USAGE_PARAM_FLAG('1', "run only once, then exit", true); PRINT_MODULE_USAGE_ARG("<filter1> [<filter2>]", "topic(s) to match (implies -a)", true); }