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

This commit is contained in:
Beat Küng
2019-03-11 14:32:26 +01:00
committed by Daniel Agar
parent 6672284871
commit 509189ea95
2 changed files with 22 additions and 11 deletions
+21 -11
View File
@@ -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