Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_BattMonitor/AP_BattMonitor_Logging.cpp
Views: 1798
#include "AP_BattMonitor_config.h"1#include <AP_Logger/AP_Logger_config.h>23#if AP_BATTERY_ENABLED && HAL_LOGGING_ENABLED45#include "AP_BattMonitor_Backend.h"6#include <AP_Logger/AP_Logger.h>78extern const AP_HAL::HAL& hal;910// Write BAT data packet(s)11void AP_BattMonitor_Backend::Log_Write_BAT(const uint8_t instance, const uint64_t time_us) const12{13bool has_curr = has_current();14uint8_t percent = -1;15IGNORE_RETURN(capacity_remaining_pct(percent));1617float temperature;18int16_t temperature_cd = 0;19if (get_temperature(temperature)) {20temperature_cd = temperature * 100.0;21}2223uint8_t soh_pct = 0;24IGNORE_RETURN(get_state_of_health_pct(soh_pct));2526const struct log_BAT pkt{27LOG_PACKET_HEADER_INIT(LOG_BAT_MSG),28time_us : time_us,29instance : instance,30voltage : _state.voltage,31voltage_resting : _state.voltage_resting_estimate,32current_amps : has_curr ? _state.current_amps : AP::logger().quiet_nanf(),33current_total : has_curr ? _state.consumed_mah : AP::logger().quiet_nanf(),34consumed_wh : has_curr ? _state.consumed_wh : AP::logger().quiet_nanf(),35temperature : temperature_cd,36resistance : _state.resistance,37rem_percent : percent,38health : _state.healthy,39state_of_health_pct : soh_pct40};41AP::logger().WriteBlock(&pkt, sizeof(pkt));42}4344// Write BCL data packet if has_cell_voltages45void AP_BattMonitor_Backend::Log_Write_BCL(const uint8_t instance, const uint64_t time_us) const46{47if (!has_cell_voltages()) {48return;49}5051struct log_BCL cell_pkt{52LOG_PACKET_HEADER_INIT(LOG_BCL_MSG),53time_us : time_us,54instance : instance,55voltage : _state.voltage56};5758// we pack the entire BCL message - we must have at least that59// many supported cells or the loop below will over-read60static_assert(ARRAY_SIZE(_state.cell_voltages.cells) >= ARRAY_SIZE(cell_pkt.cell_voltages), "must have at least ARRAY_SIZE(log_BCL.cell_voltages) cells");6162for (uint8_t i = 0; i < ARRAY_SIZE(cell_pkt.cell_voltages); i++) {63cell_pkt.cell_voltages[i] = _state.cell_voltages.cells[i] + 1; // add 1mv64}65AP::logger().WriteBlock(&cell_pkt, sizeof(cell_pkt));6667#if AP_BATT_MONITOR_CELLS_MAX > 1268if (_state.cell_voltages.cells[12] != UINT16_MAX || _state.cell_voltages.cells[13] != UINT16_MAX)69{70// @LoggerMessage: BCL271// @Description: Battery cell voltage information72// @Field: TimeUS: Time since system startup73// @Field: Instance: battery instance number74// @Field: V13: thirteenth cell voltage75// @Field: V14: fourteenth cell voltage76AP::logger().WriteStreaming(77"BCL2",78"TimeUS,Instance,V13,V14",79"s#vv",80"F-CC",81"QBHH",82time_us,83instance,84_state.cell_voltages.cells[ARRAY_SIZE(cell_pkt.cell_voltages)+0] + 1, // add 1mv85_state.cell_voltages.cells[ARRAY_SIZE(cell_pkt.cell_voltages)+1] + 1 // add 1mv86);87}88#endif89}9091#endif // AP_BATTERY_ENABLED && HAL_LOGGING_ENABLED929394