From 9cb0d8f99b04320e1c70dc287ad8499b7d898241 Mon Sep 17 00:00:00 2001 From: Michael du Breuil Date: Fri, 7 Apr 2017 20:28:14 -0700 Subject: [PATCH] GCS_MAVlink: Add battery cell backend --- libraries/GCS_MAVLink/GCS_Common.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/libraries/GCS_MAVLink/GCS_Common.cpp b/libraries/GCS_MAVLink/GCS_Common.cpp index de6c3ce756..b91769264c 100644 --- a/libraries/GCS_MAVLink/GCS_Common.cpp +++ b/libraries/GCS_MAVLink/GCS_Common.cpp @@ -236,14 +236,16 @@ void GCS_MAVLINK::send_power_status(void) void GCS_MAVLINK::send_battery_status(const AP_BattMonitor &battery, const uint8_t instance) const { - uint16_t voltages[MAVLINK_MSG_BATTERY_STATUS_FIELD_VOLTAGES_LEN]; - memset(&voltages, 0xff, sizeof(uint16_t)*MAVLINK_MSG_BATTERY_STATUS_FIELD_VOLTAGES_LEN); // fill with UINT16_MAX for unknown cells + // catch the battery backend not supporting the required number of cells + static_assert(sizeof(AP_BattMonitor::cells) >= (sizeof(uint16_t) * MAVLINK_MSG_BATTERY_STATUS_FIELD_VOLTAGES_LEN), + "Not enough battery cells for the MAVLink message"); + mavlink_msg_battery_status_send(chan, instance, // id MAV_BATTERY_FUNCTION_UNKNOWN, // function MAV_BATTERY_TYPE_UNKNOWN, // type INT16_MAX, // temperature. INT16_MAX if unknown - voltages, + battery.get_cell_voltages(instance).cells, // cell voltages battery.has_current(instance) ? battery.current_amps(instance) * 100 : -1, // current battery.has_current(instance) ? battery.current_total_mah(instance) : -1, // total current -1, // joules used