3 #define AP_BATTMONITOR_SMBUS_PEC_POLYNOME 0x07 // Polynome for CRC generation 106 uint8_t buff[read_size];
116 if (pec != buff[2]) {
122 data = (uint16_t)buff[1]<<8 | (uint16_t)buff[0];
137 uint8_t tmp_buff[len+3];
138 tmp_buff[0] = i2c_addr << 1;
140 tmp_buff[2] = tmp_buff[0] | (uint8_t)reading;
141 memcpy(&tmp_buff[3],buff,len);
145 uint8_t shift_reg = 0;
149 for (uint8_t i=0; i<
sizeof(tmp_buff); i++) {
151 shift_reg = tmp_buff[i];
153 for (uint8_t j=0; j<8; j++) {
154 do_invert = (crc ^ shift_reg) & 0x80;
virtual Device::PeriodicHandle register_periodic_callback(uint32_t period_usec, Device::PeriodicCb) override=0
#define AP_BATTMONITOR_SMBUS_PEC_POLYNOME
virtual void timer(void)=0
AP_BattMonitor_SMBus(AP_BattMonitor &mon, AP_BattMonitor::BattMonitor_State &mon_state, AP_BattMonitor_Params ¶ms, AP_HAL::OwnPtr< AP_HAL::I2CDevice > dev)
Constructor.
uint16_t _full_charge_capacity
#define AP_BATTMONITOR_SMBUS_I2C_ADDR
bool read_word(uint8_t reg, uint16_t &data) const
AP_BattMonitor_Params & _params
static auto MAX(const A &one, const B &two) -> decltype(one > two ? one :two)
AP_Int32 _pack_capacity
offset voltage that is subtracted from current pin before conversion to amps
uint8_t get_PEC(const uint8_t i2c_addr, uint8_t cmd, bool reading, const uint8_t buff[], uint8_t len) const
get_PEC - calculate packet error correction code of buffer
static AP_HAL::OwnPtr< AP_HAL::Device > dev
AP_HAL::OwnPtr< AP_HAL::I2CDevice > _dev
bool read_full_charge_capacity(void)
void read(void) override
read the battery_voltage and current, should be called at 10hz
AP_BattMonitor::BattMonitor_State & _state
#define AP_BATT_SERIAL_NUMBER_DEFAULT
bool read_registers(uint8_t first_reg, uint8_t *recv, uint32_t recv_len)
#define FUNCTOR_BIND_MEMBER(func, rettype,...)
bool read_remaining_capacity(void)
AP_Int32 _serial_number
max battery power allowed. Reduce max throttle to reduce current to satisfy t his limit ...
uint32_t temperature_time
bool read_serial_number(void)