POSIX: Improve shell so it does not spam the user, enable CTRL-C to actually quit the application. Twiddle the app boot delay to avoid a race with the commander app. Needs a proper fix on the startup sequencing.

This commit is contained in:
Lorenz Meier
2015-09-06 15:37:35 +02:00
parent 4450f1ae54
commit 54209af679
2 changed files with 32 additions and 13 deletions
+30 -11
View File
@@ -65,11 +65,15 @@ extern "C" {
}
}
static void print_prompt()
{
cout << "pxh> ";
}
static void run_cmd(const vector<string> &appargs)
{
// command is appargs[0]
string command = appargs[0];
cout << "----------------------------------\n";
if (apps.find(command) != apps.end()) {
const char *arg[appargs.size() + 2];
@@ -82,15 +86,20 @@ static void run_cmd(const vector<string> &appargs)
}
arg[i] = (char *)0;
cout << "Running: " << command << "\n";
apps[command](i, (char **)arg);
usleep(40000);
cout << "Returning: " << command << "\n";
usleep(45000);
} else if (command.compare("help") == 0) {
list_builtins();
} else if (command.length() == 0) {
// Do nothing
} else {
cout << "Invalid command: " << command << endl;
list_builtins();
cout << "Invalid command: " << command << "\ntype 'help' for a list of commands" << endl;
}
print_prompt();
}
static void usage()
@@ -177,16 +186,26 @@ int main(int argc, char **argv)
if (!daemon_mode) {
string mystr;
print_prompt();
while (!_ExitFlag) {
cout << "Enter a command and its args:" << endl;
getline(cin, mystr);
process_line(mystr);
mystr = "";
struct pollfd fds;
int ret;
fds.fd = 0; /* stdin */
fds.events = POLLIN;
ret = poll(&fds, 1, 100);
if (ret > 0) {
getline(cin, mystr);
process_line(mystr);
mystr = "";
}
}
} else {
while (!_ExitFlag) {
sleep(1000000);
usleep(100000);
}
}
@@ -143,7 +143,7 @@ px4_task_t px4_task_spawn_cmd(const char *name, int scheduler, int priority, int
// Must add NULL at end of argv
taskdata->argv[argc] = (char *)0;
PX4_WARN("starting task %s", name);
PX4_DEBUG("starting task %s", name);
rv = pthread_attr_init(&attr);
if (rv != 0) {
@@ -203,7 +203,7 @@ int px4_task_delete(px4_task_t id)
{
int rv = 0;
pthread_t pid;
PX4_WARN("Called px4_task_delete");
PX4_DEBUG("Called px4_task_delete");
if (id < PX4_MAX_TASKS && taskmap[id].isused)
pid = taskmap[id].pid;