|
|
|
@ -3,7 +3,6 @@
@@ -3,7 +3,6 @@
|
|
|
|
|
#include <AP_Math/AP_Math.h> |
|
|
|
|
#include "AP_BattMonitor.h" |
|
|
|
|
#include "AP_BattMonitor_SMBus_Generic.h" |
|
|
|
|
#include <utility> |
|
|
|
|
|
|
|
|
|
uint8_t smbus_cell_ids[] = { 0x3f, // cell 1
|
|
|
|
|
0x3e, // cell 2
|
|
|
|
@ -23,7 +22,6 @@ uint8_t smbus_cell_ids[] = { 0x3f, // cell 1
@@ -23,7 +22,6 @@ uint8_t smbus_cell_ids[] = { 0x3f, // cell 1
|
|
|
|
|
#endif |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
#define SMBUS_READ_BLOCK_MAXIMUM_TRANSFER 0x20 // A Block Read or Write is allowed to transfer a maximum of 32 data bytes.
|
|
|
|
|
#define SMBUS_CELL_COUNT_CHECK_TIMEOUT 15 // check cell count for up to 15 seconds
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -129,45 +127,6 @@ void AP_BattMonitor_SMBus_Generic::timer()
@@ -129,45 +127,6 @@ void AP_BattMonitor_SMBus_Generic::timer()
|
|
|
|
|
read_cycle_count(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// read_block - returns number of characters read if successful, zero if unsuccessful
|
|
|
|
|
uint8_t AP_BattMonitor_SMBus_Generic::read_block(uint8_t reg, uint8_t* data) const |
|
|
|
|
{ |
|
|
|
|
// get length
|
|
|
|
|
uint8_t bufflen; |
|
|
|
|
// read byte (first byte indicates the number of bytes in the block)
|
|
|
|
|
if (!_dev->read_registers(reg, &bufflen, 1)) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// sanity check length returned by smbus
|
|
|
|
|
if (bufflen == 0 || bufflen > SMBUS_READ_BLOCK_MAXIMUM_TRANSFER) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// buffer to hold results (2 extra byte returned holding length and PEC)
|
|
|
|
|
const uint8_t read_size = bufflen + 1 + (_pec_supported ? 1 : 0); |
|
|
|
|
uint8_t buff[read_size]; |
|
|
|
|
|
|
|
|
|
// read bytes
|
|
|
|
|
if (!_dev->read_registers(reg, buff, read_size)) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// check PEC
|
|
|
|
|
if (_pec_supported) { |
|
|
|
|
uint8_t pec = get_PEC(AP_BATTMONITOR_SMBUS_I2C_ADDR, reg, true, buff, bufflen+1); |
|
|
|
|
if (pec != buff[bufflen+1]) { |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// copy data (excluding PEC)
|
|
|
|
|
memcpy(data, &buff[1], bufflen); |
|
|
|
|
|
|
|
|
|
// return success
|
|
|
|
|
return bufflen; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// check if PEC supported with the version value in SpecificationInfo() function
|
|
|
|
|
// returns true once PEC is confirmed as working or not working
|
|
|
|
|
bool AP_BattMonitor_SMBus_Generic::check_pec_support() |
|
|
|
@ -194,8 +153,8 @@ bool AP_BattMonitor_SMBus_Generic::check_pec_support()
@@ -194,8 +153,8 @@ bool AP_BattMonitor_SMBus_Generic::check_pec_support()
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// check manufacturer name
|
|
|
|
|
uint8_t buff[SMBUS_READ_BLOCK_MAXIMUM_TRANSFER + 1] {}; |
|
|
|
|
if (read_block(BATTMONITOR_SMBUS_MANUFACTURE_NAME, buff)) { |
|
|
|
|
uint8_t buff[AP_BATTMONITOR_SMBUS_READ_BLOCK_MAXIMUM_TRANSFER + 1] {}; |
|
|
|
|
if (read_block(BATTMONITOR_SMBUS_MANUFACTURE_NAME, buff, sizeof(buff))) { |
|
|
|
|
// Hitachi maxell batteries do not support PEC
|
|
|
|
|
if (strcmp((char*)buff, "Hitachi maxell") == 0) { |
|
|
|
|
_pec_supported = false; |
|
|
|
@ -209,4 +168,3 @@ bool AP_BattMonitor_SMBus_Generic::check_pec_support()
@@ -209,4 +168,3 @@ bool AP_BattMonitor_SMBus_Generic::check_pec_support()
|
|
|
|
|
_pec_confirmed = true; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|