mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 07:23:34 +08:00
delete drv_baro.h, drv_mag.h, drv_range_finder.h, drv_device.h and purge UAVCAN CDev usage
This commit is contained in:
@@ -42,7 +42,6 @@
|
||||
#include <cstring>
|
||||
|
||||
#include <px4_platform_common/posix.h>
|
||||
#include <drivers/drv_device.h>
|
||||
|
||||
namespace cdev
|
||||
{
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
#include "../CDev.hpp"
|
||||
|
||||
#include <px4_platform_common/posix.h>
|
||||
#include "drivers/drv_device.h"
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#ifdef CONFIG_DISABLE_POLL
|
||||
|
||||
@@ -43,7 +43,6 @@
|
||||
|
||||
#include <px4_platform_common/tasks.h>
|
||||
#include <px4_platform_common/time.h>
|
||||
#include <drivers/drv_device.h>
|
||||
#include <lib/cdev/CDev.hpp>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -65,8 +65,6 @@ static constexpr uint8_t clipping(const int16_t samples[16], int16_t clip_limit,
|
||||
}
|
||||
|
||||
PX4Accelerometer::PX4Accelerometer(uint32_t device_id, enum Rotation rotation) :
|
||||
_sensor_pub{ORB_ID(sensor_accel)},
|
||||
_sensor_fifo_pub{ORB_ID(sensor_accel_fifo)},
|
||||
_device_id{device_id},
|
||||
_rotation{rotation}
|
||||
{
|
||||
|
||||
@@ -66,8 +66,8 @@ private:
|
||||
void Publish(const hrt_abstime ×tamp_sample, float x, float y, float z, uint8_t clip_count[3]);
|
||||
void UpdateClipLimit();
|
||||
|
||||
uORB::PublicationMulti<sensor_accel_s> _sensor_pub;
|
||||
uORB::PublicationMulti<sensor_accel_fifo_s> _sensor_fifo_pub;
|
||||
uORB::PublicationMulti<sensor_accel_s> _sensor_pub{ORB_ID(sensor_accel)};
|
||||
uORB::PublicationMulti<sensor_accel_fifo_s> _sensor_fifo_pub{ORB_ID(sensor_accel_fifo)};
|
||||
|
||||
uint32_t _device_id{0};
|
||||
const enum Rotation _rotation;
|
||||
|
||||
@@ -36,11 +36,8 @@
|
||||
|
||||
#include <lib/drivers/device/Device.hpp>
|
||||
|
||||
PX4Barometer::PX4Barometer(uint32_t device_id) :
|
||||
CDev(nullptr),
|
||||
_sensor_baro_pub{ORB_ID(sensor_baro)}
|
||||
PX4Barometer::PX4Barometer(uint32_t device_id)
|
||||
{
|
||||
_class_device_instance = register_class_devname(BARO_BASE_DEVICE_PATH);
|
||||
_sensor_baro_pub.advertise();
|
||||
|
||||
_sensor_baro_pub.get().device_id = device_id;
|
||||
@@ -48,10 +45,6 @@ PX4Barometer::PX4Barometer(uint32_t device_id) :
|
||||
|
||||
PX4Barometer::~PX4Barometer()
|
||||
{
|
||||
if (_class_device_instance != -1) {
|
||||
unregister_class_devname(BARO_BASE_DEVICE_PATH, _class_device_instance);
|
||||
}
|
||||
|
||||
_sensor_baro_pub.unadvertise();
|
||||
}
|
||||
|
||||
|
||||
@@ -33,20 +33,17 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <drivers/drv_baro.h>
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <lib/cdev/CDev.hpp>
|
||||
#include <lib/conversion/rotation.h>
|
||||
#include <uORB/uORB.h>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/topics/sensor_baro.h>
|
||||
|
||||
class PX4Barometer : public cdev::CDev
|
||||
class PX4Barometer
|
||||
{
|
||||
|
||||
public:
|
||||
PX4Barometer(uint32_t device_id);
|
||||
~PX4Barometer() override;
|
||||
~PX4Barometer();
|
||||
|
||||
const sensor_baro_s &get() { return _sensor_baro_pub.get(); }
|
||||
|
||||
@@ -57,12 +54,9 @@ public:
|
||||
|
||||
void update(const hrt_abstime ×tamp_sample, float pressure);
|
||||
|
||||
int get_class_instance() { return _class_device_instance; };
|
||||
int get_instance() { return _sensor_baro_pub.get_instance(); };
|
||||
|
||||
private:
|
||||
|
||||
uORB::PublicationMultiData<sensor_baro_s> _sensor_baro_pub;
|
||||
|
||||
int _class_device_instance{-1};
|
||||
|
||||
uORB::PublicationMultiData<sensor_baro_s> _sensor_baro_pub{ORB_ID(sensor_baro)};
|
||||
};
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
#include <cstring>
|
||||
|
||||
#include <px4_platform_common/posix.h>
|
||||
#include <drivers/drv_device.h>
|
||||
|
||||
namespace device
|
||||
{
|
||||
@@ -77,21 +76,4 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int CDev::ioctl(file_t *filep, int cmd, unsigned long arg)
|
||||
{
|
||||
PX4_DEBUG("CDev::ioctl");
|
||||
int ret = -ENOTTY;
|
||||
|
||||
switch (cmd) {
|
||||
case DEVIOCGDEVICEID:
|
||||
ret = (int)_device_id.devid;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace device
|
||||
|
||||
@@ -75,16 +75,12 @@ public:
|
||||
/**
|
||||
* Perform an ioctl operation on the device.
|
||||
*
|
||||
* The default implementation handles DEVIOCGDEVICEID, and otherwise
|
||||
* returns -ENOTTY. Subclasses should call the default implementation
|
||||
* for any command they do not handle themselves.
|
||||
*
|
||||
* @param filep Pointer to the NuttX file structure.
|
||||
* @param cmd The ioctl command value.
|
||||
* @param arg The ioctl argument value.
|
||||
* @return OK on success, or -errno otherwise.
|
||||
*/
|
||||
virtual int ioctl(file_t *filep, int cmd, unsigned long arg);
|
||||
virtual int ioctl(file_t *filep, int cmd, unsigned long arg) { return -ENOTTY; }
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
#include <px4_platform_common/px4_config.h>
|
||||
#include <px4_platform_common/posix.h>
|
||||
|
||||
#include <drivers/drv_device.h>
|
||||
#include <drivers/drv_sensor.h>
|
||||
|
||||
#define DEVICE_LOG(FMT, ...) PX4_LOG_NAMED(_name, FMT, ##__VA_ARGS__)
|
||||
#define DEVICE_DEBUG(FMT, ...) PX4_LOG_NAMED_COND(_name, _debug_enabled, FMT, ##__VA_ARGS__)
|
||||
@@ -138,15 +138,7 @@ public:
|
||||
* @param arg An argument to the operation.
|
||||
* @return Negative errno on error, OK or positive value on success.
|
||||
*/
|
||||
virtual int ioctl(unsigned operation, unsigned &arg)
|
||||
{
|
||||
switch (operation) {
|
||||
case DEVIOCGDEVICEID:
|
||||
return (int)_device_id.devid;
|
||||
}
|
||||
|
||||
return -ENODEV;
|
||||
}
|
||||
virtual int ioctl(unsigned operation, unsigned &arg) { return -ENODEV; }
|
||||
|
||||
/** Device bus types for DEVID */
|
||||
enum DeviceBusType {
|
||||
@@ -182,7 +174,8 @@ public:
|
||||
*
|
||||
* @return The bus type
|
||||
*/
|
||||
DeviceBusType get_device_bus_type() const { return _device_id.devid_s.bus_type; }
|
||||
DeviceBusType get_device_bus_type() const { return _device_id.devid_s.bus_type; }
|
||||
void set_device_bus_type(DeviceBusType bus_type) { _device_id.devid_s.bus_type = bus_type; }
|
||||
|
||||
static const char *get_device_bus_string(DeviceBusType bus)
|
||||
{
|
||||
@@ -211,6 +204,7 @@ public:
|
||||
* @return The bus ID
|
||||
*/
|
||||
uint8_t get_device_bus() const { return _device_id.devid_s.bus; }
|
||||
void set_device_bus(uint8_t bus) { _device_id.devid_s.bus = bus; }
|
||||
|
||||
/**
|
||||
* Return the bus address of the device.
|
||||
|
||||
@@ -52,8 +52,6 @@ static constexpr int32_t sum(const int16_t samples[16], uint8_t len)
|
||||
}
|
||||
|
||||
PX4Gyroscope::PX4Gyroscope(uint32_t device_id, enum Rotation rotation) :
|
||||
_sensor_pub{ORB_ID(sensor_gyro)},
|
||||
_sensor_fifo_pub{ORB_ID(sensor_gyro_fifo)},
|
||||
_device_id{device_id},
|
||||
_rotation{rotation}
|
||||
{
|
||||
|
||||
@@ -64,8 +64,8 @@ public:
|
||||
private:
|
||||
void Publish(const hrt_abstime ×tamp_sample, float x, float y, float z);
|
||||
|
||||
uORB::PublicationMulti<sensor_gyro_s> _sensor_pub;
|
||||
uORB::PublicationMulti<sensor_gyro_fifo_s> _sensor_fifo_pub;
|
||||
uORB::PublicationMulti<sensor_gyro_s> _sensor_pub{ORB_ID(sensor_gyro)};
|
||||
uORB::PublicationMulti<sensor_gyro_fifo_s> _sensor_fifo_pub{ORB_ID(sensor_gyro_fifo)};
|
||||
|
||||
uint32_t _device_id{0};
|
||||
const enum Rotation _rotation;
|
||||
|
||||
@@ -37,23 +37,15 @@
|
||||
#include <lib/drivers/device/Device.hpp>
|
||||
|
||||
PX4Magnetometer::PX4Magnetometer(uint32_t device_id, enum Rotation rotation) :
|
||||
CDev(nullptr),
|
||||
_sensor_pub{ORB_ID(sensor_mag)},
|
||||
_device_id{device_id},
|
||||
_rotation{rotation}
|
||||
{
|
||||
// advertise immediately to keep instance numbering in sync
|
||||
_sensor_pub.advertise();
|
||||
|
||||
_class_device_instance = register_class_devname(MAG_BASE_DEVICE_PATH);
|
||||
}
|
||||
|
||||
PX4Magnetometer::~PX4Magnetometer()
|
||||
{
|
||||
if (_class_device_instance != -1) {
|
||||
unregister_class_devname(MAG_BASE_DEVICE_PATH, _class_device_instance);
|
||||
}
|
||||
|
||||
_sensor_pub.unadvertise();
|
||||
}
|
||||
|
||||
|
||||
@@ -33,18 +33,16 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <drivers/drv_mag.h>
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <lib/cdev/CDev.hpp>
|
||||
#include <lib/conversion/rotation.h>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/topics/sensor_mag.h>
|
||||
|
||||
class PX4Magnetometer : public cdev::CDev
|
||||
class PX4Magnetometer
|
||||
{
|
||||
public:
|
||||
PX4Magnetometer(uint32_t device_id, enum Rotation rotation = ROTATION_NONE);
|
||||
~PX4Magnetometer() override;
|
||||
~PX4Magnetometer();
|
||||
|
||||
bool external() { return _external; }
|
||||
|
||||
@@ -58,10 +56,10 @@ public:
|
||||
|
||||
void update(const hrt_abstime ×tamp_sample, float x, float y, float z);
|
||||
|
||||
int get_class_instance() { return _class_device_instance; };
|
||||
int get_instance() { return _sensor_pub.get_instance(); };
|
||||
|
||||
private:
|
||||
uORB::PublicationMulti<sensor_mag_s> _sensor_pub;
|
||||
uORB::PublicationMulti<sensor_mag_s> _sensor_pub{ORB_ID(sensor_mag)};
|
||||
|
||||
uint32_t _device_id{0};
|
||||
const enum Rotation _rotation;
|
||||
@@ -71,6 +69,4 @@ private:
|
||||
uint32_t _error_count{0};
|
||||
|
||||
bool _external{false};
|
||||
|
||||
int _class_device_instance{-1};
|
||||
};
|
||||
|
||||
@@ -35,12 +35,8 @@
|
||||
|
||||
#include <lib/drivers/device/Device.hpp>
|
||||
|
||||
PX4Rangefinder::PX4Rangefinder(const uint32_t device_id, const uint8_t device_orientation) :
|
||||
CDev(nullptr),
|
||||
_distance_sensor_pub{ORB_ID(distance_sensor)}
|
||||
PX4Rangefinder::PX4Rangefinder(const uint32_t device_id, const uint8_t device_orientation)
|
||||
{
|
||||
_class_device_instance = register_class_devname(RANGE_FINDER_BASE_DEVICE_PATH);
|
||||
|
||||
_distance_sensor_pub.advertise();
|
||||
|
||||
set_device_id(device_id);
|
||||
@@ -49,10 +45,6 @@ PX4Rangefinder::PX4Rangefinder(const uint32_t device_id, const uint8_t device_or
|
||||
|
||||
PX4Rangefinder::~PX4Rangefinder()
|
||||
{
|
||||
if (_class_device_instance != -1) {
|
||||
unregister_class_devname(RANGE_FINDER_BASE_DEVICE_PATH, _class_device_instance);
|
||||
}
|
||||
|
||||
_distance_sensor_pub.unadvertise();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,15 +34,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <drivers/drv_hrt.h>
|
||||
#include <drivers/drv_range_finder.h>
|
||||
#include <lib/cdev/CDev.hpp>
|
||||
#include <lib/conversion/rotation.h>
|
||||
#include <uORB/PublicationMulti.hpp>
|
||||
#include <uORB/topics/distance_sensor.h>
|
||||
|
||||
class PX4Rangefinder : public cdev::CDev
|
||||
class PX4Rangefinder
|
||||
{
|
||||
|
||||
public:
|
||||
PX4Rangefinder(const uint32_t device_id,
|
||||
const uint8_t device_orientation = distance_sensor_s::ROTATION_DOWNWARD_FACING);
|
||||
@@ -64,12 +61,8 @@ public:
|
||||
|
||||
void update(const hrt_abstime ×tamp_sample, const float distance, const int8_t quality = -1);
|
||||
|
||||
int get_class_instance() { return _class_device_instance; };
|
||||
int get_instance() { return _distance_sensor_pub.get_instance(); };
|
||||
|
||||
private:
|
||||
|
||||
uORB::PublicationMultiData<distance_sensor_s> _distance_sensor_pub;
|
||||
|
||||
int _class_device_instance{-1};
|
||||
|
||||
uORB::PublicationMultiData<distance_sensor_s> _distance_sensor_pub{ORB_ID(distance_sensor)};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user