From 509189ea95aa651666dbf6641917378ae3554141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Mon, 11 Mar 2019 14:32:26 +0100 Subject: [PATCH] uorb top: add 'uorb top -1' to run only once --- src/modules/uORB/uORBDeviceMaster.cpp | 32 ++++++++++++++++++--------- src/modules/uORB/uORBMain.cpp | 1 + 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/modules/uORB/uORBDeviceMaster.cpp b/src/modules/uORB/uORBDeviceMaster.cpp index c761ee6131..6bce477de6 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 90396f8a0a..2459194d38 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(" []", "topic(s) to match (implies -a)", true); }