mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-27 17:53:33 +08:00
Fixes for DriverFramework, accelsim and gyrosim
DriverFramework was updated to properly delete nodes in managed lists. Baro was fixed to use DriverFramework. Accelsim was fixed with change to DriverFramework to return < 0 when start() is called and the driver was already started, or stop() is called but the driver was not running. Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
+1
-1
Submodule src/lib/DriverFramework updated: c06bbb16cf...2ae8d8118d
@@ -530,9 +530,14 @@ ACCELSIM::devIOCTL(unsigned long cmd, unsigned long arg)
|
|||||||
/* adjust filters */
|
/* adjust filters */
|
||||||
accel_set_driver_lowpass_filter((float)ul_arg, _accel_filter_x.get_cutoff_freq());
|
accel_set_driver_lowpass_filter((float)ul_arg, _accel_filter_x.get_cutoff_freq());
|
||||||
|
|
||||||
|
bool want_start = (m_sample_interval_usecs == 0);
|
||||||
|
|
||||||
/* update interval for next measurement */
|
/* update interval for next measurement */
|
||||||
setSampleInterval(interval);
|
setSampleInterval(interval);
|
||||||
|
|
||||||
|
if (want_start) {
|
||||||
|
start();
|
||||||
|
}
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -651,9 +656,14 @@ ACCELSIM::mag_ioctl(unsigned long cmd, unsigned long arg)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool want_start = (_mag->m_sample_interval_usecs == 0);
|
||||||
|
|
||||||
/* update interval for next measurement */
|
/* update interval for next measurement */
|
||||||
_mag->setSampleInterval(interval);
|
_mag->setSampleInterval(interval);
|
||||||
|
|
||||||
|
if (want_start) {
|
||||||
|
_mag->start();
|
||||||
|
}
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -765,11 +775,7 @@ ACCELSIM::start()
|
|||||||
{
|
{
|
||||||
//PX4_INFO("ACCELSIM::start");
|
//PX4_INFO("ACCELSIM::start");
|
||||||
/* make sure we are stopped first */
|
/* make sure we are stopped first */
|
||||||
int ret = stop();
|
stop();
|
||||||
|
|
||||||
if (ret != 0) {
|
|
||||||
PX4_ERR("ACCELSIM::start stop failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* reset the report ring */
|
/* reset the report ring */
|
||||||
_accel_reports->flush();
|
_accel_reports->flush();
|
||||||
@@ -781,7 +787,7 @@ ACCELSIM::start()
|
|||||||
PX4_ERR("ACCELSIM::start base class start failed");
|
PX4_ERR("ACCELSIM::start base class start failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
return (ret != 0 || ret2 != 0) ? -1 : 0;
|
return (ret2 != 0) ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|||||||
@@ -68,16 +68,13 @@
|
|||||||
#include "barosim.h"
|
#include "barosim.h"
|
||||||
#include "VirtDevObj.hpp"
|
#include "VirtDevObj.hpp"
|
||||||
|
|
||||||
enum BAROSIM_BUS {
|
|
||||||
BAROSIM_BUS_SIM_EXTERNAL
|
|
||||||
};
|
|
||||||
|
|
||||||
/* helper macro for handling report buffer indices */
|
/* helper macro for handling report buffer indices */
|
||||||
#define INCREMENT(_x, _lim) do { __typeof__(_x) _tmp = _x+1; if (_tmp >= _lim) _tmp = 0; _x = _tmp; } while(0)
|
#define INCREMENT(_x, _lim) do { __typeof__(_x) _tmp = _x+1; if (_tmp >= _lim) _tmp = 0; _x = _tmp; } while(0)
|
||||||
|
|
||||||
/* helper macro for arithmetic - returns the square of the argument */
|
/* helper macro for arithmetic - returns the square of the argument */
|
||||||
#define POW2(_x) ((_x) * (_x))
|
#define POW2(_x) ((_x) * (_x))
|
||||||
|
|
||||||
|
#define BAROSIM_DEV_PATH "/dev/barosim"
|
||||||
/*
|
/*
|
||||||
* BAROSIM internal constants and data structures.
|
* BAROSIM internal constants and data structures.
|
||||||
*/
|
*/
|
||||||
@@ -89,7 +86,7 @@ enum BAROSIM_BUS {
|
|||||||
class BAROSIM : public VirtDevObj
|
class BAROSIM : public VirtDevObj
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BAROSIM(DevObj *interface, barosim::prom_u &prom_buf, const char *path);
|
BAROSIM(const char *path);
|
||||||
~BAROSIM();
|
~BAROSIM();
|
||||||
|
|
||||||
virtual int init();
|
virtual int init();
|
||||||
@@ -103,12 +100,9 @@ public:
|
|||||||
void print_info();
|
void print_info();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
DevObj *_interface;
|
BAROSIM_DEV *_interface;
|
||||||
|
|
||||||
barosim::prom_s _prom;
|
|
||||||
|
|
||||||
struct work_s _work;
|
struct work_s _work;
|
||||||
unsigned _measure_ticks;
|
|
||||||
|
|
||||||
ringbuffer::RingBuffer *_reports;
|
ringbuffer::RingBuffer *_reports;
|
||||||
|
|
||||||
@@ -127,7 +121,6 @@ protected:
|
|||||||
|
|
||||||
orb_advert_t _baro_topic;
|
orb_advert_t _baro_topic;
|
||||||
int _orb_class_instance;
|
int _orb_class_instance;
|
||||||
int _class_instance;
|
|
||||||
|
|
||||||
perf_counter_t _sample_perf;
|
perf_counter_t _sample_perf;
|
||||||
perf_counter_t _measure_perf;
|
perf_counter_t _measure_perf;
|
||||||
@@ -185,7 +178,7 @@ protected:
|
|||||||
int measure();
|
int measure();
|
||||||
|
|
||||||
// Unused
|
// Unused
|
||||||
virtual void _measure() {}
|
virtual void _measure();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collect the result of the most recent measurement.
|
* Collect the result of the most recent measurement.
|
||||||
@@ -193,16 +186,16 @@ protected:
|
|||||||
virtual int collect();
|
virtual int collect();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static BAROSIM *g_barosim = nullptr;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Driver 'main' command.
|
* Driver 'main' command.
|
||||||
*/
|
*/
|
||||||
extern "C" __EXPORT int barosim_main(int argc, char *argv[]);
|
extern "C" __EXPORT int barosim_main(int argc, char *argv[]);
|
||||||
|
|
||||||
BAROSIM::BAROSIM(DevObj *interface, barosim::prom_u &prom_buf, const char *path) :
|
BAROSIM::BAROSIM(const char *path) :
|
||||||
VirtDevObj("BAROSIM", path, BARO_BASE_DEVICE_PATH, 1e6 / 100),
|
VirtDevObj("BAROSIM", path, BARO_BASE_DEVICE_PATH, 1e6 / 100),
|
||||||
_interface(interface),
|
_interface(nullptr),
|
||||||
_prom(prom_buf.s),
|
|
||||||
_measure_ticks(0),
|
|
||||||
_reports(nullptr),
|
_reports(nullptr),
|
||||||
_collect_phase(false),
|
_collect_phase(false),
|
||||||
_measure_phase(0),
|
_measure_phase(0),
|
||||||
@@ -212,7 +205,6 @@ BAROSIM::BAROSIM(DevObj *interface, barosim::prom_u &prom_buf, const char *path)
|
|||||||
_msl_pressure(101325),
|
_msl_pressure(101325),
|
||||||
_baro_topic(nullptr),
|
_baro_topic(nullptr),
|
||||||
_orb_class_instance(-1),
|
_orb_class_instance(-1),
|
||||||
_class_instance(-1),
|
|
||||||
_sample_perf(perf_alloc(PC_ELAPSED, "barosim_read")),
|
_sample_perf(perf_alloc(PC_ELAPSED, "barosim_read")),
|
||||||
_measure_perf(perf_alloc(PC_ELAPSED, "barosim_measure")),
|
_measure_perf(perf_alloc(PC_ELAPSED, "barosim_measure")),
|
||||||
_comms_errors(perf_alloc(PC_COUNT, "barosim_comms_errors")),
|
_comms_errors(perf_alloc(PC_COUNT, "barosim_comms_errors")),
|
||||||
@@ -220,6 +212,8 @@ BAROSIM::BAROSIM(DevObj *interface, barosim::prom_u &prom_buf, const char *path)
|
|||||||
{
|
{
|
||||||
// work_cancel in stop_cycle called from the dtor will explode if we don't do this...
|
// work_cancel in stop_cycle called from the dtor will explode if we don't do this...
|
||||||
memset(&_work, 0, sizeof(_work));
|
memset(&_work, 0, sizeof(_work));
|
||||||
|
|
||||||
|
_interface = new BAROSIM_DEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
BAROSIM::~BAROSIM()
|
BAROSIM::~BAROSIM()
|
||||||
@@ -334,7 +328,7 @@ BAROSIM::devRead(void *buffer, size_t buflen)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* if automatic measurement is enabled */
|
/* if automatic measurement is enabled */
|
||||||
if (_measure_ticks > 0) {
|
if (m_sample_interval_usecs > 0) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* While there is space in the caller's buffer, and reports, copy them.
|
* While there is space in the caller's buffer, and reports, copy them.
|
||||||
@@ -396,7 +390,6 @@ BAROSIM::devRead(void *buffer, size_t buflen)
|
|||||||
int
|
int
|
||||||
BAROSIM::devIOCTL(unsigned long cmd, unsigned long arg)
|
BAROSIM::devIOCTL(unsigned long cmd, unsigned long arg)
|
||||||
{
|
{
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
|
|
||||||
case SENSORIOCSPOLLRATE:
|
case SENSORIOCSPOLLRATE:
|
||||||
@@ -405,7 +398,8 @@ BAROSIM::devIOCTL(unsigned long cmd, unsigned long arg)
|
|||||||
/* switching to manual polling */
|
/* switching to manual polling */
|
||||||
case SENSOR_POLLRATE_MANUAL:
|
case SENSOR_POLLRATE_MANUAL:
|
||||||
stop_cycle();
|
stop_cycle();
|
||||||
_measure_ticks = 0;
|
setSampleInterval(0);
|
||||||
|
m_sample_interval_usecs = 0;
|
||||||
return OK;
|
return OK;
|
||||||
|
|
||||||
/* external signalling not supported */
|
/* external signalling not supported */
|
||||||
@@ -418,39 +412,27 @@ BAROSIM::devIOCTL(unsigned long cmd, unsigned long arg)
|
|||||||
/* set default/max polling rate */
|
/* set default/max polling rate */
|
||||||
case SENSOR_POLLRATE_MAX:
|
case SENSOR_POLLRATE_MAX:
|
||||||
case SENSOR_POLLRATE_DEFAULT: {
|
case SENSOR_POLLRATE_DEFAULT: {
|
||||||
/* do we need to start internal polling? */
|
setSampleInterval(BAROSIM_CONVERSION_INTERVAL);
|
||||||
bool want_start = (_measure_ticks == 0);
|
|
||||||
|
|
||||||
/* set interval for next measurement to minimum legal value */
|
|
||||||
_measure_ticks = USEC2TICK(BAROSIM_CONVERSION_INTERVAL);
|
|
||||||
|
|
||||||
/* if we need to start the poll state machine, do it */
|
|
||||||
if (want_start) {
|
|
||||||
start_cycle();
|
|
||||||
}
|
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* adjust to a legal polling interval in Hz */
|
/* adjust to a legal polling interval in Hz */
|
||||||
default: {
|
default: {
|
||||||
/* do we need to start internal polling? */
|
|
||||||
bool want_start = (_measure_ticks == 0);
|
|
||||||
|
|
||||||
/* convert hz to tick interval via microseconds */
|
/* convert hz to tick interval via microseconds */
|
||||||
unsigned long ticks = USEC2TICK(1000000 / arg);
|
unsigned long interval = 1000000 / arg;
|
||||||
|
|
||||||
/* check against maximum rate */
|
/* check against maximum rate */
|
||||||
if (ticks < USEC2TICK(BAROSIM_CONVERSION_INTERVAL)) {
|
if (interval < BAROSIM_CONVERSION_INTERVAL) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* update interval for next measurement */
|
bool want_start = (m_sample_interval_usecs == 0);
|
||||||
_measure_ticks = ticks;
|
|
||||||
|
/* update interval for next measurement */
|
||||||
|
setSampleInterval(interval);
|
||||||
|
|
||||||
/* if we need to start the poll state machine, do it */
|
|
||||||
if (want_start) {
|
if (want_start) {
|
||||||
start_cycle();
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
return OK;
|
return OK;
|
||||||
@@ -458,11 +440,11 @@ BAROSIM::devIOCTL(unsigned long cmd, unsigned long arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case SENSORIOCGPOLLRATE:
|
case SENSORIOCGPOLLRATE:
|
||||||
if (_measure_ticks == 0) {
|
if (m_sample_interval_usecs == 0) {
|
||||||
return SENSOR_POLLRATE_MANUAL;
|
return SENSOR_POLLRATE_MANUAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (1000 / _measure_ticks);
|
return (1000000 / m_sample_interval_usecs);
|
||||||
|
|
||||||
case SENSORIOCSQUEUEDEPTH: {
|
case SENSORIOCSQUEUEDEPTH: {
|
||||||
/* lower bound is mandatory, upper bound is a sanity check */
|
/* lower bound is mandatory, upper bound is a sanity check */
|
||||||
@@ -519,21 +501,20 @@ BAROSIM::start_cycle()
|
|||||||
_reports->flush();
|
_reports->flush();
|
||||||
|
|
||||||
/* schedule a cycle to start things */
|
/* schedule a cycle to start things */
|
||||||
work_queue(HPWORK, &_work, (worker_t)&BAROSIM::cycle_trampoline, this, 1);
|
setSampleInterval(1000);
|
||||||
|
start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
BAROSIM::stop_cycle()
|
BAROSIM::stop_cycle()
|
||||||
{
|
{
|
||||||
work_cancel(HPWORK, &_work);
|
setSampleInterval(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
BAROSIM::cycle_trampoline(void *arg)
|
BAROSIM::_measure()
|
||||||
{
|
{
|
||||||
BAROSIM *dev = reinterpret_cast<BAROSIM *>(arg);
|
cycle();
|
||||||
|
|
||||||
dev->cycle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -551,8 +532,10 @@ BAROSIM::cycle()
|
|||||||
if (ret != OK) {
|
if (ret != OK) {
|
||||||
/* issue a reset command to the sensor */
|
/* issue a reset command to the sensor */
|
||||||
_interface->devIOCTL(IOCTL_RESET, dummy);
|
_interface->devIOCTL(IOCTL_RESET, dummy);
|
||||||
|
|
||||||
/* reset the collection state machine and try again */
|
/* reset the collection state machine and try again */
|
||||||
start_cycle();
|
start_cycle();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -564,15 +547,9 @@ BAROSIM::cycle()
|
|||||||
* Don't inject one after temperature measurements, so we can keep
|
* Don't inject one after temperature measurements, so we can keep
|
||||||
* doing pressure measurements at something close to the desired rate.
|
* doing pressure measurements at something close to the desired rate.
|
||||||
*/
|
*/
|
||||||
if ((_measure_phase != 0) &&
|
if (_measure_phase != 0) {
|
||||||
(_measure_ticks > USEC2TICK(BAROSIM_CONVERSION_INTERVAL))) {
|
|
||||||
|
|
||||||
/* schedule a fresh cycle call when we are ready to measure again */
|
setSampleInterval(BAROSIM_CONVERSION_INTERVAL);
|
||||||
work_queue(HPWORK,
|
|
||||||
&_work,
|
|
||||||
(worker_t)&BAROSIM::cycle_trampoline,
|
|
||||||
this,
|
|
||||||
_measure_ticks - USEC2TICK(BAROSIM_CONVERSION_INTERVAL));
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -585,6 +562,7 @@ BAROSIM::cycle()
|
|||||||
//DEVICE_LOG("measure error %d", ret);
|
//DEVICE_LOG("measure error %d", ret);
|
||||||
/* issue a reset command to the sensor */
|
/* issue a reset command to the sensor */
|
||||||
_interface->devIOCTL(IOCTL_RESET, dummy);
|
_interface->devIOCTL(IOCTL_RESET, dummy);
|
||||||
|
|
||||||
/* reset the collection state machine and try again */
|
/* reset the collection state machine and try again */
|
||||||
start_cycle();
|
start_cycle();
|
||||||
return;
|
return;
|
||||||
@@ -593,12 +571,7 @@ BAROSIM::cycle()
|
|||||||
/* next phase is collection */
|
/* next phase is collection */
|
||||||
_collect_phase = true;
|
_collect_phase = true;
|
||||||
|
|
||||||
/* schedule a fresh cycle call when the measurement is done */
|
setSampleInterval(BAROSIM_CONVERSION_INTERVAL);
|
||||||
work_queue(HPWORK,
|
|
||||||
&_work,
|
|
||||||
(worker_t)&BAROSIM::cycle_trampoline,
|
|
||||||
this,
|
|
||||||
USEC2TICK(BAROSIM_CONVERSION_INTERVAL));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -702,7 +675,7 @@ BAROSIM::print_info()
|
|||||||
perf_print_counter(_sample_perf);
|
perf_print_counter(_sample_perf);
|
||||||
perf_print_counter(_comms_errors);
|
perf_print_counter(_comms_errors);
|
||||||
perf_print_counter(_buffer_overflows);
|
perf_print_counter(_buffer_overflows);
|
||||||
PX4_INFO("poll interval: %u ticks", _measure_ticks);
|
PX4_INFO("poll interval: %u usec", m_sample_interval_usecs);
|
||||||
_reports->print_info("report queue");
|
_reports->print_info("report queue");
|
||||||
PX4_INFO("TEMP: %ld", (long)_TEMP);
|
PX4_INFO("TEMP: %ld", (long)_TEMP);
|
||||||
PX4_INFO("SENS: %lld", (long long)_SENS);
|
PX4_INFO("SENS: %lld", (long long)_SENS);
|
||||||
@@ -710,44 +683,9 @@ BAROSIM::print_info()
|
|||||||
PX4_INFO("P: %.3f", (double)_P);
|
PX4_INFO("P: %.3f", (double)_P);
|
||||||
PX4_INFO("T: %.3f", (double)_T);
|
PX4_INFO("T: %.3f", (double)_T);
|
||||||
PX4_INFO("MSL pressure: %10.4f", (double)(_msl_pressure / 100.f));
|
PX4_INFO("MSL pressure: %10.4f", (double)(_msl_pressure / 100.f));
|
||||||
|
|
||||||
PX4_INFO("factory_setup %u", _prom.factory_setup);
|
|
||||||
PX4_INFO("c1_pressure_sens %u", _prom.c1_pressure_sens);
|
|
||||||
PX4_INFO("c2_pressure_offset %u", _prom.c2_pressure_offset);
|
|
||||||
PX4_INFO("c3_temp_coeff_pres_sens %u", _prom.c3_temp_coeff_pres_sens);
|
|
||||||
PX4_INFO("c4_temp_coeff_pres_offset %u", _prom.c4_temp_coeff_pres_offset);
|
|
||||||
PX4_INFO("c5_reference_temp %u", _prom.c5_reference_temp);
|
|
||||||
PX4_INFO("c6_temp_coeff_temp %u", _prom.c6_temp_coeff_temp);
|
|
||||||
PX4_INFO("serial_and_crc %u", _prom.serial_and_crc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
namespace barosim {
|
||||||
* Local functions in support of the shell command.
|
|
||||||
*/
|
|
||||||
namespace barosim
|
|
||||||
{
|
|
||||||
|
|
||||||
/*
|
|
||||||
list of supported bus configurations
|
|
||||||
*/
|
|
||||||
struct barosim_bus_option {
|
|
||||||
enum BAROSIM_BUS busid;
|
|
||||||
const char *devpath;
|
|
||||||
BAROSIM_constructor interface_constructor;
|
|
||||||
uint8_t busnum;
|
|
||||||
BAROSIM *dev;
|
|
||||||
} bus_options[] = {
|
|
||||||
{ BAROSIM_BUS_SIM_EXTERNAL, "/dev/baro_sim", &BAROSIM_sim_interface, PX4_SIM_BUS_TEST, NULL },
|
|
||||||
};
|
|
||||||
#define NUM_BUS_OPTIONS (sizeof(bus_options)/sizeof(bus_options[0]))
|
|
||||||
|
|
||||||
bool start_bus(struct barosim_bus_option &bus);
|
|
||||||
int start();
|
|
||||||
int test();
|
|
||||||
int reset();
|
|
||||||
int info();
|
|
||||||
int calibrate(unsigned altitude);
|
|
||||||
void usage();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* BAROSIM crc4 cribbed from the datasheet
|
* BAROSIM crc4 cribbed from the datasheet
|
||||||
@@ -795,38 +733,26 @@ crc4(uint16_t *n_prom)
|
|||||||
return (0x000F & crc_read) == (n_rem ^ 0x00);
|
return (0x000F & crc_read) == (n_rem ^ 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the driver.
|
* Start the driver.
|
||||||
|
*
|
||||||
|
* This function call only returns once the driver
|
||||||
|
* is either successfully up and running or failed to start.
|
||||||
*/
|
*/
|
||||||
bool
|
static int
|
||||||
start_bus(struct barosim_bus_option &bus)
|
start()
|
||||||
{
|
{
|
||||||
if (bus.dev != nullptr) {
|
g_barosim = new BAROSIM(BAROSIM_DEV_PATH);
|
||||||
PX4_ERR("bus option already started");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
prom_u prom_buf;
|
if (g_barosim != nullptr && OK != g_barosim->init()) {
|
||||||
DevObj *interface = bus.interface_constructor(prom_buf, bus.busnum);
|
delete g_barosim;
|
||||||
|
g_barosim = NULL;
|
||||||
if (interface->init() != OK) {
|
PX4_ERR("bus init failed");
|
||||||
delete interface;
|
|
||||||
PX4_ERR("no device on bus %u", (unsigned)bus.busid);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bus.dev = new BAROSIM(interface, prom_buf, bus.devpath);
|
|
||||||
|
|
||||||
if (bus.dev != nullptr && OK != bus.dev->init()) {
|
|
||||||
delete bus.dev;
|
|
||||||
bus.dev = NULL;
|
|
||||||
PX4_ERR("bus init failed %p", bus.dev);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DevHandle h;
|
DevHandle h;
|
||||||
DevMgr::getHandle(bus.devpath, h);
|
DevMgr::getHandle(BAROSIM_DEV_PATH, h);
|
||||||
|
|
||||||
/* set the poll rate to default, starts automatic data collection */
|
/* set the poll rate to default, starts automatic data collection */
|
||||||
if (!h.isValid()) {
|
if (!h.isValid()) {
|
||||||
@@ -845,44 +771,20 @@ start_bus(struct barosim_bus_option &bus)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Start the driver.
|
|
||||||
*
|
|
||||||
* This function call only returns once the driver
|
|
||||||
* is either successfully up and running or failed to start.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
start()
|
|
||||||
{
|
|
||||||
bool started = false;
|
|
||||||
|
|
||||||
started |= start_bus(bus_options[0]);
|
|
||||||
|
|
||||||
if (!started) {
|
|
||||||
PX4_ERR("driver start failed");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// driver started OK
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform some basic functional tests on the driver;
|
* Perform some basic functional tests on the driver;
|
||||||
* make sure we can collect data from the sensor in polled
|
* make sure we can collect data from the sensor in polled
|
||||||
* and automatic modes.
|
* and automatic modes.
|
||||||
*/
|
*/
|
||||||
int
|
static int
|
||||||
test()
|
test()
|
||||||
{
|
{
|
||||||
struct barosim_bus_option &bus = bus_options[0];
|
|
||||||
struct baro_report report;
|
struct baro_report report;
|
||||||
ssize_t sz;
|
ssize_t sz;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
DevHandle h;
|
DevHandle h;
|
||||||
DevMgr::getHandle(bus.devpath, h);
|
DevMgr::getHandle(BAROSIM_DEV_PATH, h);
|
||||||
|
|
||||||
if (!h.isValid()) {
|
if (!h.isValid()) {
|
||||||
PX4_ERR("getHandle failed (try 'barosim start' if the driver is not running)");
|
PX4_ERR("getHandle failed (try 'barosim start' if the driver is not running)");
|
||||||
@@ -953,13 +855,11 @@ test()
|
|||||||
/**
|
/**
|
||||||
* Reset the driver.
|
* Reset the driver.
|
||||||
*/
|
*/
|
||||||
int
|
static int
|
||||||
reset()
|
reset()
|
||||||
{
|
{
|
||||||
struct barosim_bus_option &bus = bus_options[0];
|
|
||||||
|
|
||||||
DevHandle h;
|
DevHandle h;
|
||||||
DevMgr::getHandle(bus.devpath, h);
|
DevMgr::getHandle(BAROSIM_DEV_PATH, h);
|
||||||
|
|
||||||
if (!h.isValid()) {
|
if (!h.isValid()) {
|
||||||
PX4_ERR("failed ");
|
PX4_ERR("failed ");
|
||||||
@@ -982,16 +882,12 @@ reset()
|
|||||||
/**
|
/**
|
||||||
* Print a little info about the driver.
|
* Print a little info about the driver.
|
||||||
*/
|
*/
|
||||||
int
|
static int
|
||||||
info()
|
info()
|
||||||
{
|
{
|
||||||
for (uint8_t i = 0; i < NUM_BUS_OPTIONS; i++) {
|
if (g_barosim != nullptr) {
|
||||||
struct barosim_bus_option &bus = bus_options[i];
|
PX4_INFO("%s", BAROSIM_DEV_PATH);
|
||||||
|
g_barosim->print_info();
|
||||||
if (bus.dev != nullptr) {
|
|
||||||
PX4_INFO("%s", bus.devpath);
|
|
||||||
bus.dev->print_info();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1000,16 +896,15 @@ info()
|
|||||||
/**
|
/**
|
||||||
* Calculate actual MSL pressure given current altitude
|
* Calculate actual MSL pressure given current altitude
|
||||||
*/
|
*/
|
||||||
int
|
static int
|
||||||
calibrate(unsigned altitude)
|
calibrate(unsigned altitude)
|
||||||
{
|
{
|
||||||
struct barosim_bus_option &bus = bus_options[0];
|
|
||||||
struct baro_report report;
|
struct baro_report report;
|
||||||
float pressure;
|
float pressure;
|
||||||
float p1;
|
float p1;
|
||||||
|
|
||||||
DevHandle h;
|
DevHandle h;
|
||||||
DevMgr::getHandle(bus.devpath, h);
|
DevMgr::getHandle(BAROSIM_DEV_PATH, h);
|
||||||
|
|
||||||
if (!h.isValid()) {
|
if (!h.isValid()) {
|
||||||
PX4_ERR("open failed (try 'barosim start' if the driver is not running)");
|
PX4_ERR("open failed (try 'barosim start' if the driver is not running)");
|
||||||
@@ -1077,13 +972,13 @@ calibrate(unsigned altitude)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
PX4_WARN("missing command: try 'start', 'info', 'test', 'test2', 'reset', 'calibrate <altitude>'");
|
PX4_WARN("missing command: try 'start', 'info', 'test', 'test2', 'reset', 'calibrate <altitude>'");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
}; // namespace barosim
|
||||||
|
|
||||||
int
|
int
|
||||||
barosim_main(int argc, char *argv[])
|
barosim_main(int argc, char *argv[])
|
||||||
|
|||||||
@@ -42,11 +42,7 @@
|
|||||||
#include <px4_defines.h>
|
#include <px4_defines.h>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
//#include <debug.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <drivers/device/sim.h>
|
#include <drivers/device/sim.h>
|
||||||
@@ -54,96 +50,33 @@
|
|||||||
#include "barosim.h"
|
#include "barosim.h"
|
||||||
#include "board_config.h"
|
#include "board_config.h"
|
||||||
|
|
||||||
DevObj *BAROSIM_sim_interface(barosim::prom_u &prom_buf);
|
BAROSIM_DEV::BAROSIM_DEV() :
|
||||||
|
VirtDevObj("BAROSIM_DEV", "/dev/BAROSIM_DEV", BARO_BASE_DEVICE_PATH, 0)
|
||||||
class BARO_SIM : public device::SIM
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
BARO_SIM(uint8_t bus, barosim::prom_u &prom_buf);
|
|
||||||
virtual ~BARO_SIM();
|
|
||||||
|
|
||||||
virtual int init();
|
|
||||||
virtual int dev_read(unsigned offset, void *data, unsigned count);
|
|
||||||
virtual int dev_ioctl(unsigned operation, unsigned arg);
|
|
||||||
|
|
||||||
virtual int transfer(const uint8_t *send, unsigned send_len,
|
|
||||||
uint8_t *recv, unsigned recv_len);
|
|
||||||
private:
|
|
||||||
//barosim::prom_u &_prom;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a reset command to the barometer simulator.
|
|
||||||
*
|
|
||||||
* This is required after any bus reset.
|
|
||||||
*/
|
|
||||||
int _reset();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send a measure command to the barometer simulator.
|
|
||||||
*
|
|
||||||
* @param addr Which address to use for the measure operation.
|
|
||||||
*/
|
|
||||||
int _measure(unsigned addr);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read the MS5611 PROM
|
|
||||||
*
|
|
||||||
* @return PX4_OK if the PROM reads successfully.
|
|
||||||
*/
|
|
||||||
int _read_prom();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
DevObj *
|
|
||||||
BAROSIM_sim_interface(barosim::prom_u &prom_buf, uint8_t busnum)
|
|
||||||
{
|
|
||||||
return reinterpret_cast<DevObj *>(new BARO_SIM(busnum, prom_buf));
|
|
||||||
}
|
|
||||||
|
|
||||||
BARO_SIM::BARO_SIM(uint8_t bus, barosim::prom_u &prom) :
|
|
||||||
SIM("BARO_SIM", "/dev/BARO_SIM", bus, 0)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
BARO_SIM::~BARO_SIM()
|
BAROSIM_DEV::~BAROSIM_DEV()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
BARO_SIM::init()
|
BAROSIM_DEV::init()
|
||||||
{
|
{
|
||||||
return SIM::init();
|
return VirtDevObj::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
ssize_t
|
||||||
BARO_SIM::dev_read(unsigned offset, void *data, unsigned count)
|
BAROSIM_DEV::devRead(void *data, size_t count)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
union _cvt {
|
|
||||||
uint8_t b[4];
|
|
||||||
uint32_t w;
|
|
||||||
} *cvt = (_cvt *)data;
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* read the most recent measurement */
|
/* read the most recent measurement */
|
||||||
uint8_t cmd = 0;
|
uint8_t cmd = 0;
|
||||||
int ret = transfer(&cmd, 1, static_cast<uint8_t *>(data), count);
|
int ret = transfer(&cmd, 1, static_cast<uint8_t *>(data), count);
|
||||||
|
|
||||||
/*
|
|
||||||
if (ret == PX4_OK) {
|
|
||||||
// fetch the raw value
|
|
||||||
cvt->b[0] = buf[2];
|
|
||||||
cvt->b[1] = buf[1];
|
|
||||||
cvt->b[2] = buf[0];
|
|
||||||
cvt->b[3] = 0;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
BARO_SIM::dev_ioctl(unsigned operation, unsigned arg)
|
BAROSIM_DEV::devIOCTL(unsigned long operation, unsigned long arg)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@@ -153,7 +86,7 @@ BARO_SIM::dev_ioctl(unsigned operation, unsigned arg)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case IOCTL_MEASURE:
|
case IOCTL_MEASURE:
|
||||||
ret = _measure(arg);
|
ret = _doMeasurement(arg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -164,69 +97,60 @@ BARO_SIM::dev_ioctl(unsigned operation, unsigned arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
BARO_SIM::_reset()
|
BAROSIM_DEV::_reset()
|
||||||
{
|
{
|
||||||
unsigned old_retrycount = _retries;
|
|
||||||
uint8_t cmd = ADDR_RESET_CMD;
|
uint8_t cmd = ADDR_RESET_CMD;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
/* bump the retry count */
|
/* bump the retry count */
|
||||||
_retries = 10;
|
|
||||||
result = transfer(&cmd, 1, nullptr, 0);
|
result = transfer(&cmd, 1, nullptr, 0);
|
||||||
_retries = old_retrycount;
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
BARO_SIM::_measure(unsigned addr)
|
BAROSIM_DEV::_doMeasurement(unsigned addr)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
* Disable retries on this command; we can't know whether failure
|
|
||||||
* means the device did or did not see the command.
|
|
||||||
*/
|
|
||||||
_retries = 0;
|
|
||||||
|
|
||||||
uint8_t cmd = addr;
|
uint8_t cmd = addr;
|
||||||
return transfer(&cmd, 1, nullptr, 0);
|
return transfer(&cmd, 1, nullptr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
BARO_SIM::_read_prom()
|
BAROSIM_DEV::transfer(const uint8_t *send, unsigned send_len, uint8_t *recv, unsigned recv_len)
|
||||||
{
|
{
|
||||||
int ret = 1;
|
if (send_len == 1 && send[0] == ADDR_RESET_CMD) {
|
||||||
// TODO input simlation data
|
/* reset command */
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
|
||||||
BARO_SIM::transfer(const uint8_t *send, unsigned send_len,
|
|
||||||
uint8_t *recv, unsigned recv_len)
|
|
||||||
{
|
|
||||||
// TODO add Simulation data connection so calls retrieve
|
|
||||||
// data from the simulator
|
|
||||||
if (recv_len == 0) {
|
|
||||||
PX4_DEBUG("BARO_SIM measurement requested");
|
|
||||||
|
|
||||||
} else if (send_len == 1 || send[0] != 12) {
|
|
||||||
/* measure command */
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
} else if (send_len != 1 || send[0] != 0) {
|
} else if (send_len == 1 && (send[0] == ADDR_CMD_CONVERT_D2 || send[0] == ADDR_CMD_CONVERT_D1)) {
|
||||||
PX4_WARN("BARO_SIM::transfer invalid param %u %u %u", send_len, send[0], recv_len);
|
/* measure command */
|
||||||
return 1;
|
if (send[0] == ADDR_CMD_CONVERT_D2) {
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
|
||||||
} else {
|
} else if (send[0] == 0 && send_len == 1) {
|
||||||
|
/* read requested */
|
||||||
Simulator *sim = Simulator::getInstance();
|
Simulator *sim = Simulator::getInstance();
|
||||||
|
|
||||||
if (sim == NULL) {
|
if (sim == NULL) {
|
||||||
PX4_ERR("Error BARO_SIM::transfer no simulator");
|
PX4_ERR("Error BAROSIM_DEV::transfer no simulator");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
PX4_DEBUG("BARO_SIM::transfer getting sample");
|
PX4_DEBUG("BAROSIM_DEV::transfer getting sample");
|
||||||
sim->getBaroSample(recv, recv_len);
|
sim->getBaroSample(recv, recv_len);
|
||||||
|
return recv_len;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
PX4_WARN("BAROSIM_DEV::transfer invalid param %u %u %u", send_len, send[0], recv_len);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BAROSIM_DEV::_measure()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
*
|
*
|
||||||
* Shared defines for the ms5611 driver.
|
* Shared defines for the ms5611 driver.
|
||||||
*/
|
*/
|
||||||
#include "DevObj.hpp"
|
#include "VirtDevObj.hpp"
|
||||||
|
|
||||||
#define ADDR_RESET_CMD 0x1E /* write to this address to reset chip */
|
#define ADDR_RESET_CMD 0x1E /* write to this address to reset chip */
|
||||||
#define ADDR_CMD_CONVERT_D1 0x48 /* write to this address to start pressure conversion */
|
#define ADDR_CMD_CONVERT_D1 0x48 /* write to this address to start pressure conversion */
|
||||||
@@ -82,6 +82,35 @@ extern bool crc4(uint16_t *n_prom);
|
|||||||
|
|
||||||
using namespace DriverFramework;
|
using namespace DriverFramework;
|
||||||
|
|
||||||
/* interface factories */
|
class BAROSIM_DEV : public VirtDevObj
|
||||||
extern DevObj *BAROSIM_sim_interface(barosim::prom_u &prom_buf, uint8_t busnum);
|
{
|
||||||
typedef DevObj *(*BAROSIM_constructor)(barosim::prom_u &prom_buf, uint8_t busnum);
|
public:
|
||||||
|
BAROSIM_DEV();
|
||||||
|
virtual ~BAROSIM_DEV();
|
||||||
|
|
||||||
|
virtual int init();
|
||||||
|
virtual ssize_t devRead(void *data, size_t count);
|
||||||
|
virtual int devIOCTL(unsigned long operation, unsigned long arg);
|
||||||
|
|
||||||
|
virtual int transfer(const uint8_t *send, unsigned send_len,
|
||||||
|
uint8_t *recv, unsigned recv_len);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void _measure();
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* Send a reset command to the barometer simulator.
|
||||||
|
*
|
||||||
|
* This is required after any bus reset.
|
||||||
|
*/
|
||||||
|
int _reset();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a measure command to the barometer simulator.
|
||||||
|
*
|
||||||
|
* @param addr Which address to use for the measure operation.
|
||||||
|
*/
|
||||||
|
int _doMeasurement(unsigned addr);
|
||||||
|
|
||||||
|
};
|
||||||
|
|||||||
@@ -384,6 +384,7 @@ GYROSIM::~GYROSIM()
|
|||||||
int
|
int
|
||||||
GYROSIM::init()
|
GYROSIM::init()
|
||||||
{
|
{
|
||||||
|
PX4_INFO("GYROSIM::init");
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
|
|
||||||
struct accel_report arp = {};
|
struct accel_report arp = {};
|
||||||
@@ -443,7 +444,13 @@ GYROSIM::init()
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
start();
|
ret = start();
|
||||||
|
if (ret != OK) {
|
||||||
|
PX4_ERR("gyro accel start failed (%d)", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do not call _gyro->start() because polling is done in accel
|
||||||
|
|
||||||
_measure();
|
_measure();
|
||||||
|
|
||||||
@@ -1179,8 +1186,8 @@ int
|
|||||||
GYROSIM_gyro::init()
|
GYROSIM_gyro::init()
|
||||||
{
|
{
|
||||||
int ret = VirtDevObj::init();
|
int ret = VirtDevObj::init();
|
||||||
printf("init ret: %d\n", ret);
|
PX4_INFO("GYROSIM_gyro::init base class ret: %d", ret);
|
||||||
return ret ? ret : start();
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -31,9 +31,7 @@
|
|||||||
#
|
#
|
||||||
############################################################################
|
############################################################################
|
||||||
set(MIXER_CFLAGS -Os)
|
set(MIXER_CFLAGS -Os)
|
||||||
if(${OS} STREQUAL "qurt")
|
if(${OS} STREQUAL "nuttx")
|
||||||
list(APPEND MIXER_CFLAGS -Wframe-larger-than=2176)
|
|
||||||
else()
|
|
||||||
list(APPEND MIXER_CFLAGS -Wframe-larger-than=2100)
|
list(APPEND MIXER_CFLAGS -Wframe-larger-than=2100)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user