uORB move to standalone CDev

- uORB topics should not be Devices with bus, address, device id
This commit is contained in:
Daniel Agar
2018-08-27 13:14:15 -04:00
parent a2f4757e31
commit dbf2d25e2f
9 changed files with 49 additions and 68 deletions
+4 -4
View File
@@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
* *
* Copyright (c) 2012-2017 PX4 Development Team. All rights reserved. * Copyright (c) 2012-2018 PX4 Development Team. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@@ -272,7 +272,7 @@ private:
bool _registered{false}; /**< true if device name was registered */ bool _registered{false}; /**< true if device name was registered */
uint8_t _max_pollwaiters{0}; /**< size of the _pollset array */ uint8_t _max_pollwaiters{0}; /**< size of the _pollset array */
uint8_t _open_count{0}; /**< number of successful opens */ uint16_t _open_count{0}; /**< number of successful opens */
/** /**
* Store a pollwaiter in a slot where we can find it later. * Store a pollwaiter in a slot where we can find it later.
@@ -281,14 +281,14 @@ private:
* *
* @return OK, or -errno on error. * @return OK, or -errno on error.
*/ */
int store_poll_waiter(px4_pollfd_struct_t *fds); inline int store_poll_waiter(px4_pollfd_struct_t *fds);
/** /**
* Remove a poll waiter. * Remove a poll waiter.
* *
* @return OK, or -errno on error. * @return OK, or -errno on error.
*/ */
int remove_poll_waiter(px4_pollfd_struct_t *fds); inline int remove_poll_waiter(px4_pollfd_struct_t *fds);
/* do not allow copying this class */ /* do not allow copying this class */
CDev(const CDev &); CDev(const CDev &);
+1 -2
View File
@@ -34,7 +34,6 @@
#ifndef _uORBCommon_hpp_ #ifndef _uORBCommon_hpp_
#define _uORBCommon_hpp_ #define _uORBCommon_hpp_
#include <drivers/device/device.h>
#include <drivers/drv_orb_dev.h> #include <drivers/drv_orb_dev.h>
#include <systemlib/err.h> #include <systemlib/err.h>
#include "uORB.h" #include "uORB.h"
@@ -43,7 +42,7 @@
namespace uORB namespace uORB
{ {
static const unsigned orb_maxpath = 64; static constexpr unsigned orb_maxpath = 64;
struct orb_advertdata { struct orb_advertdata {
const struct orb_metadata *meta; const struct orb_metadata *meta;
+3 -7
View File
@@ -61,16 +61,14 @@
UNUSED(node_name_str); UNUSED(node_name_str);
#endif #endif
using namespace device;
uORB::DeviceMaster::DeviceMaster() : uORB::DeviceMaster::DeviceMaster() :
CDev("obj_master", TOPIC_MASTER_DEVICE_PATH) CDev(TOPIC_MASTER_DEVICE_PATH)
{ {
_last_statistics_output = hrt_absolute_time(); _last_statistics_output = hrt_absolute_time();
} }
int int
uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg) uORB::DeviceMaster::ioctl(cdev::file_t *filp, int cmd, unsigned long arg)
{ {
int ret; int ret;
@@ -114,8 +112,6 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg)
*(adv->instance) = group_tries; *(adv->instance) = group_tries;
} }
const char *objname = meta->o_name; //no need for a copy, meta->o_name will never be freed or changed
/* driver wants a permanent copy of the path, so make one here */ /* driver wants a permanent copy of the path, so make one here */
const char *devpath = strdup(nodepath); const char *devpath = strdup(nodepath);
@@ -124,7 +120,7 @@ uORB::DeviceMaster::ioctl(device::file_t *filp, int cmd, unsigned long arg)
} }
/* construct the new node */ /* construct the new node */
uORB::DeviceNode *node = new uORB::DeviceNode(meta, objname, devpath, adv->priority); uORB::DeviceNode *node = new uORB::DeviceNode(meta, devpath, adv->priority);
/* if we didn't get a device, that's bad */ /* if we didn't get a device, that's bad */
if (node == nullptr) { if (node == nullptr) {
+3 -2
View File
@@ -35,6 +35,7 @@
#include <stdint.h> #include <stdint.h>
#include "uORBCommon.hpp" #include "uORBCommon.hpp"
#include <lib/cdev/CDev.hpp>
namespace uORB namespace uORB
{ {
@@ -61,10 +62,10 @@ class Manager;
* Used primarily to create new objects via the ORBIOCCREATE * Used primarily to create new objects via the ORBIOCCREATE
* ioctl. * ioctl.
*/ */
class uORB::DeviceMaster : public device::CDev class uORB::DeviceMaster : public cdev::CDev
{ {
public: public:
virtual int ioctl(device::file_t *filp, int cmd, unsigned long arg); virtual int ioctl(cdev::file_t *filp, int cmd, unsigned long arg);
/** /**
* Public interface for getDeviceNodeLocked(). Takes care of synchronization. * Public interface for getDeviceNodeLocked(). Takes care of synchronization.
+10 -13
View File
@@ -49,9 +49,7 @@
#include "uORBCommunicator.hpp" #include "uORBCommunicator.hpp"
#endif /* ORB_COMMUNICATOR */ #endif /* ORB_COMMUNICATOR */
using namespace device; uORB::DeviceNode::SubscriberData *uORB::DeviceNode::filp_to_sd(cdev::file_t *filp)
uORB::DeviceNode::SubscriberData *uORB::DeviceNode::filp_to_sd(device::file_t *filp)
{ {
#ifndef __PX4_NUTTX #ifndef __PX4_NUTTX
@@ -63,9 +61,8 @@ uORB::DeviceNode::SubscriberData *uORB::DeviceNode::filp_to_sd(device::file_t *f
return (SubscriberData *)(FILE_PRIV(filp)); return (SubscriberData *)(FILE_PRIV(filp));
} }
uORB::DeviceNode::DeviceNode(const struct orb_metadata *meta, const char *name, const char *path, uORB::DeviceNode::DeviceNode(const struct orb_metadata *meta, const char *path, int priority, unsigned int queue_size) :
int priority, unsigned int queue_size) : CDev(path),
CDev(name, path),
_meta(meta), _meta(meta),
_priority((uint8_t)priority), _priority((uint8_t)priority),
_queue_size(queue_size) _queue_size(queue_size)
@@ -80,7 +77,7 @@ uORB::DeviceNode::~DeviceNode()
} }
int int
uORB::DeviceNode::open(device::file_t *filp) uORB::DeviceNode::open(cdev::file_t *filp)
{ {
int ret; int ret;
@@ -152,7 +149,7 @@ uORB::DeviceNode::open(device::file_t *filp)
} }
int int
uORB::DeviceNode::close(device::file_t *filp) uORB::DeviceNode::close(cdev::file_t *filp)
{ {
/* is this the publisher closing? */ /* is this the publisher closing? */
if (px4_getpid() == _publisher) { if (px4_getpid() == _publisher) {
@@ -177,7 +174,7 @@ uORB::DeviceNode::close(device::file_t *filp)
} }
ssize_t ssize_t
uORB::DeviceNode::read(device::file_t *filp, char *buffer, size_t buflen) uORB::DeviceNode::read(cdev::file_t *filp, char *buffer, size_t buflen)
{ {
SubscriberData *sd = (SubscriberData *)filp_to_sd(filp); SubscriberData *sd = (SubscriberData *)filp_to_sd(filp);
@@ -233,7 +230,7 @@ uORB::DeviceNode::read(device::file_t *filp, char *buffer, size_t buflen)
} }
ssize_t ssize_t
uORB::DeviceNode::write(device::file_t *filp, const char *buffer, size_t buflen) uORB::DeviceNode::write(cdev::file_t *filp, const char *buffer, size_t buflen)
{ {
/* /*
* Writes are legal from interrupt context as long as the * Writes are legal from interrupt context as long as the
@@ -301,7 +298,7 @@ uORB::DeviceNode::write(device::file_t *filp, const char *buffer, size_t buflen)
} }
int int
uORB::DeviceNode::ioctl(device::file_t *filp, int cmd, unsigned long arg) uORB::DeviceNode::ioctl(cdev::file_t *filp, int cmd, unsigned long arg)
{ {
SubscriberData *sd = filp_to_sd(filp); SubscriberData *sd = filp_to_sd(filp);
@@ -493,7 +490,7 @@ int16_t uORB::DeviceNode::topic_unadvertised(const orb_metadata *meta, int prior
#endif /* ORB_COMMUNICATOR */ #endif /* ORB_COMMUNICATOR */
pollevent_t pollevent_t
uORB::DeviceNode::poll_state(device::file_t *filp) uORB::DeviceNode::poll_state(cdev::file_t *filp)
{ {
SubscriberData *sd = filp_to_sd(filp); SubscriberData *sd = filp_to_sd(filp);
@@ -510,7 +507,7 @@ uORB::DeviceNode::poll_state(device::file_t *filp)
void void
uORB::DeviceNode::poll_notify_one(px4_pollfd_struct_t *fds, pollevent_t events) uORB::DeviceNode::poll_notify_one(px4_pollfd_struct_t *fds, pollevent_t events)
{ {
SubscriberData *sd = filp_to_sd((device::file_t *)fds->priv); SubscriberData *sd = filp_to_sd((cdev::file_t *)fds->priv);
/* /*
* If the topic looks updated to the subscriber, go ahead and notify them. * If the topic looks updated to the subscriber, go ahead and notify them.
+9 -10
View File
@@ -46,23 +46,22 @@ class Manager;
/** /**
* Per-object device instance. * Per-object device instance.
*/ */
class uORB::DeviceNode : public device::CDev class uORB::DeviceNode : public cdev::CDev
{ {
public: public:
DeviceNode(const struct orb_metadata *meta, const char *name, const char *path, DeviceNode(const struct orb_metadata *meta, const char *path, int priority, unsigned int queue_size = 1);
int priority, unsigned int queue_size = 1);
~DeviceNode(); ~DeviceNode();
/** /**
* Method to create a subscriber instance and return the struct * Method to create a subscriber instance and return the struct
* pointing to the subscriber as a file pointer. * pointing to the subscriber as a file pointer.
*/ */
virtual int open(device::file_t *filp); virtual int open(cdev::file_t *filp);
/** /**
* Method to close a subscriber for this topic. * Method to close a subscriber for this topic.
*/ */
virtual int close(device::file_t *filp); virtual int close(cdev::file_t *filp);
/** /**
* reads data from a subscriber node to the buffer provided. * reads data from a subscriber node to the buffer provided.
@@ -75,7 +74,7 @@ public:
* @return * @return
* ssize_t the number of bytes read. * ssize_t the number of bytes read.
*/ */
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);
/** /**
* writes the published data to the internal buffer to be read by * writes the published data to the internal buffer to be read by
@@ -89,12 +88,12 @@ public:
* @return ssize_t * @return ssize_t
* The number of bytes that are written * The number of bytes that are written
*/ */
virtual ssize_t write(device::file_t *filp, const char *buffer, size_t buflen); virtual ssize_t write(cdev::file_t *filp, const char *buffer, size_t buflen);
/** /**
* IOCTL control for the subscriber. * IOCTL control for the subscriber.
*/ */
virtual int ioctl(device::file_t *filp, int cmd, unsigned long arg); virtual int ioctl(cdev::file_t *filp, int cmd, unsigned long arg);
/** /**
* Method to publish a data to this node. * Method to publish a data to this node.
@@ -177,7 +176,7 @@ public:
void set_priority(uint8_t priority) { _priority = priority; } void set_priority(uint8_t priority) { _priority = priority; }
protected: protected:
virtual pollevent_t poll_state(device::file_t *filp); virtual pollevent_t poll_state(cdev::file_t *filp);
virtual void poll_notify_one(px4_pollfd_struct_t *fds, pollevent_t events); virtual void poll_notify_one(px4_pollfd_struct_t *fds, pollevent_t events);
private: private:
@@ -211,7 +210,7 @@ private:
uint8_t _queue_size; /**< maximum number of elements in the queue */ uint8_t _queue_size; /**< maximum number of elements in the queue */
int8_t _subscriber_count{0}; int8_t _subscriber_count{0};
inline static SubscriberData *filp_to_sd(device::file_t *filp); inline static SubscriberData *filp_to_sd(cdev::file_t *filp);
#ifdef __PX4_NUTTX #ifdef __PX4_NUTTX
pid_t _publisher {0}; /**< if nonzero, current publisher. Only used inside the advertise call. pid_t _publisher {0}; /**< if nonzero, current publisher. Only used inside the advertise call.
+6 -6
View File
@@ -187,11 +187,8 @@ orb_advert_t uORB::Manager::orb_advertise_multi(const struct orb_metadata *meta,
#endif /* ORB_USE_PUBLISHER_RULES */ #endif /* ORB_USE_PUBLISHER_RULES */
int result, fd;
orb_advert_t advertiser;
/* open the node as an advertiser */ /* open the node as an advertiser */
fd = node_open(meta, data, true, instance, priority); int fd = node_open(meta, data, true, instance, priority);
if (fd == PX4_ERROR) { if (fd == PX4_ERROR) {
PX4_ERR("%s advertise failed", meta->o_name); PX4_ERR("%s advertise failed", meta->o_name);
@@ -201,13 +198,15 @@ orb_advert_t uORB::Manager::orb_advertise_multi(const struct orb_metadata *meta,
/* Set the queue size. This must be done before the first publication; thus it fails if /* Set the queue size. This must be done before the first publication; thus it fails if
* this is not the first advertiser. * this is not the first advertiser.
*/ */
result = px4_ioctl(fd, ORBIOCSETQUEUESIZE, (unsigned long)queue_size); int result = px4_ioctl(fd, ORBIOCSETQUEUESIZE, (unsigned long)queue_size);
if (result < 0 && queue_size > 1) { if (result < 0 && queue_size > 1) {
PX4_WARN("orb_advertise_multi: failed to set queue size"); PX4_WARN("orb_advertise_multi: failed to set queue size");
} }
/* get the advertiser handle and close the node */ /* get the advertiser handle and close the node */
orb_advert_t advertiser;
result = px4_ioctl(fd, ORBIOCGADVERTISER, (unsigned long)&advertiser); result = px4_ioctl(fd, ORBIOCGADVERTISER, (unsigned long)&advertiser);
px4_close(fd); px4_close(fd);
@@ -357,7 +356,8 @@ int uORB::Manager::node_open(const struct orb_metadata *meta, const void *data,
int priority) int priority)
{ {
char path[orb_maxpath]; char path[orb_maxpath];
int fd = -1, ret; int fd = -1;
int ret = -1;
/* /*
* If meta is null, the object was not defined, i.e. it is not * If meta is null, the object was not defined, i.e. it is not
@@ -38,6 +38,7 @@
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <poll.h> #include <poll.h>
#include <lib/cdev/CDev.hpp>
ORB_DEFINE(orb_test, struct orb_test, sizeof(orb_test), "ORB_TEST:int val;hrt_abstime time;"); ORB_DEFINE(orb_test, struct orb_test, sizeof(orb_test), "ORB_TEST:int val;hrt_abstime time;");
ORB_DEFINE(orb_multitest, struct orb_test, sizeof(orb_test), "ORB_MULTITEST:int val;hrt_abstime time;"); ORB_DEFINE(orb_multitest, struct orb_test, sizeof(orb_test), "ORB_MULTITEST:int val;hrt_abstime time;");
@@ -43,14 +43,12 @@
#include <px4_time.h> #include <px4_time.h>
#include "vcdevtest_example.h" #include "vcdevtest_example.h"
#include <drivers/drv_device.h> #include <drivers/drv_device.h>
#include <drivers/device/device.h> #include <lib/cdev/CDev.hpp>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
px4::AppState VCDevExample::appState; px4::AppState VCDevExample::appState;
using namespace device;
#define TESTDEV "/dev/vdevtest" #define TESTDEV "/dev/vdevtest"
static bool g_exit = false; static bool g_exit = false;
@@ -99,27 +97,27 @@ public:
size_t _read_offset; size_t _read_offset;
}; };
class VCDevNode : public CDev class VCDevNode : public cdev::CDev
{ {
public: public:
VCDevNode() : VCDevNode() :
CDev("vcdevtest", TESTDEV), CDev(TESTDEV),
_is_open_for_write(false), _is_open_for_write(false),
_write_offset(0) {} _write_offset(0) {}
~VCDevNode() = default; ~VCDevNode() = default;
virtual int open(device::file_t *handlep); virtual int open(cdev::file_t *handlep);
virtual int close(device::file_t *handlep); virtual int close(cdev::file_t *handlep);
virtual ssize_t write(device::file_t *handlep, const char *buffer, size_t buflen); virtual ssize_t write(cdev::file_t *handlep, const char *buffer, size_t buflen);
virtual ssize_t read(device::file_t *handlep, char *buffer, size_t buflen); virtual ssize_t read(cdev::file_t *handlep, char *buffer, size_t buflen);
private: private:
bool _is_open_for_write; bool _is_open_for_write;
size_t _write_offset; size_t _write_offset;
char _buf[1000]; char _buf[1000];
}; };
int VCDevNode::open(device::file_t *handlep) int VCDevNode::open(cdev::file_t *handlep)
{ {
// Only allow one writer // Only allow one writer
if (_is_open_for_write && (handlep->flags & PX4_F_WRONLY)) { if (_is_open_for_write && (handlep->flags & PX4_F_WRONLY)) {
@@ -142,7 +140,7 @@ int VCDevNode::open(device::file_t *handlep)
return 0; return 0;
} }
int VCDevNode::close(device::file_t *handlep) int VCDevNode::close(cdev::file_t *handlep)
{ {
delete (PrivData *)handlep->priv; delete (PrivData *)handlep->priv;
handlep->priv = nullptr; handlep->priv = nullptr;
@@ -156,7 +154,7 @@ int VCDevNode::close(device::file_t *handlep)
return 0; return 0;
} }
ssize_t VCDevNode::write(device::file_t *handlep, const char *buffer, size_t buflen) ssize_t VCDevNode::write(cdev::file_t *handlep, const char *buffer, size_t buflen)
{ {
for (size_t i = 0; i < buflen && _write_offset < 1000; i++) { for (size_t i = 0; i < buflen && _write_offset < 1000; i++) {
_buf[_write_offset] = buffer[i]; _buf[_write_offset] = buffer[i];
@@ -169,7 +167,7 @@ ssize_t VCDevNode::write(device::file_t *handlep, const char *buffer, size_t buf
return buflen; return buflen;
} }
ssize_t VCDevNode::read(device::file_t *handlep, char *buffer, size_t buflen) ssize_t VCDevNode::read(cdev::file_t *handlep, char *buffer, size_t buflen)
{ {
PrivData *p = (PrivData *)handlep->priv; PrivData *p = (PrivData *)handlep->priv;
ssize_t chars_read = 0; ssize_t chars_read = 0;
@@ -289,17 +287,7 @@ int VCDevExample::main()
return -px4_errno; return -px4_errno;
} }
void *p = nullptr; int ret = test_pub_block(fd, 1);
int ret = px4_ioctl(fd, DIOC_GETPRIV, (unsigned long)&p);
if (ret < 0) {
PX4_INFO("ioctl DIOC_GETPRIV failed %d %d", ret, px4_errno);
return -px4_errno;
}
PX4_INFO("priv data = %p %s", p, p == (void *)_node ? "PASS" : "FAIL");
ret = test_pub_block(fd, 1);
if (ret < 0) { if (ret < 0) {
return ret; return ret;