mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-22 01:12:31 +00:00
removed unneeded file, some more clean up
This commit is contained in:
@@ -32,13 +32,13 @@
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file batt_smbus.cpp
|
||||
* @file batt_smbus.h
|
||||
*
|
||||
* Driver for a battery monitor connected via SMBus (I2C).
|
||||
* Header for a battery monitor connected via SMBus (I2C).
|
||||
* Designed for BQ40Z50-R1/R2
|
||||
*
|
||||
* @author Alex Klimaj <alexklimaj@gmail.com>
|
||||
* @author Jacob Dahl <dahl.jakejacob@gmail.com>
|
||||
* @author Alex Klimaj <alexklimaj@gmail.com>
|
||||
*/
|
||||
|
||||
#include <px4_defines.h>
|
||||
@@ -134,7 +134,6 @@ int BATT_SMBUS::task_spawn(int argc, char *argv[])
|
||||
SMBus *interface = new SMBus(bus_options[i].busnum, BATT_SMBUS_ADDR);
|
||||
BATT_SMBUS *dev = new BATT_SMBUS(interface, bus_options[i].devpath);
|
||||
|
||||
|
||||
// Successful read of device type, we've found our battery
|
||||
_object = dev;
|
||||
_task_id = task_id_is_work_queue;
|
||||
@@ -200,7 +199,8 @@ void BATT_SMBUS::cycle()
|
||||
|
||||
new_report.average_current_a = average_current;
|
||||
|
||||
// If current is high, turn under voltage protection off.
|
||||
// If current is high, turn under voltage protection off. This is neccessary to prevent
|
||||
// a battery from cutting off while flying with high current near the end of the packs capacity.
|
||||
set_undervoltage_protection(average_current);
|
||||
|
||||
// Read run time to empty.
|
||||
@@ -425,32 +425,6 @@ int BATT_SMBUS::get_startup_info()
|
||||
_batt_capacity = full_cap;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// if (_interface->read_word(BATT_SMBUS_SERIAL_NUMBER, &tmp) == PX4_OK) {
|
||||
// _serial_number = tmp;
|
||||
// result = PX4_OK;
|
||||
// }
|
||||
|
||||
// // Read battery capacity on startup.
|
||||
// if (_interface->read_word(BATT_SMBUS_REMAINING_CAPACITY, &tmp) == PX4_OK) {
|
||||
// _batt_startup_capacity = tmp;
|
||||
// result = PX4_OK;
|
||||
// }
|
||||
|
||||
// // Read battery cycle count on startup.
|
||||
// if (_interface->read_word(BATT_SMBUS_CYCLE_COUNT, &tmp) == PX4_OK) {
|
||||
// _cycle_count = tmp;
|
||||
// result = PX4_OK;
|
||||
// }
|
||||
|
||||
// // Read battery design capacity on startup.
|
||||
// if (_interface->read_word(BATT_SMBUS_FULL_CHARGE_CAPACITY, &tmp) == PX4_OK) {
|
||||
// _batt_capacity = tmp;
|
||||
// result = PX4_OK;
|
||||
// }
|
||||
|
||||
if (lifetime_data_flush() == PX4_OK) {
|
||||
if (lifetime_read_block_one() == PX4_OK) {
|
||||
if (_lifetime_max_delta_cell_voltage > BATT_CELL_VOLTAGE_THRESHOLD_FAILED) {
|
||||
@@ -586,7 +560,6 @@ int BATT_SMBUS::lifetime_read_block_one()
|
||||
|
||||
uint8_t lifetime_block_one[32] = {};
|
||||
|
||||
//
|
||||
if (PX4_OK != manufacturer_read(BATT_SMBUS_LIFETIME_BLOCK_ONE, lifetime_block_one, 32)) {
|
||||
PX4_INFO("Failed to read lifetime block 1.");
|
||||
return PX4_ERROR;
|
||||
@@ -621,10 +594,10 @@ int BATT_SMBUS::write_flash(uint16_t address, uint8_t *tx_buf, const unsigned le
|
||||
|
||||
int BATT_SMBUS::custom_command(int argc, char *argv[])
|
||||
{
|
||||
//const char *input = argv[optind];
|
||||
const char *input = argv[0];
|
||||
uint8_t man_name[22];
|
||||
int result = 0;
|
||||
const char *input = argv[0];
|
||||
|
||||
BATT_SMBUS *obj = get_instance();
|
||||
|
||||
if (!strcmp(input, "man_info")) {
|
||||
|
||||
@@ -37,10 +37,8 @@
|
||||
* Header for a battery monitor connected via SMBus (I2C).
|
||||
* Designed for BQ40Z50-R1/R2
|
||||
*
|
||||
* @author Randy Mackay <rmackay9@yahoo.com>
|
||||
* @author Alex Klimaj <alexklimaj@gmail.com>
|
||||
* @author Mark Sauder <mcsauder@gmail.com>
|
||||
* @author Jacob Dahl <dahl.jakejacob@gmail.com>
|
||||
* @author Alex Klimaj <alexklimaj@gmail.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
@@ -282,33 +280,35 @@ public:
|
||||
*/
|
||||
int write_flash(uint16_t address, uint8_t *tx_buf, const unsigned length);
|
||||
|
||||
/**
|
||||
* @brief Reads the cell voltages.
|
||||
* @return Returns PX4_OK on success or associated read error code on failure.
|
||||
*/
|
||||
int get_cell_voltages();
|
||||
|
||||
/**
|
||||
* @brief Enables or disables the cell under voltage protection emergency shut off.
|
||||
*/
|
||||
void set_undervoltage_protection(float average_current);
|
||||
|
||||
SMBus *_interface;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief Static function that is called by worker queue.
|
||||
*/
|
||||
static void cycle_trampoline(void *arg);
|
||||
|
||||
static work_s _work;
|
||||
|
||||
perf_counter_t _cycle;
|
||||
|
||||
float _cell_voltages[4] = {};
|
||||
|
||||
float _max_cell_voltage_delta{0};
|
||||
|
||||
float _min_cell_voltage{0};
|
||||
|
||||
/**
|
||||
* @brief The loop that continually generates new reports.
|
||||
*/
|
||||
void cycle();
|
||||
|
||||
/** @struct _work Work queue for scheduling reads. */
|
||||
static work_s _work;
|
||||
|
||||
/** @param _last_report Last published report, used for test(). */
|
||||
battery_status_s _last_report = battery_status_s{};
|
||||
|
||||
|
||||
@@ -1,131 +0,0 @@
|
||||
/****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2018 PX4 Development Team. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name PX4 nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file batt_smbus_i2c.cpp
|
||||
*
|
||||
* I2C interface for batt_smbus
|
||||
*
|
||||
* @author Jacob Dahl <dahl.jakejacob@gmail.com>
|
||||
*/
|
||||
|
||||
#include "batt_smbus.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include <px4_config.h>
|
||||
|
||||
#include <drivers/device/i2c.h>
|
||||
#include <drivers/drv_device.h>
|
||||
|
||||
#include "board_config.h"
|
||||
|
||||
device::Device *BATT_SMBUS_I2C_interface(int bus);
|
||||
|
||||
class BATT_SMBUS_I2C : public device::I2C
|
||||
{
|
||||
public:
|
||||
BATT_SMBUS_I2C(int bus);
|
||||
virtual ~BATT_SMBUS_I2C() = default;
|
||||
|
||||
/**
|
||||
* @brief Sends a block read command.
|
||||
* @param cmd_code The command code.
|
||||
* @param data Pointer to the data being returned.
|
||||
* @param count The number of bytes being read
|
||||
* @return Returns PX4_OK on success, PX4_ERROR on failure.
|
||||
*/
|
||||
virtual int read(unsigned cmd_code, void *data, unsigned count);
|
||||
|
||||
/**
|
||||
* @brief Sends a block write command.
|
||||
* @param cmd_code The command code.
|
||||
* @param data Pointer to the data to be written.
|
||||
* @param count The number of bytes being written.
|
||||
* @return Returns PX4_OK on success, PX4_ERROR on failure.
|
||||
*/
|
||||
virtual int write(unsigned cmd_code, void *data, unsigned count);
|
||||
|
||||
/**
|
||||
* @brief Sends a block read command.
|
||||
* @param cmd_code The command code.
|
||||
* @param data Pointer to the data being returned.
|
||||
* @return Returns PX4_OK on success, PX4_ERROR on failure.
|
||||
*/
|
||||
int read(unsigned cmd_code, void *data);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Sends a block write command.
|
||||
* @param cmd_code The command code.
|
||||
* @param data Pointer to the data to be written.
|
||||
* @return Returns PX4_OK on success, PX4_ERROR on failure.
|
||||
*/
|
||||
int write(unsigned cmd_code, void *data);
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* @brief Calculates the PEC from the data.
|
||||
* @param buffer The buffer that stores the data.
|
||||
* @param length The number of bytes being written.
|
||||
* @return Returns PX4_OK on success, PX4_ERROR on failure.
|
||||
*/
|
||||
uint8_t get_pec(uint8_t *buffer, uint8_t length);
|
||||
|
||||
};
|
||||
|
||||
device::Device *
|
||||
BATT_SMBUS_I2C_interface(int bus)
|
||||
{
|
||||
return new BATT_SMBUS_I2C(bus);
|
||||
}
|
||||
|
||||
BATT_SMBUS_I2C::BATT_SMBUS_I2C(int bus) :
|
||||
I2C("BATT_SMBUS_I2C", nullptr, bus, BATT_SMBUS_ADDR, 100000)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
BATT_SMBUS_I2C::read(unsigned cmd_code, void *data, unsigned length)
|
||||
{
|
||||
uint8_t buf = (uint8_t) cmd_code;
|
||||
return transfer(&buf, 1, (uint8_t *)data, length);
|
||||
}
|
||||
|
||||
int
|
||||
BATT_SMBUS_I2C::write(unsigned cmd_code, void *data, unsigned length)
|
||||
{
|
||||
return transfer((uint8_t *)data, length, nullptr, 0);
|
||||
}
|
||||
Reference in New Issue
Block a user