diff --git a/makefiles/qurt/toolchain_hexagon.mk b/makefiles/qurt/toolchain_hexagon.mk index 038c299904..c54a74f203 100644 --- a/makefiles/qurt/toolchain_hexagon.mk +++ b/makefiles/qurt/toolchain_hexagon.mk @@ -47,7 +47,7 @@ endif # HEXAGON_TOOLS_ROOT ?= /opt/6.4.03 #HEXAGON_TOOLS_ROOT = /opt/6.4.05 -HEXAGON_SDK_ROOT = /opt/Hexagon_SDK/2.0 +HEXAGON_SDK_ROOT ?= /opt/Hexagon_SDK/2.0 V_ARCH = v5 CROSSDEV = hexagon- HEXAGON_BIN = $(addsuffix /gnu/bin,$(HEXAGON_TOOLS_ROOT)) diff --git a/src/platforms/posix/main.cpp b/src/platforms/posix/main.cpp index 9f914ed693..dbc4b7cc3f 100644 --- a/src/platforms/posix/main.cpp +++ b/src/platforms/posix/main.cpp @@ -32,7 +32,7 @@ ****************************************************************************/ /** * @file main.cpp - * Basic shell to execute builtin "apps" + * Basic shell to execute builtin "apps" * * @author Mark Charlebois */ @@ -42,8 +42,10 @@ #include #include #include +#include -namespace px4 { +namespace px4 +{ void init_once(void); } @@ -54,21 +56,34 @@ typedef int (*px4_main_t)(int argc, char *argv[]); #include "apps.h" #include "px4_middleware.h" -static void run_cmd(const vector &appargs) { +static bool _ExitFlag = false; +extern "C" { + void _SigIntHandler(int sig_num); + void _SigIntHandler(int sig_num) + { + _ExitFlag = true; + } +} + +static void run_cmd(const vector &appargs) +{ // command is appargs[0] string command = appargs[0]; cout << "----------------------------------\n"; + if (apps.find(command) != apps.end()) { - const char *arg[appargs.size()+2]; + const char *arg[appargs.size() + 2]; unsigned int i = 0; + while (i < appargs.size() && appargs[i] != "") { arg[i] = (char *)appargs[i].c_str(); ++i; } + arg[i] = (char *)0; cout << "Running: " << command << "\n"; - apps[command](i,(char **)arg); + apps[command](i, (char **)arg); usleep(40000); cout << "Returning: " << command << "\n"; @@ -78,40 +93,93 @@ static void run_cmd(const vector &appargs) { } } +static void usage() +{ + + cout << "./mainapp [-d] [startup_config] -h" << std::endl; + cout << " -d - Optional flag to run the app in daemon mode and does not take listen for user input." << + std::endl; + cout << " This is needed if mainapp is intended to be run as a upstart job on linux" << std::endl; + cout << " - config file for starting/stopping px4 modules" << std::endl; + cout << " -h - help/usage information" << std::endl; +} + static void process_line(string &line) { vector appargs(8); - stringstream(line) >> appargs[0] >> appargs[1] >> appargs[2] >> appargs[3] >> appargs[4] >> appargs[5] >> appargs[6] >> appargs[7]; + stringstream(line) >> appargs[0] >> appargs[1] >> appargs[2] >> appargs[3] >> appargs[4] >> appargs[5] >> appargs[6] >> + appargs[7]; run_cmd(appargs); } int main(int argc, char **argv) { - px4::init_once(); + bool daemon_mode = false; + signal(SIGINT, _SigIntHandler); - px4::init(argc, argv, "mainapp"); + int index = 1; + bool error_detected = false; - // Execute a command list of provided - if (argc == 2) { - ifstream infile(argv[1]); + while (index < argc) { + if (argv[index][0] == '-') { + // the arg starts with - + if (strcmp(argv[index], "-d") == 0) { + daemon_mode = true; - if (!infile) { - cout << "failed opening script" << argv[1] << std::endl; - return 1; - } - - for (string line; getline(infile, line, '\n'); ) { - process_line(line); + } else if (strcmp(argv[index], "-h") == 0) { + usage(); + return 0; + + } else { + PX4_WARN("Unknown/unhandled parameter: %s", argv[index]); + return 1; + } + + } else { + // this is an argument that does not have '-' prefix; treat it like a file name + ifstream infile(argv[index]); + if (infile.is_open()) { + for (string line; getline(infile, line, '\n');) { + process_line(line); + } + + } else { + PX4_WARN("Error opening file: %s", argv[index]); + error_detected = true; + break; + } } + ++index; } - string mystr; - - while(1) { - cout << "Enter a command and its args:" << endl; - getline (cin,mystr); - process_line(mystr); - mystr = ""; + if (!error_detected) { + px4::init_once(); + + px4::init(argc, argv, "mainapp"); + + if (!daemon_mode) { + string mystr; + + while (!_ExitFlag) { + cout << "Enter a command and its args:" << endl; + getline(cin, mystr); + process_line(mystr); + mystr = ""; + } + + } else { + while (!_ExitFlag) { + sleep(1000000); + } + } + + if (px4_task_is_running("muorb")) { + // sending muorb stop is needed if it is running to exit cleanly + vector muorb_stop_cmd = { "muorb", "stop" }; + run_cmd(muorb_stop_cmd); + } + vector shutdown_cmd = { "shutdown" }; + run_cmd(shutdown_cmd); } } diff --git a/src/platforms/posix/px4_layer/px4_posix_tasks.cpp b/src/platforms/posix/px4_layer/px4_posix_tasks.cpp index 44f9ceff88..129709d3d7 100644 --- a/src/platforms/posix/px4_layer/px4_posix_tasks.cpp +++ b/src/platforms/posix/px4_layer/px4_posix_tasks.cpp @@ -280,6 +280,17 @@ void px4_show_tasks() } +bool px4_task_is_running(const char *taskname) +{ + int idx; + for (idx=0; idx < PX4_MAX_TASKS; idx++) + { + if (taskmap[idx].isused && (strcmp(taskmap[idx].name.c_str(), taskname) == 0)) { + return true; + } + } + return false; +} __BEGIN_DECLS unsigned long px4_getpid() diff --git a/src/platforms/px4_tasks.h b/src/platforms/px4_tasks.h index 8dde7cfdd5..941c1ceb37 100644 --- a/src/platforms/px4_tasks.h +++ b/src/platforms/px4_tasks.h @@ -117,5 +117,8 @@ __EXPORT void px4_task_exit(int ret); /** Show a list of running tasks **/ __EXPORT void px4_show_tasks(void); +/** See if a task is running **/ +__EXPORT bool px4_task_is_running(const char *taskname); + __END_DECLS