PX4 Firmware
PX4 Autopilot Software http://px4.io
|
Per-object device instance. More...
#include <uORBDeviceNode.hpp>
Classes | |
struct | SubscriberData |
struct | UpdateIntervalData |
Public Member Functions | |
DeviceNode (const struct orb_metadata *meta, const uint8_t instance, const char *path, uint8_t priority, uint8_t queue_size=1) | |
virtual | ~DeviceNode () |
DeviceNode (const DeviceNode &)=delete | |
DeviceNode & | operator= (const DeviceNode &)=delete |
DeviceNode (DeviceNode &&)=delete | |
DeviceNode & | operator= (DeviceNode &&)=delete |
int | open (cdev::file_t *filp) override |
Method to create a subscriber instance and return the struct pointing to the subscriber as a file pointer. More... | |
int | close (cdev::file_t *filp) override |
Method to close a subscriber for this topic. More... | |
ssize_t | read (cdev::file_t *filp, char *buffer, size_t buflen) override |
reads data from a subscriber node to the buffer provided. More... | |
ssize_t | write (cdev::file_t *filp, const char *buffer, size_t buflen) override |
writes the published data to the internal buffer to be read by subscribers later. More... | |
int | ioctl (cdev::file_t *filp, int cmd, unsigned long arg) override |
IOCTL control for the subscriber. More... | |
void | add_internal_subscriber () |
Add the subscriber to the node's list of subscriber. More... | |
void | remove_internal_subscriber () |
Removes the subscriber from the list. More... | |
bool | is_advertised () const |
Return true if this topic has been advertised. More... | |
void | mark_as_advertised () |
int | update_queue_size (unsigned int queue_size) |
Try to change the size of the queue. More... | |
bool | print_statistics (bool reset) |
Print statistics (nr of lost messages) More... | |
uint8_t | get_queue_size () const |
int8_t | subscriber_count () const |
uint32_t | lost_message_count () const |
unsigned | published_message_count () const |
const orb_metadata * | get_meta () const |
const char * | get_name () const |
uint8_t | get_instance () const |
int | get_priority () const |
void | set_priority (uint8_t priority) |
bool | copy (void *dst, unsigned &generation) |
Copies data and the corresponding generation from a node to the buffer provided. More... | |
uint64_t | copy_and_get_timestamp (void *dst, unsigned &generation) |
Copies data and the corresponding generation from a node to the buffer provided. More... | |
bool | register_callback (SubscriptionCallback *callback_sub) |
void | unregister_callback (SubscriptionCallback *callback_sub) |
Public Member Functions inherited from cdev::CDev | |
CDev (const char *devname) | |
Constructor. More... | |
CDev (const CDev &)=delete | |
CDev & | operator= (const CDev &)=delete |
CDev (CDev &&)=delete | |
CDev & | operator= (CDev &&)=delete |
virtual | ~CDev () |
virtual int | init () |
virtual off_t | seek (file_t *filep, off_t offset, int whence) |
Perform a logical seek operation on the device. More... | |
virtual int | poll (file_t *filep, px4_pollfd_struct_t *fds, bool setup) |
Perform a poll setup/teardown operation. More... | |
const char * | get_devname () const |
Get the device name. More... | |
Public Member Functions inherited from ListNode< uORB::DeviceNode *> | |
void | setSibling (uORB::DeviceNode * sibling) |
const uORB::DeviceNode * | getSibling () const |
Static Public Member Functions | |
static ssize_t | publish (const orb_metadata *meta, orb_advert_t handle, const void *data) |
Method to publish a data to this node. More... | |
static int | unadvertise (orb_advert_t handle) |
Protected Member Functions | |
pollevent_t | poll_state (cdev::file_t *filp) override |
Check the current state of the device for poll events from the perspective of the file. More... | |
void | poll_notify_one (px4_pollfd_struct_t *fds, pollevent_t events) override |
Internal implementation of poll_notify. More... | |
Protected Member Functions inherited from cdev::CDev | |
virtual void | poll_notify (pollevent_t events) |
Report new poll events. More... | |
virtual int | open_first (file_t *filep) |
Notification of the first open. More... | |
virtual int | close_last (file_t *filep) |
Notification of the last close. More... | |
virtual int | register_class_devname (const char *class_devname) |
Register a class device name, automatically adding device class instance suffix if need be. More... | |
virtual int | unregister_class_devname (const char *class_devname, unsigned class_instance) |
Register a class device name, automatically adding device class instance suffix if need be. More... | |
void | lock () |
Take the driver lock. More... | |
void | unlock () |
Release the driver lock. More... | |
int | unregister_driver_and_memory () |
First, unregisters the driver. More... | |
Private Member Functions | |
bool | copy_locked (void *dst, unsigned &generation) |
Copies data and the corresponding generation from a node to the buffer provided. More... | |
bool | appears_updated (SubscriberData *sd) |
Check whether a topic appears updated to a subscriber. More... | |
Static Private Member Functions | |
static SubscriberData * | filp_to_sd (cdev::file_t *filp) |
Private Attributes | |
const orb_metadata * | _meta |
object metadata information More... | |
const uint8_t | _instance |
orb multi instance identifier More... | |
uint8_t * | _data {nullptr} |
allocated object buffer More... | |
hrt_abstime | _last_update {0} |
time the object was last updated More... | |
px4::atomic< unsigned > | _generation {0} |
object generation count More... | |
List< uORB::SubscriptionCallback * > | _callbacks |
uint8_t | _priority |
priority of the topic More... | |
bool | _advertised {false} |
has ever been advertised (not necessarily published data yet) More... | |
uint8_t | _queue_size |
maximum number of elements in the queue More... | |
int8_t | _subscriber_count {0} |
uint32_t | _lost_messages = 0 |
nr of lost messages for all subscribers. More... | |
Additional Inherited Members | |
Protected Attributes inherited from cdev::CDev | |
px4_sem_t | _lock |
lock to protect access to all class members (also for derived classes) More... | |
Protected Attributes inherited from ListNode< uORB::DeviceNode *> | |
uORB::DeviceNode * | _list_node_sibling |
Static Protected Attributes inherited from cdev::CDev | |
static const px4_file_operations_t | fops = {} |
Pointer to the default cdev file operations table; useful for registering clone devices etc. More... | |
Per-object device instance.
Definition at line 55 of file uORBDeviceNode.hpp.
uORB::DeviceNode::DeviceNode | ( | const struct orb_metadata * | meta, |
const uint8_t | instance, | ||
const char * | path, | ||
uint8_t | priority, | ||
uint8_t | queue_size = 1 |
||
) |
Definition at line 57 of file uORBDeviceNode.cpp.
|
virtual |
Definition at line 67 of file uORBDeviceNode.cpp.
References _data.
|
delete |
|
delete |
void uORB::DeviceNode::add_internal_subscriber | ( | ) |
Add the subscriber to the node's list of subscriber.
If there is remote proxy to which this subscription needs to be sent, it will done via uORBCommunicator::IChannel interface.
sd | the subscriber to be added. |
Definition at line 551 of file uORBDeviceNode.cpp.
References _meta, _subscriber_count, uORBCommunicator::IChannel::add_subscription(), uORB::Manager::get_instance(), cdev::CDev::lock(), orb_metadata::o_name, and cdev::CDev::unlock().
Referenced by open(), and uORB::Subscription::subscribe().
|
private |
Check whether a topic appears updated to a subscriber.
Lock must already be held when calling this.
sd | The subscriber for whom to check. |
Definition at line 512 of file uORBDeviceNode.cpp.
References _data, uORB::DeviceNode::SubscriberData::generation, hrt_elapsed_time(), uORB::DeviceNode::UpdateIntervalData::interval, uORB::DeviceNode::UpdateIntervalData::last_update, published_message_count(), and uORB::DeviceNode::SubscriberData::update_interval.
Referenced by ioctl(), poll_notify_one(), and poll_state().
|
overridevirtual |
Method to close a subscriber for this topic.
Reimplemented from cdev::CDev.
Definition at line 125 of file uORBDeviceNode.cpp.
References cdev::file_t::f_oflags, filp_to_sd(), and remove_internal_subscriber().
bool uORB::DeviceNode::copy | ( | void * | dst, |
unsigned & | generation | ||
) |
Copies data and the corresponding generation from a node to the buffer provided.
dst | The buffer into which the data is copied. |
generation | The generation that was copied. |
Definition at line 175 of file uORBDeviceNode.cpp.
References ATOMIC_ENTER, ATOMIC_LEAVE, and copy_locked().
Referenced by uORB::Subscription::copy(), and set_priority().
uint64_t uORB::DeviceNode::copy_and_get_timestamp | ( | void * | dst, |
unsigned & | generation | ||
) |
Copies data and the corresponding generation from a node to the buffer provided.
dst | The buffer into which the data is copied. If topic was not updated since last check it will return false but still copy the data. |
generation | The generation that was copied. |
Definition at line 187 of file uORBDeviceNode.cpp.
References _last_update, ATOMIC_ENTER, ATOMIC_LEAVE, copy_locked(), and hrt_abstime.
Referenced by set_priority(), and uORB::Subscription::update().
|
private |
Copies data and the corresponding generation from a node to the buffer provided.
Caller handles locking.
dst | The buffer into which the data is copied. |
generation | The generation that was copied. |
Definition at line 142 of file uORBDeviceNode.cpp.
References _data, _generation, _lost_messages, _meta, _queue_size, and orb_metadata::o_size.
Referenced by copy(), copy_and_get_timestamp(), read(), and set_priority().
|
inlinestaticprivate |
Definition at line 45 of file uORBDeviceNode.cpp.
References cdev::file_t::f_priv.
Referenced by close(), ioctl(), poll_notify_one(), poll_state(), and read().
|
inline |
Definition at line 197 of file uORBDeviceNode.hpp.
References _instance.
Referenced by uORB::DeviceMaster::showTop().
|
inline |
Definition at line 193 of file uORBDeviceNode.hpp.
References _meta.
Referenced by uORB::DeviceMaster::addNewDeviceNodes(), and uORB::DeviceMaster::showTop().
|
inline |
Definition at line 195 of file uORBDeviceNode.hpp.
References _meta, and orb_metadata::o_name.
|
inline |
Definition at line 199 of file uORBDeviceNode.hpp.
References _priority.
Referenced by ioctl().
|
inline |
Definition at line 185 of file uORBDeviceNode.hpp.
References _queue_size.
Referenced by uORB::DeviceMaster::showTop(), and uORB::Subscription::subscribe().
|
overridevirtual |
IOCTL control for the subscriber.
Reimplemented from cdev::CDev.
Definition at line 300 of file uORBDeviceNode.cpp.
References _advertised, _last_update, appears_updated(), ATOMIC_ENTER, ATOMIC_LEAVE, filp_to_sd(), get_priority(), hrt_abstime, uORB::DeviceNode::UpdateIntervalData::interval, cdev::CDev::lock(), OK, ORBIOCGADVERTISER, ORBIOCGETINTERVAL, ORBIOCGPRIORITY, ORBIOCISADVERTISED, ORBIOCLASTUPDATE, ORBIOCSETINTERVAL, ORBIOCSETQUEUESIZE, ORBIOCUPDATED, cdev::CDev::unlock(), uORB::DeviceNode::SubscriberData::update_interval, and update_queue_size().
|
inline |
Return true if this topic has been advertised.
This is used in the case of multi_pub/sub to check if it's valid to advertise and publish to this node or if another node should be tried.
Definition at line 165 of file uORBDeviceNode.hpp.
References _advertised.
Referenced by uORB::DeviceMaster::advertise(), uORB::Subscription::advertised(), and uORB::Manager::orb_exists().
|
inline |
Definition at line 189 of file uORBDeviceNode.hpp.
References _lost_messages.
Referenced by uORB::DeviceMaster::addNewDeviceNodes(), and uORB::DeviceMaster::showTop().
|
inline |
Definition at line 167 of file uORBDeviceNode.hpp.
References _advertised, print_statistics(), lps22hb::reset(), and update_queue_size().
Referenced by uORB::DeviceMaster::advertise(), and open().
|
overridevirtual |
Method to create a subscriber instance and return the struct pointing to the subscriber as a file pointer.
Reimplemented from cdev::CDev.
Definition at line 75 of file uORBDeviceNode.cpp.
References _queue_size, add_internal_subscriber(), cdev::file_t::f_oflags, cdev::file_t::f_priv, uORB::DeviceNode::SubscriberData::generation, cdev::CDev::lock(), mark_as_advertised(), published_message_count(), and cdev::CDev::unlock().
|
delete |
|
delete |
|
overrideprotectedvirtual |
Internal implementation of poll_notify.
fds | A poll waiter to notify. |
events | The event(s) to send to the waiter. |
Reimplemented from cdev::CDev.
Definition at line 499 of file uORBDeviceNode.cpp.
References appears_updated(), and filp_to_sd().
Referenced by set_priority().
|
overrideprotectedvirtual |
Check the current state of the device for poll events from the perspective of the file.
This function is called by the default poll() implementation when a poll is set up to determine whether the poll should return immediately.
The default implementation returns no events.
filep | The file that's interested. |
Reimplemented from cdev::CDev.
Definition at line 484 of file uORBDeviceNode.cpp.
References appears_updated(), and filp_to_sd().
Referenced by set_priority().
bool uORB::DeviceNode::print_statistics | ( | bool | reset | ) |
Print statistics (nr of lost messages)
reset | if true, reset statistics afterwards |
Definition at line 531 of file uORBDeviceNode.cpp.
References _lost_messages, _meta, cdev::CDev::lock(), orb_metadata::o_name, and cdev::CDev::unlock().
Referenced by mark_as_advertised(), and uORB::DeviceMaster::printStatistics().
|
static |
Method to publish a data to this node.
Definition at line 386 of file uORBDeviceNode.cpp.
References _meta, uORB::Manager::get_instance(), orb_metadata::o_name, orb_metadata::o_size, uORBCommunicator::IChannel::send_message(), and write().
Referenced by uORB::Manager::orb_publish().
|
inline |
Definition at line 191 of file uORBDeviceNode.hpp.
References _generation.
Referenced by uORB::DeviceMaster::addNewDeviceNodes(), appears_updated(), open(), uORB::DeviceMaster::showTop(), uORB::Subscription::subscribe(), and uORB::Subscription::updated().
|
overridevirtual |
reads data from a subscriber node to the buffer provided.
filp | The subscriber from which the data needs to be read from. |
buffer | The buffer into which the data is read into. |
buflen | the length of the buffer |
Reimplemented from cdev::CDev.
Definition at line 200 of file uORBDeviceNode.cpp.
References _data, _last_update, _meta, ATOMIC_ENTER, ATOMIC_LEAVE, copy_locked(), filp_to_sd(), uORB::DeviceNode::SubscriberData::generation, uORB::DeviceNode::UpdateIntervalData::last_update, orb_metadata::o_size, and uORB::DeviceNode::SubscriberData::update_interval.
bool uORB::DeviceNode::register_callback | ( | uORB::SubscriptionCallback * | callback_sub | ) |
Definition at line 651 of file uORBDeviceNode.cpp.
References _callbacks, ATOMIC_ENTER, and ATOMIC_LEAVE.
Referenced by uORB::SubscriptionCallback::registerCallback(), and set_priority().
void uORB::DeviceNode::remove_internal_subscriber | ( | ) |
Removes the subscriber from the list.
Also notifies the remote if there a uORBCommunicator::IChannel instance.
sd | the Subscriber to be removed. |
Definition at line 571 of file uORBDeviceNode.cpp.
References _data, _meta, _subscriber_count, data, uORB::Manager::get_instance(), cdev::CDev::lock(), orb_metadata::o_name, orb_metadata::o_size, uORBCommunicator::IChannel::remove_subscription(), uORBCommunicator::IChannel::send_message(), cdev::CDev::unlock(), and write().
Referenced by close(), and uORB::Subscription::unsubscribe().
|
inline |
Definition at line 200 of file uORBDeviceNode.hpp.
References _priority, copy(), copy_and_get_timestamp(), copy_locked(), poll_notify_one(), poll_state(), register_callback(), and unregister_callback().
Referenced by uORB::DeviceMaster::advertise().
|
inline |
Definition at line 187 of file uORBDeviceNode.hpp.
References _subscriber_count.
Referenced by uORB::DeviceMaster::showTop().
|
static |
Definition at line 434 of file uORBDeviceNode.cpp.
References _advertised, uORB::Manager::get_instance(), orb_metadata::o_name, and uORBCommunicator::IChannel::topic_advertised().
Referenced by uORB::Manager::orb_unadvertise().
void uORB::DeviceNode::unregister_callback | ( | uORB::SubscriptionCallback * | callback_sub | ) |
Definition at line 673 of file uORBDeviceNode.cpp.
References _callbacks, ATOMIC_ENTER, and ATOMIC_LEAVE.
Referenced by set_priority(), and uORB::SubscriptionCallback::unregisterCallback().
int uORB::DeviceNode::update_queue_size | ( | unsigned int | queue_size | ) |
Try to change the size of the queue.
This can only be done as long as nobody published yet. This is the case, for example when orb_subscribe was called before an orb_advertise. The queue size can only be increased.
queue_size | new size of the queue |
Definition at line 635 of file uORBDeviceNode.cpp.
References _data, and _queue_size.
Referenced by ioctl(), and mark_as_advertised().
|
overridevirtual |
writes the published data to the internal buffer to be read by subscribers later.
filp | the subscriber; this is not used. |
buffer | The buffer for the input data |
buflen | the length of the buffer. |
Reimplemented from cdev::CDev.
Definition at line 232 of file uORBDeviceNode.cpp.
References _callbacks, _data, _generation, _last_update, _meta, _queue_size, ATOMIC_ENTER, ATOMIC_LEAVE, hrt_absolute_time(), cdev::CDev::lock(), orb_metadata::o_size, cdev::CDev::poll_notify(), and cdev::CDev::unlock().
Referenced by publish(), and remove_internal_subscriber().
|
private |
has ever been advertised (not necessarily published data yet)
Definition at line 276 of file uORBDeviceNode.hpp.
Referenced by ioctl(), is_advertised(), mark_as_advertised(), and unadvertise().
|
private |
Definition at line 274 of file uORBDeviceNode.hpp.
Referenced by register_callback(), unregister_callback(), and write().
|
private |
allocated object buffer
Definition at line 271 of file uORBDeviceNode.hpp.
Referenced by appears_updated(), copy_locked(), read(), remove_internal_subscriber(), update_queue_size(), write(), and ~DeviceNode().
|
private |
object generation count
Definition at line 273 of file uORBDeviceNode.hpp.
Referenced by copy_locked(), published_message_count(), and write().
|
private |
orb multi instance identifier
Definition at line 270 of file uORBDeviceNode.hpp.
Referenced by get_instance().
|
private |
time the object was last updated
Definition at line 272 of file uORBDeviceNode.hpp.
Referenced by copy_and_get_timestamp(), ioctl(), read(), and write().
|
private |
nr of lost messages for all subscribers.
If two subscribers lose the same message, it is counted as two.
Definition at line 281 of file uORBDeviceNode.hpp.
Referenced by copy_locked(), lost_message_count(), and print_statistics().
|
private |
object metadata information
Definition at line 269 of file uORBDeviceNode.hpp.
Referenced by add_internal_subscriber(), copy_locked(), get_meta(), get_name(), print_statistics(), publish(), read(), remove_internal_subscriber(), and write().
|
private |
priority of the topic
Definition at line 275 of file uORBDeviceNode.hpp.
Referenced by get_priority(), and set_priority().
|
private |
maximum number of elements in the queue
Definition at line 277 of file uORBDeviceNode.hpp.
Referenced by copy_locked(), get_queue_size(), open(), update_queue_size(), and write().
|
private |
Definition at line 278 of file uORBDeviceNode.hpp.
Referenced by add_internal_subscriber(), remove_internal_subscriber(), and subscriber_count().