From a716b105f545188b79a3e552f23cad864d1c1821 Mon Sep 17 00:00:00 2001 From: zthorson Date: Tue, 28 Feb 2017 20:13:01 -0800 Subject: [PATCH] px4fmu-v4: Only close down fmu drivers on reset if they weren't running Signed-off-by: zthorson --- src/drivers/px4fmu/fmu.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/drivers/px4fmu/fmu.cpp b/src/drivers/px4fmu/fmu.cpp index 3cee284a2d..2979af4bf0 100644 --- a/src/drivers/px4fmu/fmu.cpp +++ b/src/drivers/px4fmu/fmu.cpp @@ -3273,6 +3273,7 @@ fmu_main(int argc, char *argv[]) { PortMode new_mode = PORT_MODE_UNSET; const char *verb = argv[1]; + bool fmu_was_running = false; if (!strcmp(verb, "bind")) { bind_spektrum(); @@ -3302,6 +3303,8 @@ fmu_main(int argc, char *argv[]) errx(0, "FMU driver stopped"); } + fmu_was_running = (g_fmu != nullptr); + if (fmu_start() != OK) { errx(1, "failed to start the FMU driver"); } @@ -3396,10 +3399,12 @@ fmu_main(int argc, char *argv[]) warnx("resettet default time"); } - // When we are done resetting, we should clean up the fmu drivers - // Failure to do so prevents other devices (HIL sim driver) - // from starting. - fmu_stop(); + // When we are done resetting, we should clean up the fmu drivers if they + // weren't active at the beginning of the reset. + // Failure to do so prevents other devices (HIL sim driver) from starting + if (!fmu_was_running) { + fmu_stop(); + } exit(0); } @@ -3413,10 +3418,12 @@ fmu_main(int argc, char *argv[]) warnx("resettet default time"); } - // When we are done resetting, we should clean up the fmu drivers - // Failure to do so prevents other devices (HIL sim driver) - // from starting. - fmu_stop(); + // When we are done resetting, we should clean up the fmu drivers if they + // weren't active at the beginning of the reset. + // Failure to do so prevents other devices (HIL sim driver) from starting + if (!fmu_was_running) { + fmu_stop(); + } exit(0); }