From ba10c0ae42beb6d003c6dbe953b1f159670a31d4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 22 Jun 2022 19:32:31 +1000 Subject: [PATCH] AP_BattMonitor: make healthy() check all configured monitors GCS reporting for SYS_STATUS should check all healthy, not just first backend --- libraries/AP_BattMonitor/AP_BattMonitor.cpp | 13 +++++++++++++ libraries/AP_BattMonitor/AP_BattMonitor.h | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libraries/AP_BattMonitor/AP_BattMonitor.cpp b/libraries/AP_BattMonitor/AP_BattMonitor.cpp index 1045f7ff41..c73950f767 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor.cpp +++ b/libraries/AP_BattMonitor/AP_BattMonitor.cpp @@ -740,6 +740,19 @@ uint32_t AP_BattMonitor::get_mavlink_fault_bitmask(const uint8_t instance) const return drivers[instance]->get_mavlink_fault_bitmask(); } +/* + check that all configured battery monitors are healthy + */ +bool AP_BattMonitor::healthy() const +{ + for (uint8_t i=0; i< _num_instances; i++) { + if (get_type(i) != Type::NONE && !healthy(i)) { + return false; + } + } + return true; +} + namespace AP { AP_BattMonitor &battery() diff --git a/libraries/AP_BattMonitor/AP_BattMonitor.h b/libraries/AP_BattMonitor/AP_BattMonitor.h index cd362215f5..5702183d32 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor.h +++ b/libraries/AP_BattMonitor/AP_BattMonitor.h @@ -156,7 +156,9 @@ public: // healthy - returns true if monitor is functioning bool healthy(uint8_t instance) const; - bool healthy() const { return healthy(AP_BATT_PRIMARY_INSTANCE); } + + // return true if all configured battery monitors are healthy + bool healthy() const; /// voltage - returns battery voltage in volts float voltage(uint8_t instance) const;