From 3ed2fafefa2981d9ea720b552ba405dbeae37eca Mon Sep 17 00:00:00 2001 From: Tom Pittenger Date: Thu, 2 Jun 2016 14:00:57 -0700 Subject: [PATCH] DataFlash: Log new CUR2 entry for battery2 data --- libraries/DataFlash/LogFile.cpp | 33 +++++++++++++++++++----------- libraries/DataFlash/LogStructure.h | 12 +++++------ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/libraries/DataFlash/LogFile.cpp b/libraries/DataFlash/LogFile.cpp index 14d77815c1..773e67dfd5 100644 --- a/libraries/DataFlash/LogFile.cpp +++ b/libraries/DataFlash/LogFile.cpp @@ -1640,18 +1640,27 @@ void DataFlash_Class::Log_Write_Attitude(AP_AHRS &ahrs, const Vector3f &targets) // Write an Current data packet void DataFlash_Class::Log_Write_Current(const AP_BattMonitor &battery) { - float voltage2 = battery.voltage2(); - struct log_Current pkt = { - LOG_PACKET_HEADER_INIT(LOG_CURRENT_MSG), - time_us : AP_HAL::micros64(), - throttle : throttle, - battery_voltage : (int16_t) (battery.voltage() * 100.0f), - current_amps : (int16_t) (battery.current_amps() * 100.0f), - board_voltage : (uint16_t)(hal.analogin->board_voltage()*1000), - current_total : battery.current_total_mah(), - battery2_voltage : (int16_t)(voltage2 * 100.0f) - }; - WriteBlock(&pkt, sizeof(pkt)); + if (battery.num_instances() >= 1) { + struct log_Current pkt = { + LOG_PACKET_HEADER_INIT(LOG_CURRENT_MSG), + time_us : AP_HAL::micros64(), + battery_voltage : battery.voltage(0), + current_amps : battery.current_amps(0), + current_total : battery.current_total_mah(0), + }; + WriteBlock(&pkt, sizeof(pkt)); + } + + if (battery.num_instances() >= 2) { + struct log_Current pkt = { + LOG_PACKET_HEADER_INIT(LOG_CURRENT2_MSG), + time_us : AP_HAL::micros64(), + battery_voltage : battery.voltage(1), + current_amps : battery.current_amps(1), + current_total : battery.current_total_mah(1), + }; + WriteBlock(&pkt, sizeof(pkt)); + } } // Write a Compass packet diff --git a/libraries/DataFlash/LogStructure.h b/libraries/DataFlash/LogStructure.h index caf4d5e494..1cd4366bab 100644 --- a/libraries/DataFlash/LogStructure.h +++ b/libraries/DataFlash/LogStructure.h @@ -421,12 +421,9 @@ struct PACKED log_PID { struct PACKED log_Current { LOG_PACKET_HEADER; uint64_t time_us; - int16_t throttle; - int16_t battery_voltage; - int16_t current_amps; - uint16_t board_voltage; + float battery_voltage; + float current_amps; float current_total; - int16_t battery2_voltage; }; struct PACKED log_Compass { @@ -751,7 +748,9 @@ Format characters in the format string for binary log messages { LOG_ARSP_MSG, sizeof(log_AIRSPEED), \ "ARSP", "QffcffB", "TimeUS,Airspeed,DiffPress,Temp,RawPress,Offset,U" }, \ { LOG_CURRENT_MSG, sizeof(log_Current), \ - "CURR", "QhhhHfh","TimeUS,Throttle,Volt,Curr,Vcc,CurrTot,Volt2" },\ + "CURR", "Qfff","TimeUS,Volt,Curr,CurrTot" },\ + { LOG_CURRENT2_MSG, sizeof(log_Current), \ + "CUR2", "Qfff","TimeUS,Volt,Curr,CurrTot" }, \ { LOG_ATTITUDE_MSG, sizeof(log_Attitude),\ "ATT", "QccccCCCC", "TimeUS,DesRoll,Roll,DesPitch,Pitch,DesYaw,Yaw,ErrRP,ErrYaw" }, \ { LOG_COMPASS_MSG, sizeof(log_Compass), \ @@ -945,6 +944,7 @@ enum LogMessages { LOG_ARSP_MSG, LOG_ATTITUDE_MSG, LOG_CURRENT_MSG, + LOG_CURRENT2_MSG, LOG_COMPASS_MSG, LOG_COMPASS2_MSG, LOG_COMPASS3_MSG,