PX4 Firmware
PX4 Autopilot Software http://px4.io
BATT_SMBUS Class Reference

#include <batt_smbus.h>

Inheritance diagram for BATT_SMBUS:
Collaboration diagram for BATT_SMBUS:

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}
 

Detailed Description

Definition at line 125 of file batt_smbus.h.

Constructor & Destructor Documentation

◆ BATT_SMBUS() [1/2]

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~BATT_SMBUS()

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().

Here is the call graph for this function:

◆ BATT_SMBUS() [2/2]

BATT_SMBUS::BATT_SMBUS ( const BATT_SMBUS )
privatedelete

Member Function Documentation

◆ custom_command()

int BATT_SMBUS::custom_command ( int  argc,
char *  argv[] 
)
static
See also
ModuleBase

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().

Here is the call graph for this function:

◆ dataflash_read()

int BATT_SMBUS::dataflash_read ( uint16_t &  address,
void *  data 
)

Reads data from flash.

Parameters
addressThe address to start the read from.
dataThe returned data.
Returns
Returns PX4_OK on success, PX4_ERROR on failure.

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.

Here is the call graph for this function:

◆ dataflash_write()

int BATT_SMBUS::dataflash_write ( uint16_t &  address,
void *  data,
const unsigned  length 
)

Writes data to flash.

Parameters
addressThe start address of the write.
dataThe data to be written.
lengthThe number of bytes being written.
Returns
Returns PX4_OK on success, PX4_ERROR on failure.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_cell_voltages()

int BATT_SMBUS::get_cell_voltages ( )

Reads the cell voltages.

Returns
Returns PX4_OK on success or associated read error code on failure.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_serial_number()

uint16_t BATT_SMBUS::get_serial_number ( )

Returns the SBS serial number of the battery device.

Returns
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_startup_info()

int BATT_SMBUS::get_startup_info ( )

Read info from battery on startup.

Returns
Returns PX4_OK on success, PX4_ERROR on failure.

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().

Here is the call graph for this function:

◆ lifetime_data_flush()

int BATT_SMBUS::lifetime_data_flush ( )

This command flushes the RAM Lifetime Data to data flash to help streamline evaluation testing.

Returns
Returns PX4_OK on success, PX4_ERROR on failure.

Definition at line 546 of file batt_smbus.cpp.

References BATT_SMBUS_LIFETIME_FLUSH, and manufacturer_write().

Referenced by get_startup_info().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lifetime_read_block_one()

int BATT_SMBUS::lifetime_read_block_one ( )

Reads the lifetime data from block 1.

Returns
Returns PX4_OK on success, PX4_ERROR on failure.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ manufacture_date()

int BATT_SMBUS::manufacture_date ( )

Gets the SBS manufacture date of the battery.

Returns
Returns PX4_OK on success, PX4_ERROR on failure.

Definition at line 451 of file batt_smbus.cpp.

References _interface, BATT_SMBUS_MANUFACTURE_DATE, and SMBus::read_word().

Referenced by custom_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ manufacturer_name()

int BATT_SMBUS::manufacturer_name ( uint8_t *  manufacturer_name,
const uint8_t  length 
)

Gets the SBS manufacturer name of the battery device.

Parameters
manufacturer_namePointer to a buffer into which the manufacturer name is to be written.
max_lengthThe maximum number of bytes to attempt to read from the manufacturer name register, including the null character that is appended to the end.
Returns
Returns PX4_OK on success, PX4_ERROR on failure.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ manufacturer_read()

int BATT_SMBUS::manufacturer_read ( const uint16_t  cmd_code,
void *  data,
const unsigned  length 
)

Performs a ManufacturerBlockAccess() read command.

Parameters
cmd_codeThe command code.
dataThe returned data.
lengthThe number of bytes being written.
Returns
Returns PX4_OK on success, PX4_ERROR on failure.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ manufacturer_write()

int BATT_SMBUS::manufacturer_write ( const uint16_t  cmd_code,
void *  data,
const unsigned  length 
)

Performs a ManufacturerBlockAccess() write command.

Parameters
cmd_codeThe command code.
dataThe sent data.
lengthThe number of bytes being written.
Returns
Returns PX4_OK on success, PX4_ERROR on failure.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

BATT_SMBUS BATT_SMBUS::operator= ( const BATT_SMBUS )
privatedelete

◆ print_status()

int BATT_SMBUS::print_status ( )
override
See also
ModuleBase::print_status()

Definition at line 478 of file batt_smbus.cpp.

References _last_report.

◆ print_usage()

int BATT_SMBUS::print_usage ( )
static
See also
ModuleBase

Definition at line 660 of file batt_smbus.cpp.

Referenced by custom_command(), and task_spawn().

Here is the caller graph for this function:

◆ resume()

void BATT_SMBUS::resume ( )

Definition at line 261 of file batt_smbus.cpp.

References BATT_SMBUS_MEASUREMENT_INTERVAL_US.

Referenced by custom_command().

Here is the caller graph for this function:

◆ Run()

◆ seal()

int BATT_SMBUS::seal ( )

Seals the battery to disallow writing to restricted flash.

Returns
Returns PX4_OK on success, PX4_ERROR on failure.

Definition at line 538 of file batt_smbus.cpp.

References BATT_SMBUS_SEAL, and manufacturer_write().

Referenced by custom_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_undervoltage_protection()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ suspend()

void BATT_SMBUS::suspend ( )

Definition at line 256 of file batt_smbus.cpp.

Referenced by custom_command().

Here is the caller graph for this function:

◆ task_spawn()

int BATT_SMBUS::task_spawn ( int  argc,
char *  argv[] 
)
static
See also
ModuleBase

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.

Here is the call graph for this function:

◆ unseal()

int BATT_SMBUS::unseal ( )

Unseals the battery to allow writing to restricted flash.

Returns
Returns PX4_OK on success, PX4_ERROR on failure.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _batt_capacity

uint16_t BATT_SMBUS::_batt_capacity {0}
private
Parameters
_batt_capacityBattery design capacity in mAh (0 means unknown).

Definition at line 273 of file batt_smbus.h.

Referenced by get_startup_info(), and Run().

◆ _batt_startup_capacity

uint16_t BATT_SMBUS::_batt_startup_capacity {0}
private
Parameters
_batt_startup_capacityBattery remaining capacity in mAh on startup.

Definition at line 276 of file batt_smbus.h.

Referenced by get_startup_info(), and Run().

◆ _batt_topic

orb_advert_t BATT_SMBUS::_batt_topic {nullptr}
private
Parameters
_batt_topicuORB battery topic.

Definition at line 267 of file batt_smbus.h.

Referenced by BATT_SMBUS(), Run(), and ~BATT_SMBUS().

◆ _cell_count

uint8_t BATT_SMBUS::_cell_count {4}
private
Parameters
_cell_countNumber of series cell.

Definition at line 270 of file batt_smbus.h.

Referenced by Run().

◆ _cell_undervoltage_protection_status

uint8_t BATT_SMBUS::_cell_undervoltage_protection_status {1}
private
Parameters
_cell_undervoltage_protection_status0 if protection disabled, 1 if enabled

Definition at line 300 of file batt_smbus.h.

Referenced by set_undervoltage_protection().

◆ _cell_voltages

float BATT_SMBUS::_cell_voltages[4] {}
private

Definition at line 257 of file batt_smbus.h.

Referenced by get_cell_voltages(), and Run().

◆ _crit_thr

float BATT_SMBUS::_crit_thr {0.f}
private
Parameters
_crit_thrCritical battery threshold param.

Definition at line 285 of file batt_smbus.h.

Referenced by get_startup_info(), and Run().

◆ _cycle

perf_counter_t BATT_SMBUS::_cycle {perf_alloc(PC_ELAPSED, "batt_smbus_cycle")}
private

Definition at line 255 of file batt_smbus.h.

Referenced by ~BATT_SMBUS().

◆ _cycle_count

uint16_t BATT_SMBUS::_cycle_count {0}
private
Parameters
_cycle_countThe number of cycles the battery has experienced.

Definition at line 279 of file batt_smbus.h.

Referenced by get_startup_info(), and Run().

◆ _emergency_thr

float BATT_SMBUS::_emergency_thr {0.f}
private
Parameters
_emergency_thrEmergency battery threshold param.

Definition at line 288 of file batt_smbus.h.

Referenced by get_startup_info(), and Run().

◆ _interface

◆ _last_report

battery_status_s BATT_SMBUS::_last_report {}
private
Parameters
_last_reportLast published report, used for test().

Definition at line 264 of file batt_smbus.h.

Referenced by get_cell_voltages(), print_status(), and Run().

◆ _lifetime_max_delta_cell_voltage

float BATT_SMBUS::_lifetime_max_delta_cell_voltage {0.f}
private
Parameters
_lifetime_max_delta_cell_voltageMax 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().

◆ _low_thr

float BATT_SMBUS::_low_thr {0.f}
private
Parameters
_low_thrLow battery threshold param.

Definition at line 291 of file batt_smbus.h.

Referenced by get_startup_info(), and Run().

◆ _manufacturer_name

char* BATT_SMBUS::_manufacturer_name {nullptr}
private
Parameters
_manufacturer_nameName of the battery manufacturer.

Definition at line 294 of file batt_smbus.h.

Referenced by get_startup_info(), and ~BATT_SMBUS().

◆ _max_cell_voltage_delta

float BATT_SMBUS::_max_cell_voltage_delta {0}
private

Definition at line 259 of file batt_smbus.h.

Referenced by get_cell_voltages().

◆ _min_cell_voltage

float BATT_SMBUS::_min_cell_voltage {0}
private

Definition at line 261 of file batt_smbus.h.

Referenced by get_cell_voltages(), and set_undervoltage_protection().

◆ _serial_number

uint16_t BATT_SMBUS::_serial_number {0}
private
Parameters
_serial_numberSerial number register.

Definition at line 282 of file batt_smbus.h.

Referenced by get_startup_info(), and Run().

◆ SMBus

friend BATT_SMBUS::SMBus

Definition at line 133 of file batt_smbus.h.


The documentation for this class was generated from the following files: