AP_BattMonitor: print unhealthy message if battery backend not as expected

a backend which fails to allocate, or where the user has changed the backend type without rebooting will cause an "unhealthy" message to be emitted
This commit is contained in:
Peter Barker 2024-09-26 11:36:25 +10:00 committed by Andrew Tridgell
parent 4b5f490e9f
commit 721a9b846e
1 changed files with 13 additions and 2 deletions

View File

@ -1019,8 +1019,19 @@ bool AP_BattMonitor::arming_checks(size_t buflen, char *buffer) const
{
char temp_buffer[MAVLINK_MSG_STATUSTEXT_FIELD_TEXT_LEN+1] {};
for (uint8_t i = 0; i < _num_instances; i++) {
if (drivers[i] != nullptr && !(drivers[i]->arming_checks(temp_buffer, sizeof(temp_buffer)))) {
for (uint8_t i = 0; i < AP_BATT_MONITOR_MAX_INSTANCES; i++) {
const auto expected_type = configured_type(i);
if (drivers[i] == nullptr && expected_type == Type::NONE) {
continue;
}
if (drivers[i] == nullptr || allocated_type(i) != expected_type) {
hal.util->snprintf(buffer, buflen, "Battery %d %s", i + 1, "unhealthy");
return false;
}
if (!drivers[i]->arming_checks(temp_buffer, sizeof(temp_buffer))) {
hal.util->snprintf(buffer, buflen, "Battery %d %s", i + 1, temp_buffer);
return false;
}