From f5a8561fde0a8b1756924385dd60fe883cb99830 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 3 Aug 2022 15:15:43 +1000 Subject: [PATCH] AP_Arming: display 'Arm: ' instead of 'PreArm: ' for arming failures Before this patch we would display PreArm: even if the checks were being performed as part of the arming sequence. This lets us distinguish betwee checks failing because the user is trying to arm the vehicle and when the prearms are running while disarmed (or triggered via GCS) --- libraries/AP_Arming/AP_Arming.cpp | 26 ++++++++++++++++++++++++-- libraries/AP_Arming/AP_Arming.h | 1 + 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/libraries/AP_Arming/AP_Arming.cpp b/libraries/AP_Arming/AP_Arming.cpp index 7824bce6ad..3d0beddb16 100644 --- a/libraries/AP_Arming/AP_Arming.cpp +++ b/libraries/AP_Arming/AP_Arming.cpp @@ -215,7 +215,16 @@ void AP_Arming::check_failed(const enum AP_Arming::ArmingChecks check, bool repo return; } char taggedfmt[MAVLINK_MSG_STATUSTEXT_FIELD_TEXT_LEN+1]; - hal.util->snprintf(taggedfmt, sizeof(taggedfmt), "PreArm: %s", fmt); + + // metafmt is wrapped around the passed-in format string to + // prepend "PreArm" or "Arm", depending on what sorts of checks + // we're currently doing. + const char *metafmt = "PreArm: %s"; // it's formats all the way down + if (running_arming_checks) { + metafmt = "Arm: %s"; + } + hal.util->snprintf(taggedfmt, sizeof(taggedfmt), metafmt, fmt); + MAV_SEVERITY severity = check_severity(check); va_list arg_list; va_start(arg_list, fmt); @@ -229,7 +238,16 @@ void AP_Arming::check_failed(bool report, const char *fmt, ...) const return; } char taggedfmt[MAVLINK_MSG_STATUSTEXT_FIELD_TEXT_LEN+1]; - hal.util->snprintf(taggedfmt, sizeof(taggedfmt), "PreArm: %s", fmt); + + // metafmt is wrapped around the passed-in format string to + // prepend "PreArm" or "Arm", depending on what sorts of checks + // we're currently doing. + const char *metafmt = "PreArm: %s"; // it's formats all the way down + if (running_arming_checks) { + metafmt = "Arm: %s"; + } + hal.util->snprintf(taggedfmt, sizeof(taggedfmt), metafmt, fmt); + va_list arg_list; va_start(arg_list, fmt); gcs().send_textv(MAV_SEVERITY_CRITICAL, taggedfmt, arg_list); @@ -1426,6 +1444,8 @@ bool AP_Arming::arm(AP_Arming::Method method, const bool do_arming_checks) return false; } + running_arming_checks = true; // so we show Arm: rather than Disarm: in messages + if ((!do_arming_checks && mandatory_checks(true)) || (pre_arm_checks(true) && arm_checks(method))) { armed = true; @@ -1436,6 +1456,8 @@ bool AP_Arming::arm(AP_Arming::Method method, const bool do_arming_checks) armed = false; } + running_arming_checks = false; + if (armed && do_arming_checks && checks_to_perform == 0) { gcs().send_text(MAV_SEVERITY_WARNING, "Warning: Arming Checks Disabled"); } diff --git a/libraries/AP_Arming/AP_Arming.h b/libraries/AP_Arming/AP_Arming.h index 8aeaf39cc7..e2569b6dee 100644 --- a/libraries/AP_Arming/AP_Arming.h +++ b/libraries/AP_Arming/AP_Arming.h @@ -261,6 +261,7 @@ private: Method _last_disarm_method = Method::UNKNOWN; uint32_t last_prearm_display_ms; // last time we send statustexts for prearm failures + bool running_arming_checks; // true if the arming checks currently being performed are being done because the vehicle is trying to arm the vehicle }; namespace AP {