PX4 Firmware
PX4 Autopilot Software http://px4.io
|
#include <batt_smbus.h>
Public Member Functions | |
BATT_SMBUS (SMBus *interface, const char *path) | |
~BATT_SMBUS () | |
int | print_status () override |
int | dataflash_read (uint16_t &address, void *data) |
Reads data from flash. More... | |
int | dataflash_write (uint16_t &address, void *data, const unsigned length) |
Writes data to flash. More... | |
uint16_t | get_serial_number () |
Returns the SBS serial number of the battery device. More... | |
int | get_startup_info () |
Read info from battery on startup. More... | |
int | manufacture_date () |
Gets the SBS manufacture date of the battery. More... | |
int | manufacturer_name (uint8_t *manufacturer_name, const uint8_t length) |
Gets the SBS manufacturer name of the battery device. More... | |
int | manufacturer_read (const uint16_t cmd_code, void *data, const unsigned length) |
Performs a ManufacturerBlockAccess() read command. More... | |
int | manufacturer_write (const uint16_t cmd_code, void *data, const unsigned length) |
Performs a ManufacturerBlockAccess() write command. More... | |
int | unseal () |
Unseals the battery to allow writing to restricted flash. More... | |
int | seal () |
Seals the battery to disallow writing to restricted flash. More... | |
int | lifetime_data_flush () |
This command flushes the RAM Lifetime Data to data flash to help streamline evaluation testing. More... | |
int | lifetime_read_block_one () |
Reads the lifetime data from block 1. More... | |
int | get_cell_voltages () |
Reads the cell voltages. More... | |
void | set_undervoltage_protection (float average_current) |
Enables or disables the cell under voltage protection emergency shut off. More... | |
void | suspend () |
void | resume () |
Static Public Member Functions | |
static int | print_usage () |
static int | custom_command (int argc, char *argv[]) |
static int | task_spawn (int argc, char *argv[]) |
Public Attributes | |
friend | SMBus |
Protected Member Functions | |
void | Run () override |
Private Member Functions | |
BATT_SMBUS (const BATT_SMBUS &)=delete | |
BATT_SMBUS | operator= (const BATT_SMBUS &)=delete |
Private Attributes | |
SMBus * | _interface |
perf_counter_t | _cycle {perf_alloc(PC_ELAPSED, "batt_smbus_cycle")} |
float | _cell_voltages [4] {} |
float | _max_cell_voltage_delta {0} |
float | _min_cell_voltage {0} |
battery_status_s | _last_report {} |
orb_advert_t | _batt_topic {nullptr} |
uint8_t | _cell_count {4} |
uint16_t | _batt_capacity {0} |
uint16_t | _batt_startup_capacity {0} |
uint16_t | _cycle_count {0} |
uint16_t | _serial_number {0} |
float | _crit_thr {0.f} |
float | _emergency_thr {0.f} |
float | _low_thr {0.f} |
char * | _manufacturer_name {nullptr} |
float | _lifetime_max_delta_cell_voltage {0.f} |
uint8_t | _cell_undervoltage_protection_status {1} |
Definition at line 125 of file batt_smbus.h.
BATT_SMBUS::BATT_SMBUS | ( | SMBus * | interface, |
const char * | path | ||
) |
Definition at line 50 of file batt_smbus.cpp.
References _batt_topic, _interface, orb_advertise(), ORB_ID, param_find(), param_set(), and unseal().
Referenced by task_spawn().
BATT_SMBUS::~BATT_SMBUS | ( | ) |
Definition at line 67 of file batt_smbus.cpp.
References _batt_topic, _cycle, _interface, _manufacturer_name, orb_unadvertise(), param_find(), param_set(), and perf_free().
|
privatedelete |
|
static |
Definition at line 571 of file batt_smbus.cpp.
References dataflash_write(), get_serial_number(), is_running(), manufacture_date(), manufacturer_name(), print_usage(), resume(), seal(), suspend(), and unseal().
int BATT_SMBUS::dataflash_read | ( | uint16_t & | address, |
void * | data | ||
) |
Reads data from flash.
address | The address to start the read from. |
data | The returned data. |
Definition at line 342 of file batt_smbus.cpp.
References _interface, BATT_SMBUS_MANUFACTURER_BLOCK_ACCESS, SMBus::block_read(), SMBus::block_write(), and DATA_BUFFER_SIZE.
int BATT_SMBUS::dataflash_write | ( | uint16_t & | address, |
void * | data, | ||
const unsigned | length | ||
) |
Writes data to flash.
address | The start address of the write. |
data | The data to be written. |
length | The number of bytes being written. |
Definition at line 363 of file batt_smbus.cpp.
References _interface, BATT_SMBUS_MANUFACTURER_BLOCK_ACCESS, SMBus::block_write(), and DATA_BUFFER_SIZE.
Referenced by custom_command(), and set_undervoltage_protection().
int BATT_SMBUS::get_cell_voltages | ( | ) |
Reads the cell voltages.
Definition at line 266 of file batt_smbus.cpp.
References _cell_voltages, _interface, _last_report, _max_cell_voltage_delta, _min_cell_voltage, BATT_SMBUS_CELL_1_VOLTAGE, BATT_SMBUS_CELL_2_VOLTAGE, BATT_SMBUS_CELL_3_VOLTAGE, BATT_SMBUS_CELL_4_VOLTAGE, math::max(), battery_status_s::max_cell_voltage_delta, math::min(), and SMBus::read_word().
Referenced by Run().
uint16_t BATT_SMBUS::get_serial_number | ( | ) |
Returns the SBS serial number of the battery device.
Definition at line 440 of file batt_smbus.cpp.
References _interface, BATT_SMBUS_SERIAL_NUMBER, and SMBus::read_word().
Referenced by custom_command().
int BATT_SMBUS::get_startup_info | ( | ) |
Read info from battery on startup.
Definition at line 379 of file batt_smbus.cpp.
References _batt_capacity, _batt_startup_capacity, _crit_thr, _cycle_count, _emergency_thr, _interface, _lifetime_max_delta_cell_voltage, _low_thr, _manufacturer_name, _serial_number, BATT_CELL_VOLTAGE_THRESHOLD_FAILED, BATT_SMBUS_CYCLE_COUNT, BATT_SMBUS_FULL_CHARGE_CAPACITY, BATT_SMBUS_REMAINING_CAPACITY, BATT_SMBUS_SERIAL_NUMBER, lifetime_data_flush(), lifetime_read_block_one(), manufacturer_name(), param_find(), param_get(), and SMBus::read_word().
int BATT_SMBUS::lifetime_data_flush | ( | ) |
This command flushes the RAM Lifetime Data to data flash to help streamline evaluation testing.
Definition at line 546 of file batt_smbus.cpp.
References BATT_SMBUS_LIFETIME_FLUSH, and manufacturer_write().
Referenced by get_startup_info().
int BATT_SMBUS::lifetime_read_block_one | ( | ) |
Reads the lifetime data from block 1.
Definition at line 553 of file batt_smbus.cpp.
References _lifetime_max_delta_cell_voltage, BATT_SMBUS_LIFETIME_BLOCK_ONE, and manufacturer_read().
Referenced by get_startup_info().
int BATT_SMBUS::manufacture_date | ( | ) |
Gets the SBS manufacture date of the battery.
Definition at line 451 of file batt_smbus.cpp.
References _interface, BATT_SMBUS_MANUFACTURE_DATE, and SMBus::read_word().
Referenced by custom_command().
int BATT_SMBUS::manufacturer_name | ( | uint8_t * | manufacturer_name, |
const uint8_t | length | ||
) |
Gets the SBS manufacturer name of the battery device.
manufacturer_name | Pointer to a buffer into which the manufacturer name is to be written. |
max_length | The maximum number of bytes to attempt to read from the manufacturer name register, including the null character that is appended to the end. |
Definition at line 463 of file batt_smbus.cpp.
References _interface, BATT_SMBUS_MANUFACTURER_NAME, and SMBus::block_read().
Referenced by custom_command(), and get_startup_info().
int BATT_SMBUS::manufacturer_read | ( | const uint16_t | cmd_code, |
void * | data, | ||
const unsigned | length | ||
) |
Performs a ManufacturerBlockAccess() read command.
cmd_code | The command code. |
data | The returned data. |
length | The number of bytes being written. |
Definition at line 485 of file batt_smbus.cpp.
References _interface, BATT_SMBUS_MANUFACTURER_BLOCK_ACCESS, SMBus::block_read(), and SMBus::block_write().
Referenced by lifetime_read_block_one().
int BATT_SMBUS::manufacturer_write | ( | const uint16_t | cmd_code, |
void * | data, | ||
const unsigned | length | ||
) |
Performs a ManufacturerBlockAccess() write command.
cmd_code | The command code. |
data | The sent data. |
length | The number of bytes being written. |
Definition at line 506 of file batt_smbus.cpp.
References _interface, BATT_SMBUS_MANUFACTURER_BLOCK_ACCESS, SMBus::block_write(), and DATA_BUFFER_SIZE.
Referenced by lifetime_data_flush(), and seal().
|
privatedelete |
|
override |
Definition at line 478 of file batt_smbus.cpp.
References _last_report.
|
static |
Definition at line 660 of file batt_smbus.cpp.
Referenced by custom_command(), and task_spawn().
void BATT_SMBUS::resume | ( | ) |
Definition at line 261 of file batt_smbus.cpp.
References BATT_SMBUS_MEASUREMENT_INTERVAL_US.
Referenced by custom_command().
|
overrideprotected |
Definition at line 149 of file batt_smbus.cpp.
References _batt_capacity, _batt_startup_capacity, _batt_topic, _cell_count, _cell_voltages, _crit_thr, _cycle_count, _emergency_thr, _interface, _last_report, _lifetime_max_delta_cell_voltage, _low_thr, _serial_number, battery_status_s::average_current_a, battery_status_s::average_time_to_empty, BATT_CELL_VOLTAGE_THRESHOLD_FAILED, BATT_SMBUS_AVERAGE_CURRENT, BATT_SMBUS_AVERAGE_TIME_TO_EMPTY, BATT_SMBUS_CURRENT, BATT_SMBUS_REMAINING_CAPACITY, BATT_SMBUS_RUN_TIME_TO_EMPTY, BATT_SMBUS_TEMP, BATT_SMBUS_VOLTAGE, battery_status_s::capacity, battery_status_s::cell_count, battery_status_s::connected, CONSTANTS_ABSOLUTE_NULL_CELSIUS, battery_status_s::current_a, battery_status_s::current_filtered_a, battery_status_s::cycle_count, battery_status_s::discharged_mah, f(), get_cell_voltages(), hrt_absolute_time(), ORB_ID, orb_publish(), SMBus::read_word(), battery_status_s::remaining, battery_status_s::run_time_to_empty, battery_status_s::serial_number, set_undervoltage_protection(), battery_status_s::temperature, battery_status_s::timestamp, battery_status_s::voltage_cell_v, battery_status_s::voltage_filtered_v, battery_status_s::voltage_v, and battery_status_s::warning.
int BATT_SMBUS::seal | ( | ) |
Seals the battery to disallow writing to restricted flash.
Definition at line 538 of file batt_smbus.cpp.
References BATT_SMBUS_SEAL, and manufacturer_write().
Referenced by custom_command().
void BATT_SMBUS::set_undervoltage_protection | ( | float | average_current | ) |
Enables or disables the cell under voltage protection emergency shut off.
Definition at line 303 of file batt_smbus.cpp.
References _cell_undervoltage_protection_status, _min_cell_voltage, BATT_CURRENT_UNDERVOLTAGE_THRESHOLD, BATT_SMBUS_ENABLED_PROTECTIONS_A_ADDRESS, BATT_SMBUS_ENABLED_PROTECTIONS_A_CUV_DISABLED, BATT_SMBUS_ENABLED_PROTECTIONS_A_DEFAULT, BATT_VOLTAGE_UNDERVOLTAGE_THRESHOLD, and dataflash_write().
Referenced by Run().
void BATT_SMBUS::suspend | ( | ) |
Definition at line 256 of file batt_smbus.cpp.
Referenced by custom_command().
|
static |
Definition at line 84 of file batt_smbus.cpp.
References BATT_SMBUS(), BATT_SMBUS_BUS_ALL, BATT_SMBUS_BUS_I2C_EXTERNAL, BATT_SMBUS_BUS_I2C_EXTERNAL1, BATT_SMBUS_BUS_I2C_EXTERNAL2, BATT_SMBUS_BUS_I2C_INTERNAL, BATT_SMBUS_MEASUREMENT_INTERVAL_US, is_running(), NUM_BUS_OPTIONS, print_usage(), and smbus_bus_options.
int BATT_SMBUS::unseal | ( | ) |
Unseals the battery to allow writing to restricted flash.
Definition at line 526 of file batt_smbus.cpp.
References _interface, BATT_SMBUS_MANUFACTURER_ACCESS, and SMBus::write_word().
Referenced by BATT_SMBUS(), and custom_command().
|
private |
_batt_capacity | Battery design capacity in mAh (0 means unknown). |
Definition at line 273 of file batt_smbus.h.
Referenced by get_startup_info(), and Run().
|
private |
_batt_startup_capacity | Battery remaining capacity in mAh on startup. |
Definition at line 276 of file batt_smbus.h.
Referenced by get_startup_info(), and Run().
|
private |
_batt_topic | uORB battery topic. |
Definition at line 267 of file batt_smbus.h.
Referenced by BATT_SMBUS(), Run(), and ~BATT_SMBUS().
|
private |
_cell_count | Number of series cell. |
Definition at line 270 of file batt_smbus.h.
Referenced by Run().
|
private |
_cell_undervoltage_protection_status | 0 if protection disabled, 1 if enabled |
Definition at line 300 of file batt_smbus.h.
Referenced by set_undervoltage_protection().
|
private |
Definition at line 257 of file batt_smbus.h.
Referenced by get_cell_voltages(), and Run().
|
private |
_crit_thr | Critical battery threshold param. |
Definition at line 285 of file batt_smbus.h.
Referenced by get_startup_info(), and Run().
|
private |
Definition at line 255 of file batt_smbus.h.
Referenced by ~BATT_SMBUS().
|
private |
_cycle_count | The number of cycles the battery has experienced. |
Definition at line 279 of file batt_smbus.h.
Referenced by get_startup_info(), and Run().
|
private |
_emergency_thr | Emergency battery threshold param. |
Definition at line 288 of file batt_smbus.h.
Referenced by get_startup_info(), and Run().
|
private |
Definition at line 253 of file batt_smbus.h.
Referenced by BATT_SMBUS(), dataflash_read(), dataflash_write(), get_cell_voltages(), get_serial_number(), get_startup_info(), manufacture_date(), manufacturer_name(), manufacturer_read(), manufacturer_write(), Run(), unseal(), and ~BATT_SMBUS().
|
private |
_last_report | Last published report, used for test(). |
Definition at line 264 of file batt_smbus.h.
Referenced by get_cell_voltages(), print_status(), and Run().
|
private |
_lifetime_max_delta_cell_voltage | Max lifetime delta of the battery cells |
Definition at line 297 of file batt_smbus.h.
Referenced by get_startup_info(), lifetime_read_block_one(), and Run().
|
private |
_low_thr | Low battery threshold param. |
Definition at line 291 of file batt_smbus.h.
Referenced by get_startup_info(), and Run().
|
private |
_manufacturer_name | Name of the battery manufacturer. |
Definition at line 294 of file batt_smbus.h.
Referenced by get_startup_info(), and ~BATT_SMBUS().
|
private |
Definition at line 259 of file batt_smbus.h.
Referenced by get_cell_voltages().
|
private |
Definition at line 261 of file batt_smbus.h.
Referenced by get_cell_voltages(), and set_undervoltage_protection().
|
private |
_serial_number | Serial number register. |
Definition at line 282 of file batt_smbus.h.
Referenced by get_startup_info(), and Run().
friend BATT_SMBUS::SMBus |
Definition at line 133 of file batt_smbus.h.