From 2579b29691fbb5d3b31ae1f84ef3329f4e95a86a Mon Sep 17 00:00:00 2001 From: Mark Charlebois Date: Sun, 30 Aug 2015 00:18:41 -0700 Subject: [PATCH] POSIX: Fix for daemon mode to process commands after init Commands were being processed before init was called. Signed-off-by: Mark Charlebois --- src/platforms/posix/main.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/platforms/posix/main.cpp b/src/platforms/posix/main.cpp index dbc4b7cc3f..1c34b281af 100644 --- a/src/platforms/posix/main.cpp +++ b/src/platforms/posix/main.cpp @@ -120,6 +120,7 @@ int main(int argc, char **argv) int index = 1; bool error_detected = false; + char *commands_file = nullptr; while (index < argc) { if (argv[index][0] == '-') { @@ -139,10 +140,10 @@ int main(int argc, char **argv) } 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); - } + + if (infile.good()) { + infile.close(); + commands_file = argv[index]; } else { PX4_WARN("Error opening file: %s", argv[index]); @@ -150,6 +151,7 @@ int main(int argc, char **argv) break; } } + ++index; } @@ -158,6 +160,20 @@ int main(int argc, char **argv) px4::init(argc, argv, "mainapp"); + //if commandfile is present, process the commands from the file + if (commands_file != nullptr) { + ifstream infile(commands_file); + + if (infile.is_open()) { + for (string line; getline(infile, line, '\n');) { + process_line(line); + } + + } else { + PX4_WARN("Error opening file: %s", commands_file); + } + } + if (!daemon_mode) { string mystr; @@ -179,6 +195,7 @@ int main(int argc, char **argv) vector muorb_stop_cmd = { "muorb", "stop" }; run_cmd(muorb_stop_cmd); } + vector shutdown_cmd = { "shutdown" }; run_cmd(shutdown_cmd); }