mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-20 10:43:34 +08:00
Changed device::px4_device_handle_t to device::file_t
This change allowed the _posix.cpp file changes to be merged back into the original files. Signed-off-by: Mark Charlebois <charlebm@gmail.com>
This commit is contained in:
@@ -60,13 +60,13 @@ static const unsigned pollset_increment = 0;
|
||||
* The standard NuttX operation dispatch table can't call C++ member functions
|
||||
* directly, so we have to bounce them through this dispatch table.
|
||||
*/
|
||||
static int cdev_open(struct file *filp);
|
||||
static int cdev_close(struct file *filp);
|
||||
static ssize_t cdev_read(struct file *filp, char *buffer, size_t buflen);
|
||||
static ssize_t cdev_write(struct file *filp, const char *buffer, size_t buflen);
|
||||
static off_t cdev_seek(struct file *filp, off_t offset, int whence);
|
||||
static int cdev_ioctl(struct file *filp, int cmd, unsigned long arg);
|
||||
static int cdev_poll(struct file *filp, struct pollfd *fds, bool setup);
|
||||
static int cdev_open(file_t *filp);
|
||||
static int cdev_close(file_t *filp);
|
||||
static ssize_t cdev_read(file_t *filp, char *buffer, size_t buflen);
|
||||
static ssize_t cdev_write(file_t *filp, const char *buffer, size_t buflen);
|
||||
static off_t cdev_seek(file_t *filp, off_t offset, int whence);
|
||||
static int cdev_ioctl(file_t *filp, int cmd, unsigned long arg);
|
||||
static int cdev_poll(file_t *filp, px4_pollfd_struct_t *fds, bool setup);
|
||||
|
||||
/**
|
||||
* Character device indirection table.
|
||||
@@ -169,7 +169,7 @@ out:
|
||||
* Default implementations of the character device interface
|
||||
*/
|
||||
int
|
||||
CDev::open(struct file *filp)
|
||||
CDev::open(file_t *filp)
|
||||
{
|
||||
int ret = OK;
|
||||
|
||||
@@ -192,13 +192,13 @@ CDev::open(struct file *filp)
|
||||
}
|
||||
|
||||
int
|
||||
CDev::open_first(struct file *filp)
|
||||
CDev::open_first(file_t *filp)
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
|
||||
int
|
||||
CDev::close(struct file *filp)
|
||||
CDev::close(file_t *filp)
|
||||
{
|
||||
int ret = OK;
|
||||
|
||||
@@ -222,31 +222,31 @@ CDev::close(struct file *filp)
|
||||
}
|
||||
|
||||
int
|
||||
CDev::close_last(struct file *filp)
|
||||
CDev::close_last(file_t *filp)
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
CDev::read(struct file *filp, char *buffer, size_t buflen)
|
||||
CDev::read(file_t *filp, char *buffer, size_t buflen)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
CDev::write(struct file *filp, const char *buffer, size_t buflen)
|
||||
CDev::write(file_t *filp, const char *buffer, size_t buflen)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
off_t
|
||||
CDev::seek(struct file *filp, off_t offset, int whence)
|
||||
CDev::seek(file_t *filp, off_t offset, int whence)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
int
|
||||
CDev::ioctl(struct file *filp, int cmd, unsigned long arg)
|
||||
CDev::ioctl(file_t *filp, int cmd, unsigned long arg)
|
||||
{
|
||||
switch (cmd) {
|
||||
|
||||
@@ -275,7 +275,7 @@ CDev::ioctl(struct file *filp, int cmd, unsigned long arg)
|
||||
}
|
||||
|
||||
int
|
||||
CDev::poll(struct file *filp, struct pollfd *fds, bool setup)
|
||||
CDev::poll(file_t *filp, struct pollfd *fds, bool setup)
|
||||
{
|
||||
int ret = OK;
|
||||
|
||||
@@ -347,7 +347,7 @@ CDev::poll_notify_one(struct pollfd *fds, pollevent_t events)
|
||||
}
|
||||
|
||||
pollevent_t
|
||||
CDev::poll_state(struct file *filp)
|
||||
CDev::poll_state(file_t *filp)
|
||||
{
|
||||
/* by default, no poll events to report */
|
||||
return 0;
|
||||
@@ -389,7 +389,7 @@ CDev::remove_poll_waiter(struct pollfd *fds)
|
||||
}
|
||||
|
||||
static int
|
||||
cdev_open(struct file *filp)
|
||||
cdev_open(file_t *filp)
|
||||
{
|
||||
CDev *cdev = (CDev *)(filp->f_inode->i_private);
|
||||
|
||||
@@ -397,7 +397,7 @@ cdev_open(struct file *filp)
|
||||
}
|
||||
|
||||
static int
|
||||
cdev_close(struct file *filp)
|
||||
cdev_close(file_t *filp)
|
||||
{
|
||||
CDev *cdev = (CDev *)(filp->f_inode->i_private);
|
||||
|
||||
@@ -405,7 +405,7 @@ cdev_close(struct file *filp)
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
cdev_read(struct file *filp, char *buffer, size_t buflen)
|
||||
cdev_read(file_t *filp, char *buffer, size_t buflen)
|
||||
{
|
||||
CDev *cdev = (CDev *)(filp->f_inode->i_private);
|
||||
|
||||
@@ -413,7 +413,7 @@ cdev_read(struct file *filp, char *buffer, size_t buflen)
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
cdev_write(struct file *filp, const char *buffer, size_t buflen)
|
||||
cdev_write(file_t *filp, const char *buffer, size_t buflen)
|
||||
{
|
||||
CDev *cdev = (CDev *)(filp->f_inode->i_private);
|
||||
|
||||
@@ -421,7 +421,7 @@ cdev_write(struct file *filp, const char *buffer, size_t buflen)
|
||||
}
|
||||
|
||||
static off_t
|
||||
cdev_seek(struct file *filp, off_t offset, int whence)
|
||||
cdev_seek(file_t *filp, off_t offset, int whence)
|
||||
{
|
||||
CDev *cdev = (CDev *)(filp->f_inode->i_private);
|
||||
|
||||
@@ -429,7 +429,7 @@ cdev_seek(struct file *filp, off_t offset, int whence)
|
||||
}
|
||||
|
||||
static int
|
||||
cdev_ioctl(struct file *filp, int cmd, unsigned long arg)
|
||||
cdev_ioctl(file_t *filp, int cmd, unsigned long arg)
|
||||
{
|
||||
CDev *cdev = (CDev *)(filp->f_inode->i_private);
|
||||
|
||||
@@ -437,7 +437,7 @@ cdev_ioctl(struct file *filp, int cmd, unsigned long arg)
|
||||
}
|
||||
|
||||
static int
|
||||
cdev_poll(struct file *filp, struct pollfd *fds, bool setup)
|
||||
cdev_poll(file_t *filp, px4_pollfd_struct_t *fds, bool setup)
|
||||
{
|
||||
CDev *cdev = (CDev *)(filp->f_inode->i_private);
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
* Includes here should only cover the needs of the framework definitions.
|
||||
*/
|
||||
#include <px4_config.h>
|
||||
#include <px4_posix.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
@@ -59,6 +60,8 @@
|
||||
namespace device __EXPORT
|
||||
{
|
||||
|
||||
typedef struct file file_t;
|
||||
|
||||
/**
|
||||
* Fundamental base class for all device drivers.
|
||||
*
|
||||
@@ -275,7 +278,7 @@ public:
|
||||
* @param filp Pointer to the NuttX file structure.
|
||||
* @return OK if the open is allowed, -errno otherwise.
|
||||
*/
|
||||
virtual int open(struct file *filp);
|
||||
virtual int open(file_t *filp);
|
||||
|
||||
/**
|
||||
* Handle a close of the device.
|
||||
@@ -286,7 +289,7 @@ public:
|
||||
* @param filp Pointer to the NuttX file structure.
|
||||
* @return OK if the close was successful, -errno otherwise.
|
||||
*/
|
||||
virtual int close(struct file *filp);
|
||||
virtual int close(file_t *filp);
|
||||
|
||||
/**
|
||||
* Perform a read from the device.
|
||||
@@ -298,7 +301,7 @@ public:
|
||||
* @param buflen The number of bytes to be read.
|
||||
* @return The number of bytes read or -errno otherwise.
|
||||
*/
|
||||
virtual ssize_t read(struct file *filp, char *buffer, size_t buflen);
|
||||
virtual ssize_t read(file_t *filp, char *buffer, size_t buflen);
|
||||
|
||||
/**
|
||||
* Perform a write to the device.
|
||||
@@ -310,7 +313,7 @@ public:
|
||||
* @param buflen The number of bytes to be written.
|
||||
* @return The number of bytes written or -errno otherwise.
|
||||
*/
|
||||
virtual ssize_t write(struct file *filp, const char *buffer, size_t buflen);
|
||||
virtual ssize_t write(file_t *filp, const char *buffer, size_t buflen);
|
||||
|
||||
/**
|
||||
* Perform a logical seek operation on the device.
|
||||
@@ -322,7 +325,7 @@ public:
|
||||
* @param whence SEEK_OFS, SEEK_CUR or SEEK_END.
|
||||
* @return The previous offset, or -errno otherwise.
|
||||
*/
|
||||
virtual off_t seek(struct file *filp, off_t offset, int whence);
|
||||
virtual off_t seek(file_t *filp, off_t offset, int whence);
|
||||
|
||||
/**
|
||||
* Perform an ioctl operation on the device.
|
||||
@@ -336,7 +339,7 @@ public:
|
||||
* @param arg The ioctl argument value.
|
||||
* @return OK on success, or -errno otherwise.
|
||||
*/
|
||||
virtual int ioctl(struct file *filp, int cmd, unsigned long arg);
|
||||
virtual int ioctl(file_t *filp, int cmd, unsigned long arg);
|
||||
|
||||
/**
|
||||
* Perform a poll setup/teardown operation.
|
||||
@@ -349,7 +352,7 @@ public:
|
||||
* it is being torn down.
|
||||
* @return OK on success, or -errno otherwise.
|
||||
*/
|
||||
virtual int poll(struct file *filp, struct pollfd *fds, bool setup);
|
||||
virtual int poll(file_t *filp, struct pollfd *fds, bool setup);
|
||||
|
||||
/**
|
||||
* Test whether the device is currently open.
|
||||
@@ -380,7 +383,7 @@ protected:
|
||||
* @param filp The file that's interested.
|
||||
* @return The current set of poll events.
|
||||
*/
|
||||
virtual pollevent_t poll_state(struct file *filp);
|
||||
virtual pollevent_t poll_state(file_t *filp);
|
||||
|
||||
/**
|
||||
* Report new poll events.
|
||||
@@ -398,7 +401,7 @@ protected:
|
||||
* @param fds A poll waiter to notify.
|
||||
* @param events The event(s) to send to the waiter.
|
||||
*/
|
||||
virtual void poll_notify_one(struct pollfd *fds, pollevent_t events);
|
||||
virtual void poll_notify_one(px4_pollfd_struct_t *fds, pollevent_t events);
|
||||
|
||||
/**
|
||||
* Notification of the first open.
|
||||
@@ -411,7 +414,7 @@ protected:
|
||||
* @param filp Pointer to the NuttX file structure.
|
||||
* @return OK if the open should proceed, -errno otherwise.
|
||||
*/
|
||||
virtual int open_first(struct file *filp);
|
||||
virtual int open_first(file_t *filp);
|
||||
|
||||
/**
|
||||
* Notification of the last close.
|
||||
@@ -424,7 +427,7 @@ protected:
|
||||
* @param filp Pointer to the NuttX file structure.
|
||||
* @return OK if the open should return OK, -errno otherwise.
|
||||
*/
|
||||
virtual int close_last(struct file *filp);
|
||||
virtual int close_last(file_t *filp);
|
||||
|
||||
/**
|
||||
* Register a class device name, automatically adding device
|
||||
@@ -470,7 +473,7 @@ private:
|
||||
*
|
||||
* @return OK, or -errno on error.
|
||||
*/
|
||||
int store_poll_waiter(struct pollfd *fds);
|
||||
int store_poll_waiter(px4_pollfd_struct_t *fds);
|
||||
|
||||
/**
|
||||
* Remove a poll waiter.
|
||||
|
||||
@@ -221,7 +221,7 @@ I2C::transfer(struct i2c_msg *msgv, unsigned msgs)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int I2C::ioctl(device::px4_dev_handle_t *handlep, int cmd, unsigned long arg)
|
||||
int I2C::ioctl(device::file_t *filp, int cmd, unsigned long arg)
|
||||
{
|
||||
//struct i2c_rdwr_ioctl_data *packets = (i2c_rdwr_ioctl_data *)(void *)arg;
|
||||
|
||||
@@ -231,11 +231,11 @@ int I2C::ioctl(device::px4_dev_handle_t *handlep, int cmd, unsigned long arg)
|
||||
return 0;
|
||||
default:
|
||||
/* give it to the superclass */
|
||||
return VDev::ioctl(handlep, cmd, arg);
|
||||
return VDev::ioctl(filp, cmd, arg);
|
||||
}
|
||||
}
|
||||
|
||||
ssize_t I2C::read(px4_dev_handle_t *handlep, char *buffer, size_t buflen)
|
||||
ssize_t I2C::read(file_t *filp, char *buffer, size_t buflen)
|
||||
{
|
||||
if (simulate) {
|
||||
// FIXME no idea what this should be
|
||||
@@ -246,7 +246,7 @@ ssize_t I2C::read(px4_dev_handle_t *handlep, char *buffer, size_t buflen)
|
||||
return ::read(_fd, buffer, buflen);
|
||||
}
|
||||
|
||||
ssize_t I2C::write(px4_dev_handle_t *handlep, const char *buffer, size_t buflen)
|
||||
ssize_t I2C::write(file_t *filp, const char *buffer, size_t buflen)
|
||||
{
|
||||
if (simulate) {
|
||||
warnx ("2C SIM I2C::write");
|
||||
|
||||
@@ -93,9 +93,9 @@ protected:
|
||||
|
||||
virtual int init();
|
||||
|
||||
virtual ssize_t read(px4_dev_handle_t *handlep, char *buffer, size_t buflen);
|
||||
virtual ssize_t write(px4_dev_handle_t *handlep, const char *buffer, size_t buflen);
|
||||
virtual int ioctl(device::px4_dev_handle_t *handlep, int cmd, unsigned long arg);
|
||||
virtual ssize_t read(file_t *handlep, char *buffer, size_t buflen);
|
||||
virtual ssize_t write(file_t *handlep, const char *buffer, size_t buflen);
|
||||
virtual int ioctl(file_t *handlep, int cmd, unsigned long arg);
|
||||
|
||||
/**
|
||||
* Perform an I2C transaction to the device.
|
||||
|
||||
@@ -38,14 +38,15 @@
|
||||
ifeq ($(PX4_TARGET_OS),nuttx)
|
||||
SRCS = \
|
||||
device_nuttx.cpp \
|
||||
cdev_nuttx.cpp \
|
||||
cdev.cpp \
|
||||
i2c_nuttx.cpp \
|
||||
pio.cpp \
|
||||
spi.cpp \
|
||||
ringbuffer.cpp
|
||||
else
|
||||
SRCS = vdev.cpp \
|
||||
device.cpp \
|
||||
SRCS = \
|
||||
device_posix.cpp \
|
||||
vdev.cpp \
|
||||
vdev_posix.cpp \
|
||||
i2c_posix.cpp \
|
||||
sim.cpp \
|
||||
|
||||
+15
-15
@@ -207,7 +207,7 @@ out:
|
||||
* Default implementations of the character device interface
|
||||
*/
|
||||
int
|
||||
VDev::open(px4_dev_handle_t *handlep)
|
||||
VDev::open(file_t *filep)
|
||||
{
|
||||
int ret = PX4_OK;
|
||||
|
||||
@@ -219,7 +219,7 @@ VDev::open(px4_dev_handle_t *handlep)
|
||||
if (_open_count == 1) {
|
||||
|
||||
/* first-open callback may decline the open */
|
||||
ret = open_first(handlep);
|
||||
ret = open_first(filep);
|
||||
|
||||
if (ret != PX4_OK)
|
||||
_open_count--;
|
||||
@@ -231,14 +231,14 @@ VDev::open(px4_dev_handle_t *handlep)
|
||||
}
|
||||
|
||||
int
|
||||
VDev::open_first(px4_dev_handle_t *handlep)
|
||||
VDev::open_first(file_t *filep)
|
||||
{
|
||||
debug("VDev::open_first");
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
int
|
||||
VDev::close(px4_dev_handle_t *handlep)
|
||||
VDev::close(file_t *filep)
|
||||
{
|
||||
debug("VDev::close");
|
||||
int ret = PX4_OK;
|
||||
@@ -251,7 +251,7 @@ VDev::close(px4_dev_handle_t *handlep)
|
||||
|
||||
/* callback cannot decline the close */
|
||||
if (_open_count == 0)
|
||||
ret = close_last(handlep);
|
||||
ret = close_last(filep);
|
||||
|
||||
} else {
|
||||
ret = -EBADF;
|
||||
@@ -263,34 +263,34 @@ VDev::close(px4_dev_handle_t *handlep)
|
||||
}
|
||||
|
||||
int
|
||||
VDev::close_last(px4_dev_handle_t *handlep)
|
||||
VDev::close_last(file_t *filep)
|
||||
{
|
||||
debug("VDev::close_last");
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
VDev::read(px4_dev_handle_t *handlep, char *buffer, size_t buflen)
|
||||
VDev::read(file_t *filep, char *buffer, size_t buflen)
|
||||
{
|
||||
debug("VDev::read");
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
VDev::write(px4_dev_handle_t *handlep, const char *buffer, size_t buflen)
|
||||
VDev::write(file_t *filep, const char *buffer, size_t buflen)
|
||||
{
|
||||
debug("VDev::write");
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
off_t
|
||||
VDev::seek(px4_dev_handle_t *handlep, off_t offset, int whence)
|
||||
VDev::seek(file_t *filep, off_t offset, int whence)
|
||||
{
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
int
|
||||
VDev::ioctl(px4_dev_handle_t *handlep, int cmd, unsigned long arg)
|
||||
VDev::ioctl(file_t *filep, int cmd, unsigned long arg)
|
||||
{
|
||||
int ret = -ENOTTY;
|
||||
|
||||
@@ -320,7 +320,7 @@ VDev::ioctl(px4_dev_handle_t *handlep, int cmd, unsigned long arg)
|
||||
}
|
||||
|
||||
int
|
||||
VDev::poll(px4_dev_handle_t *handlep, px4_pollfd_struct_t *fds, bool setup)
|
||||
VDev::poll(file_t *filep, px4_pollfd_struct_t *fds, bool setup)
|
||||
{
|
||||
int ret = PX4_OK;
|
||||
debug("VDev::Poll %s", setup ? "setup" : "teardown");
|
||||
@@ -335,8 +335,8 @@ VDev::poll(px4_dev_handle_t *handlep, px4_pollfd_struct_t *fds, bool setup)
|
||||
* Save the file pointer in the pollfd for the subclass'
|
||||
* benefit.
|
||||
*/
|
||||
fds->priv = (void *)handlep;
|
||||
debug("VDev::poll: fds->priv = %p", handlep);
|
||||
fds->priv = (void *)filep;
|
||||
debug("VDev::poll: fds->priv = %p", filep);
|
||||
|
||||
/*
|
||||
* Handle setup requests.
|
||||
@@ -349,7 +349,7 @@ VDev::poll(px4_dev_handle_t *handlep, px4_pollfd_struct_t *fds, bool setup)
|
||||
* Check to see whether we should send a poll notification
|
||||
* immediately.
|
||||
*/
|
||||
fds->revents |= fds->events & poll_state(handlep);
|
||||
fds->revents |= fds->events & poll_state(filep);
|
||||
|
||||
/* yes? post the notification */
|
||||
if (fds->revents != 0)
|
||||
@@ -402,7 +402,7 @@ VDev::poll_notify_one(px4_pollfd_struct_t *fds, pollevent_t events)
|
||||
}
|
||||
|
||||
pollevent_t
|
||||
VDev::poll_state(px4_dev_handle_t *handlep)
|
||||
VDev::poll_state(file_t *filep)
|
||||
{
|
||||
debug("VDev::poll_notify");
|
||||
/* by default, no poll events to report */
|
||||
|
||||
+23
-26
@@ -57,17 +57,14 @@
|
||||
namespace device __EXPORT
|
||||
{
|
||||
|
||||
#define PX4_F_RDONLY 1
|
||||
#define PX4_F_WRONLY 2
|
||||
|
||||
struct px4_dev_handle_t {
|
||||
struct file_t {
|
||||
int fd;
|
||||
int flags;
|
||||
void *priv;
|
||||
void *vdev;
|
||||
|
||||
px4_dev_handle_t() : fd(-1), flags(0), priv(NULL), vdev(NULL) {}
|
||||
px4_dev_handle_t(int f, void *c, int d) : fd(d), flags(f), priv(NULL), vdev(c) {}
|
||||
file_t() : fd(-1), flags(0), priv(NULL), vdev(NULL) {}
|
||||
file_t(int f, void *c, int d) : fd(d), flags(f), priv(NULL), vdev(c) {}
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -242,13 +239,13 @@ public:
|
||||
*
|
||||
* This is handled internally and should not normally be overridden.
|
||||
*
|
||||
* @param handlep Pointer to the internal file structure.
|
||||
* @param filep Pointer to the internal file structure.
|
||||
* @param fds Poll descriptor being waited on.
|
||||
* @param setup True if this is establishing a request, false if
|
||||
* it is being torn down.
|
||||
* @return OK on success, or -errno otherwise.
|
||||
*/
|
||||
virtual int poll(px4_dev_handle_t *handlep, px4_pollfd_struct_t *fds, bool setup);
|
||||
virtual int poll(file_t *filep, px4_pollfd_struct_t *fds, bool setup);
|
||||
|
||||
/**
|
||||
* Test whether the device is currently open.
|
||||
@@ -266,10 +263,10 @@ public:
|
||||
* This function is called for every open of the device. The default
|
||||
* implementation maintains _open_count and always returns OK.
|
||||
*
|
||||
* @param handlep Pointer to the NuttX file structure.
|
||||
* @param filep Pointer to the NuttX file structure.
|
||||
* @return OK if the open is allowed, -errno otherwise.
|
||||
*/
|
||||
virtual int open(px4_dev_handle_t *handlep);
|
||||
virtual int open(file_t *filep);
|
||||
|
||||
/**
|
||||
* Handle a close of the device.
|
||||
@@ -277,46 +274,46 @@ public:
|
||||
* This function is called for every close of the device. The default
|
||||
* implementation maintains _open_count and returns OK as long as it is not zero.
|
||||
*
|
||||
* @param handlep Pointer to the NuttX file structure.
|
||||
* @param filep Pointer to the NuttX file structure.
|
||||
* @return OK if the close was successful, -errno otherwise.
|
||||
*/
|
||||
virtual int close(px4_dev_handle_t *handlep);
|
||||
virtual int close(file_t *filep);
|
||||
|
||||
/**
|
||||
* Perform a read from the device.
|
||||
*
|
||||
* The default implementation returns -ENOSYS.
|
||||
*
|
||||
* @param handlep Pointer to the NuttX file structure.
|
||||
* @param filep Pointer to the NuttX file structure.
|
||||
* @param buffer Pointer to the buffer into which data should be placed.
|
||||
* @param buflen The number of bytes to be read.
|
||||
* @return The number of bytes read or -errno otherwise.
|
||||
*/
|
||||
virtual ssize_t read(px4_dev_handle_t *handlep, char *buffer, size_t buflen);
|
||||
virtual ssize_t read(file_t *filep, char *buffer, size_t buflen);
|
||||
|
||||
/**
|
||||
* Perform a write to the device.
|
||||
*
|
||||
* The default implementation returns -ENOSYS.
|
||||
*
|
||||
* @param handlep Pointer to the NuttX file structure.
|
||||
* @param filep Pointer to the NuttX file structure.
|
||||
* @param buffer Pointer to the buffer from which data should be read.
|
||||
* @param buflen The number of bytes to be written.
|
||||
* @return The number of bytes written or -errno otherwise.
|
||||
*/
|
||||
virtual ssize_t write(px4_dev_handle_t *handlep, const char *buffer, size_t buflen);
|
||||
virtual ssize_t write(file_t *filep, const char *buffer, size_t buflen);
|
||||
|
||||
/**
|
||||
* Perform a logical seek operation on the device.
|
||||
*
|
||||
* The default implementation returns -ENOSYS.
|
||||
*
|
||||
* @param handlep Pointer to the NuttX file structure.
|
||||
* @param filep Pointer to the NuttX file structure.
|
||||
* @param offset The new file position relative to whence.
|
||||
* @param whence SEEK_OFS, SEEK_CUR or SEEK_END.
|
||||
* @return The previous offset, or -errno otherwise.
|
||||
*/
|
||||
virtual off_t seek(px4_dev_handle_t *handlep, off_t offset, int whence);
|
||||
virtual off_t seek(file_t *filep, off_t offset, int whence);
|
||||
|
||||
/**
|
||||
* Perform an ioctl operation on the device.
|
||||
@@ -325,12 +322,12 @@ public:
|
||||
* returns -ENOTTY. Subclasses should call the default implementation
|
||||
* for any command they do not handle themselves.
|
||||
*
|
||||
* @param handlep Pointer to the NuttX file structure.
|
||||
* @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(px4_dev_handle_t *handlep, int cmd, unsigned long arg);
|
||||
virtual int ioctl(file_t *filep, int cmd, unsigned long arg);
|
||||
|
||||
static VDev *getDev(const char *path);
|
||||
static void showDevices(void);
|
||||
@@ -352,10 +349,10 @@ protected:
|
||||
*
|
||||
* The default implementation returns no events.
|
||||
*
|
||||
* @param handlep The file that's interested.
|
||||
* @param filep The file that's interested.
|
||||
* @return The current set of poll events.
|
||||
*/
|
||||
virtual pollevent_t poll_state(px4_dev_handle_t *handlep);
|
||||
virtual pollevent_t poll_state(file_t *filep);
|
||||
|
||||
/**
|
||||
* Report new poll events.
|
||||
@@ -383,10 +380,10 @@ protected:
|
||||
*
|
||||
* The default implementation returns OK.
|
||||
*
|
||||
* @param handlep Pointer to the NuttX file structure.
|
||||
* @param filep Pointer to the NuttX file structure.
|
||||
* @return OK if the open should proceed, -errno otherwise.
|
||||
*/
|
||||
virtual int open_first(px4_dev_handle_t *handlep);
|
||||
virtual int open_first(file_t *filep);
|
||||
|
||||
/**
|
||||
* Notification of the last close.
|
||||
@@ -396,10 +393,10 @@ protected:
|
||||
*
|
||||
* The default implementation returns OK.
|
||||
*
|
||||
* @param handlep Pointer to the NuttX file structure.
|
||||
* @param filep Pointer to the NuttX file structure.
|
||||
* @return OK if the open should return OK, -errno otherwise.
|
||||
*/
|
||||
virtual int close_last(px4_dev_handle_t *handlep);
|
||||
virtual int close_last(file_t *filep);
|
||||
|
||||
/**
|
||||
* Register a class device name, automatically adding device
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
/**
|
||||
* @file vcdev_posix.cpp
|
||||
* @file vdev_posix.cpp
|
||||
*
|
||||
* POSIX-like API for virtual character device
|
||||
*/
|
||||
@@ -47,6 +47,8 @@
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define PX4_DEBUG(...)
|
||||
|
||||
using namespace device;
|
||||
|
||||
extern "C" {
|
||||
@@ -74,7 +76,7 @@ static void *timer_handler(void *data)
|
||||
}
|
||||
|
||||
#define PX4_MAX_FD 100
|
||||
static px4_dev_handle_t *filemap[PX4_MAX_FD] = {};
|
||||
static device::file_t *filemap[PX4_MAX_FD] = {};
|
||||
|
||||
int px4_errno;
|
||||
|
||||
@@ -95,7 +97,7 @@ int px4_open(const char *path, int flags)
|
||||
else {
|
||||
for (i=0; i<PX4_MAX_FD; ++i) {
|
||||
if (filemap[i] == 0) {
|
||||
filemap[i] = new px4_dev_handle_t(flags,dev,i);
|
||||
filemap[i] = new device::file_t(flags,dev,i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user