Skip to content
Snippets Groups Projects
Commit 509189ea authored by Beat Küng's avatar Beat Küng Committed by Daniel Agar
Browse files

uorb top: add 'uorb top -1' to run only once

parent 66722848
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment