48 #include <mathlib/mathlib.h> 50 #include <px4_platform_common/module.h> 51 #include <px4_platform_common/getopt.h> 52 #include <px4_platform_common/px4_work_queue/ScheduledWorkItem.hpp> 55 #include "board_config.h" 57 #define DATA_BUFFER_SIZE 32 59 #define BATT_CELL_VOLTAGE_THRESHOLD_RTL 0.5f 60 #define BATT_CELL_VOLTAGE_THRESHOLD_FAILED 1.5f
62 #define BATT_CURRENT_UNDERVOLTAGE_THRESHOLD 5.0f 63 #define BATT_VOLTAGE_UNDERVOLTAGE_THRESHOLD 3.4f
65 #define BATT_SMBUS_ADDR 0x0B 67 #define BATT_SMBUS_CURRENT 0x0A 68 #define BATT_SMBUS_AVERAGE_CURRENT 0x0B
69 #define BATT_SMBUS_TEMP 0x08
70 #define BATT_SMBUS_VOLTAGE 0x09
71 #define BATT_SMBUS_FULL_CHARGE_CAPACITY 0x10
72 #define BATT_SMBUS_RUN_TIME_TO_EMPTY 0x11
73 #define BATT_SMBUS_AVERAGE_TIME_TO_EMPTY 0x12
74 #define BATT_SMBUS_REMAINING_CAPACITY 0x0F
75 #define BATT_SMBUS_CYCLE_COUNT 0x17
76 #define BATT_SMBUS_DESIGN_CAPACITY 0x18
77 #define BATT_SMBUS_DESIGN_VOLTAGE 0x19
78 #define BATT_SMBUS_MANUFACTURER_NAME 0x20
79 #define BATT_SMBUS_MANUFACTURE_DATE 0x1B
80 #define BATT_SMBUS_SERIAL_NUMBER 0x1C
81 #define BATT_SMBUS_MEASUREMENT_INTERVAL_US 100000
82 #define BATT_SMBUS_MANUFACTURER_ACCESS 0x00
83 #define BATT_SMBUS_MANUFACTURER_DATA 0x23 84 #define BATT_SMBUS_MANUFACTURER_BLOCK_ACCESS 0x44 85 #define BATT_SMBUS_SECURITY_KEYS 0x0035 86 #define BATT_SMBUS_CELL_1_VOLTAGE 0x3F 87 #define BATT_SMBUS_CELL_2_VOLTAGE 0x3E 88 #define BATT_SMBUS_CELL_3_VOLTAGE 0x3D 89 #define BATT_SMBUS_CELL_4_VOLTAGE 0x3C 90 #define BATT_SMBUS_LIFETIME_FLUSH 0x002E 91 #define BATT_SMBUS_LIFETIME_BLOCK_ONE 0x0060 92 #define BATT_SMBUS_ENABLED_PROTECTIONS_A_ADDRESS 0x4938 93 #define BATT_SMBUS_SEAL 0x0030 95 #define BATT_SMBUS_ENABLED_PROTECTIONS_A_DEFAULT 0xcf 96 #define BATT_SMBUS_ENABLED_PROTECTIONS_A_CUV_DISABLED 0xce 98 #define NUM_BUS_OPTIONS (sizeof(smbus_bus_options)/sizeof(smbus_bus_options[0])) 114 #ifdef PX4_I2C_BUS_EXPANSION1 117 #ifdef PX4_I2C_BUS_EXPANSION2 120 #ifdef PX4_I2C_BUS_ONBOARD 125 class BATT_SMBUS :
public ModuleBase<BATT_SMBUS>,
public px4::ScheduledWorkItem
139 static int custom_command(
int argc,
char *argv[]);
142 static int task_spawn(
int argc,
char *argv[]);
153 int dataflash_read(uint16_t &address,
void *
data);
162 int dataflash_write(uint16_t &address,
void *
data,
const unsigned length);
168 uint16_t get_serial_number();
174 int get_startup_info();
180 int manufacture_date();
189 int manufacturer_name(uint8_t *manufacturer_name,
const uint8_t length);
198 int manufacturer_read(
const uint16_t cmd_code,
void *
data,
const unsigned length);
207 int manufacturer_write(
const uint16_t cmd_code,
void *
data,
const unsigned length);
225 int lifetime_data_flush();
231 int lifetime_read_block_one();
237 int get_cell_voltages();
242 void set_undervoltage_protection(
float average_current);
257 float _cell_voltages[4] {};
259 float _max_cell_voltage_delta{0};
261 float _min_cell_voltage{0};
270 uint8_t _cell_count{4};
273 uint16_t _batt_capacity{0};
276 uint16_t _batt_startup_capacity{0};
279 uint16_t _cycle_count{0};
282 uint16_t _serial_number{0};
285 float _crit_thr{0.f};
288 float _emergency_thr{0.f};
294 char *_manufacturer_name{
nullptr};
297 float _lifetime_max_delta_cell_voltage{0.f};
300 uint8_t _cell_undervoltage_protection_status{1};
measure the time elapsed performing an event
Definition of geo / math functions to perform geodesic calculations.
static void print_usage()
SMBus v2.0 protocol implementation.
struct batt_smbus_bus_option smbus_bus_options[]
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
enum BATT_SMBUS_BUS busid
Performance measuring tools.