mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-29 01:03:33 +08:00
airspeedsim move to cdev lib
This commit is contained in:
@@ -70,7 +70,7 @@
|
|||||||
#include "airspeedsim.h"
|
#include "airspeedsim.h"
|
||||||
|
|
||||||
AirspeedSim::AirspeedSim(int bus, int address, unsigned conversion_interval, const char *path) :
|
AirspeedSim::AirspeedSim(int bus, int address, unsigned conversion_interval, const char *path) :
|
||||||
CDev("AIRSPEEDSIM", path),
|
CDev(path),
|
||||||
_reports(nullptr),
|
_reports(nullptr),
|
||||||
_retries(0),
|
_retries(0),
|
||||||
_sensor_ok(false),
|
_sensor_ok(false),
|
||||||
@@ -83,11 +83,6 @@ AirspeedSim::AirspeedSim(int bus, int address, unsigned conversion_interval, con
|
|||||||
_sample_perf(perf_alloc(PC_ELAPSED, "airspeed_read")),
|
_sample_perf(perf_alloc(PC_ELAPSED, "airspeed_read")),
|
||||||
_comms_errors(perf_alloc(PC_COUNT, "airspeed_comms_errors"))
|
_comms_errors(perf_alloc(PC_COUNT, "airspeed_comms_errors"))
|
||||||
{
|
{
|
||||||
// enable debug() calls
|
|
||||||
_debug_enabled = false;
|
|
||||||
|
|
||||||
// work_cancel in the dtor will explode if we don't do this...
|
|
||||||
memset(&_work, 0, sizeof(_work));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AirspeedSim::~AirspeedSim()
|
AirspeedSim::~AirspeedSim()
|
||||||
@@ -116,7 +111,7 @@ AirspeedSim::init()
|
|||||||
|
|
||||||
/* init base class */
|
/* init base class */
|
||||||
if (CDev::init() != OK) {
|
if (CDev::init() != OK) {
|
||||||
DEVICE_DEBUG("CDev init failed");
|
PX4_ERR("CDev init failed");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +126,7 @@ AirspeedSim::init()
|
|||||||
_class_instance = register_class_devname(AIRSPEED_BASE_DEVICE_PATH);
|
_class_instance = register_class_devname(AIRSPEED_BASE_DEVICE_PATH);
|
||||||
|
|
||||||
/* publication init */
|
/* publication init */
|
||||||
if (_class_instance == CLASS_DEVICE_PRIMARY) {
|
if (_class_instance == 0) {
|
||||||
|
|
||||||
/* advertise sensor topic, measure manually to initialize valid report */
|
/* advertise sensor topic, measure manually to initialize valid report */
|
||||||
struct differential_pressure_s arp;
|
struct differential_pressure_s arp;
|
||||||
@@ -168,7 +163,7 @@ AirspeedSim::probe()
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
AirspeedSim::ioctl(device::file_t *filp, int cmd, unsigned long arg)
|
AirspeedSim::ioctl(cdev::file_t *filp, int cmd, unsigned long arg)
|
||||||
{
|
{
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
|
|
||||||
@@ -280,7 +275,7 @@ AirspeedSim::ioctl(device::file_t *filp, int cmd, unsigned long arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ssize_t
|
ssize_t
|
||||||
AirspeedSim::read(device::file_t *filp, char *buffer, size_t buflen)
|
AirspeedSim::read(cdev::file_t *filp, char *buffer, size_t buflen)
|
||||||
{
|
{
|
||||||
unsigned count = buflen / sizeof(differential_pressure_s);
|
unsigned count = buflen / sizeof(differential_pressure_s);
|
||||||
differential_pressure_s *abuf = reinterpret_cast<differential_pressure_s *>(buffer);
|
differential_pressure_s *abuf = reinterpret_cast<differential_pressure_s *>(buffer);
|
||||||
|
|||||||
@@ -64,7 +64,7 @@
|
|||||||
#include <drivers/drv_airspeed.h>
|
#include <drivers/drv_airspeed.h>
|
||||||
#include <drivers/drv_hrt.h>
|
#include <drivers/drv_hrt.h>
|
||||||
#include <drivers/device/ringbuffer.h>
|
#include <drivers/device/ringbuffer.h>
|
||||||
#include <drivers/device/device.h>
|
#include <lib/cdev/CDev.hpp>
|
||||||
|
|
||||||
#include <uORB/uORB.h>
|
#include <uORB/uORB.h>
|
||||||
#include <uORB/topics/differential_pressure.h>
|
#include <uORB/topics/differential_pressure.h>
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
# error This requires CONFIG_SCHED_WORKQUEUE.
|
# error This requires CONFIG_SCHED_WORKQUEUE.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class __EXPORT AirspeedSim : public device::CDev
|
class __EXPORT AirspeedSim : public cdev::CDev
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AirspeedSim(int bus, int address, unsigned conversion_interval, const char *path);
|
AirspeedSim(int bus, int address, unsigned conversion_interval, const char *path);
|
||||||
@@ -84,8 +84,8 @@ public:
|
|||||||
|
|
||||||
virtual int init();
|
virtual int init();
|
||||||
|
|
||||||
virtual ssize_t read(device::file_t *filp, char *buffer, size_t buflen);
|
virtual ssize_t read(cdev::file_t *filp, char *buffer, size_t buflen);
|
||||||
virtual int ioctl(device::file_t *filp, int cmd, unsigned long arg);
|
virtual int ioctl(cdev::file_t *filp, int cmd, unsigned long arg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Diagnostics - print some basic information about the driver.
|
* Diagnostics - print some basic information about the driver.
|
||||||
@@ -115,7 +115,7 @@ protected:
|
|||||||
virtual int transfer(const uint8_t *send, unsigned send_len,
|
virtual int transfer(const uint8_t *send, unsigned send_len,
|
||||||
uint8_t *recv, unsigned recv_len);
|
uint8_t *recv, unsigned recv_len);
|
||||||
|
|
||||||
struct work_s _work;
|
struct work_s _work {};
|
||||||
bool _sensor_ok;
|
bool _sensor_ok;
|
||||||
int _measure_ticks;
|
int _measure_ticks;
|
||||||
bool _collect_phase;
|
bool _collect_phase;
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ MEASAirspeedSim::collect()
|
|||||||
report.differential_pressure_filtered_pa = _filter.apply(diff_press_pa_raw);
|
report.differential_pressure_filtered_pa = _filter.apply(diff_press_pa_raw);
|
||||||
report.differential_pressure_raw_pa = diff_press_pa_raw;
|
report.differential_pressure_raw_pa = diff_press_pa_raw;
|
||||||
|
|
||||||
if (_airspeed_pub != nullptr && !(_pub_blocked)) {
|
if (_airspeed_pub != nullptr) {
|
||||||
/* publish it */
|
/* publish it */
|
||||||
orb_publish(ORB_ID(differential_pressure), _airspeed_pub, &report);
|
orb_publish(ORB_ID(differential_pressure), _airspeed_pub, &report);
|
||||||
}
|
}
|
||||||
@@ -256,7 +256,7 @@ MEASAirspeedSim::cycle()
|
|||||||
ret = measure();
|
ret = measure();
|
||||||
|
|
||||||
if (OK != ret) {
|
if (OK != ret) {
|
||||||
DEVICE_DEBUG("measure error");
|
PX4_ERR("measure error");
|
||||||
}
|
}
|
||||||
|
|
||||||
_sensor_ok = (ret == OK);
|
_sensor_ok = (ret == OK);
|
||||||
|
|||||||
Reference in New Issue
Block a user