batt_smbus delete IOCTL usage

This commit is contained in:
Daniel Agar 2018-02-08 10:46:55 -05:00 committed by Lorenz Meier
parent 64fa1ec6a5
commit caf50dbea2
2 changed files with 7 additions and 115 deletions

View File

@ -45,7 +45,6 @@
#include <drivers/device/i2c.h>
#include <drivers/device/ringbuffer.h>
#include <drivers/drv_batt_smbus.h>
#include <drivers/drv_hrt.h>
#include <px4_config.h>
#include <px4_workqueue.h>
@ -111,11 +110,6 @@ public:
*/
virtual int init();
/**
* ioctl for retrieving battery capacity and time to empty
*/
virtual int ioctl(device::file_t *filp, int cmd, unsigned long arg);
/**
* Test device
*
@ -255,10 +249,12 @@ private:
// internal variables
bool _enabled; ///< true if we have successfully connected to battery
work_s _work{}; ///< work queue for scheduling reads
ringbuffer::RingBuffer *_reports; ///< buffer of recorded voltages, currents
struct battery_status_s _last_report; ///< last published report, used for test()
battery_status_s _last_report; ///< last published report, used for test()
orb_advert_t _batt_topic; ///< uORB battery topic
orb_id_t _batt_orb_id; ///< uORB battery topic ID
uint64_t _start_time; ///< system time we first attempt to communicate with battery
uint16_t _batt_capacity; ///< battery's design capacity in mAh (0 means unknown)
char *_manufacturer_name; ///< The name of the battery manufacturer
@ -285,9 +281,8 @@ int device_chemistry();
int solo_battery_check();
BATT_SMBUS::BATT_SMBUS(int bus, uint16_t batt_smbus_addr) :
I2C("batt_smbus", BATT_SMBUS0_DEVICE_PATH, bus, batt_smbus_addr, 100000),
I2C("batt_smbus", "/dev/batt_smbus0", bus, batt_smbus_addr, 100000),
_enabled(false),
_reports(nullptr),
_batt_topic(nullptr),
_batt_orb_id(nullptr),
_start_time(0),
@ -307,10 +302,6 @@ BATT_SMBUS::~BATT_SMBUS()
// make sure we are truly inactive
stop();
if (_reports != nullptr) {
delete _reports;
}
if (_manufacturer_name != nullptr) {
delete[] _manufacturer_name;
}
@ -337,16 +328,8 @@ BATT_SMBUS::init()
return ret;
} else {
// allocate basic report buffers
_reports = new ringbuffer::RingBuffer(2, sizeof(struct battery_status_s));
if (_reports == nullptr) {
ret = ENOTTY;
} else {
// start work queue
start();
}
// start work queue
start();
}
// init orb id
@ -355,31 +338,6 @@ BATT_SMBUS::init()
return ret;
}
int
BATT_SMBUS::ioctl(device::file_t *filp, int cmd, unsigned long arg)
{
int ret = -ENODEV;
switch (cmd) {
case BATT_SMBUS_GET_CAPACITY:
/* return battery capacity as uint16 */
if (_enabled) {
*((uint16_t *)arg) = _batt_capacity;
ret = OK;
}
break;
default:
/* see if the parent class can make any use of it */
ret = CDev::ioctl(filp, cmd, arg);
break;
}
return ret;
}
int
BATT_SMBUS::test()
{
@ -535,9 +493,6 @@ BATT_SMBUS::probe()
void
BATT_SMBUS::start()
{
// reset the report ring and state machine
_reports->flush();
// schedule a cycle to start things
work_queue(HPWORK, &_work, (worker_t)&BATT_SMBUS::cycle_trampoline, this, 1);
}
@ -691,12 +646,6 @@ BATT_SMBUS::cycle()
// copy report for test()
_last_report = new_report;
// post a report to the ring
_reports->force(&new_report);
// notify anyone waiting for data
poll_notify(POLLIN);
// record we are working
_enabled = true;
}

View File

@ -1,57 +0,0 @@
/****************************************************************************
*
* Copyright (C) 2012-2013 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 drv_batt_smbus.h
*
* SMBus battery monitor device API
*/
#pragma once
#include <stdint.h>
#include <sys/ioctl.h>
#include "drv_orb_dev.h"
/* device path */
#define BATT_SMBUS0_DEVICE_PATH "/dev/batt_smbus0"
/*
* ioctl() definitions
*/
#define _BATT_SMBUS_IOCBASE (0x2e00)
#define _BATT_SMBUS_IOC(_n) (_PX4_IOC(_BATT_SMBUS_IOCBASE, _n))
/** retrieve battery capacity */
#define BATT_SMBUS_GET_CAPACITY _BATT_SMBUS_IOC(1)