mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-01 02:55:07 +08:00
POSIX: Fix for daemon mode to process commands after init
Commands were being processed before init was called. Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
@@ -120,6 +120,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
int index = 1;
|
int index = 1;
|
||||||
bool error_detected = false;
|
bool error_detected = false;
|
||||||
|
char *commands_file = nullptr;
|
||||||
|
|
||||||
while (index < argc) {
|
while (index < argc) {
|
||||||
if (argv[index][0] == '-') {
|
if (argv[index][0] == '-') {
|
||||||
@@ -139,10 +140,10 @@ int main(int argc, char **argv)
|
|||||||
} else {
|
} else {
|
||||||
// this is an argument that does not have '-' prefix; treat it like a file name
|
// this is an argument that does not have '-' prefix; treat it like a file name
|
||||||
ifstream infile(argv[index]);
|
ifstream infile(argv[index]);
|
||||||
if (infile.is_open()) {
|
|
||||||
for (string line; getline(infile, line, '\n');) {
|
if (infile.good()) {
|
||||||
process_line(line);
|
infile.close();
|
||||||
}
|
commands_file = argv[index];
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
PX4_WARN("Error opening file: %s", argv[index]);
|
PX4_WARN("Error opening file: %s", argv[index]);
|
||||||
@@ -150,6 +151,7 @@ int main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,6 +160,20 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
px4::init(argc, argv, "mainapp");
|
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) {
|
if (!daemon_mode) {
|
||||||
string mystr;
|
string mystr;
|
||||||
|
|
||||||
@@ -179,6 +195,7 @@ int main(int argc, char **argv)
|
|||||||
vector<string> muorb_stop_cmd = { "muorb", "stop" };
|
vector<string> muorb_stop_cmd = { "muorb", "stop" };
|
||||||
run_cmd(muorb_stop_cmd);
|
run_cmd(muorb_stop_cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> shutdown_cmd = { "shutdown" };
|
vector<string> shutdown_cmd = { "shutdown" };
|
||||||
run_cmd(shutdown_cmd);
|
run_cmd(shutdown_cmd);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user