|
|
|
@ -43,8 +43,8 @@
@@ -43,8 +43,8 @@
|
|
|
|
|
|
|
|
|
|
namespace uORB |
|
|
|
|
{ |
|
|
|
|
class DeviceNode; |
|
|
|
|
class DeviceMaster; |
|
|
|
|
class DeviceNode; |
|
|
|
|
class DeviceMaster; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -53,166 +53,167 @@ namespace uORB
@@ -53,166 +53,167 @@ namespace uORB
|
|
|
|
|
class uORB::DeviceNode : public device::CDev |
|
|
|
|
{ |
|
|
|
|
public: |
|
|
|
|
/**
|
|
|
|
|
* Constructor |
|
|
|
|
*/ |
|
|
|
|
DeviceNode |
|
|
|
|
( |
|
|
|
|
const struct orb_metadata *meta, |
|
|
|
|
const char *name, |
|
|
|
|
const char *path, |
|
|
|
|
int priority |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Destructor |
|
|
|
|
*/ |
|
|
|
|
~DeviceNode(); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method to create a subscriber instance and return the struct
|
|
|
|
|
* pointing to the subscriber as a file pointer. |
|
|
|
|
*/ |
|
|
|
|
virtual int open(struct file *filp); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method to close a subscriber for this topic. |
|
|
|
|
*/ |
|
|
|
|
virtual int close(struct file *filp); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* reads data from a subscriber node to the buffer provided. |
|
|
|
|
* @param filp |
|
|
|
|
* The subscriber from which the data needs to be read from. |
|
|
|
|
* @param buffer |
|
|
|
|
* The buffer into which the data is read into. |
|
|
|
|
* @param buflen |
|
|
|
|
* the length of the buffer |
|
|
|
|
* @return |
|
|
|
|
* ssize_t the number of bytes read. |
|
|
|
|
*/ |
|
|
|
|
virtual ssize_t read(struct file *filp, char *buffer, size_t buflen); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* writes the published data to the internal buffer to be read by |
|
|
|
|
* subscribers later. |
|
|
|
|
* @param filp |
|
|
|
|
* the subscriber; this is not used. |
|
|
|
|
* @param buffer |
|
|
|
|
* The buffer for the input data |
|
|
|
|
* @param buflen |
|
|
|
|
* the length of the buffer. |
|
|
|
|
* @return ssize_t |
|
|
|
|
* The number of bytes that are written |
|
|
|
|
*/ |
|
|
|
|
virtual ssize_t write(struct file *filp, const char *buffer, size_t buflen); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* IOCTL control for the subscriber. |
|
|
|
|
*/ |
|
|
|
|
virtual int ioctl(struct file *filp, int cmd, unsigned long arg); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method to publish a data to this node. |
|
|
|
|
*/ |
|
|
|
|
static ssize_t publish |
|
|
|
|
( |
|
|
|
|
const orb_metadata *meta, |
|
|
|
|
orb_advert_t handle, |
|
|
|
|
const void *data |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* processes a request for add subscription from remote |
|
|
|
|
* @param rateInHz |
|
|
|
|
* Specifies the desired rate for the message. |
|
|
|
|
* @return |
|
|
|
|
* 0 = success |
|
|
|
|
* otherwise failure. |
|
|
|
|
*/ |
|
|
|
|
int16_t process_add_subscription( int32_t rateInHz ); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* processes a request to remove a subscription from remote. |
|
|
|
|
*/ |
|
|
|
|
int16_t process_remove_subscription(); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* processed the received data message from remote. |
|
|
|
|
*/ |
|
|
|
|
int16_t process_received_message( int32_t length, uint8_t* data ); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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. |
|
|
|
|
* @param sd |
|
|
|
|
* the subscriber to be added. |
|
|
|
|
*/ |
|
|
|
|
void add_internal_subscriber(); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes the subscriber from the list. Also notifies the remote |
|
|
|
|
* if there a uORBCommunicator::IChannel instance. |
|
|
|
|
* @param sd |
|
|
|
|
* the Subscriber to be removed. |
|
|
|
|
*/ |
|
|
|
|
void remove_internal_subscriber(); |
|
|
|
|
/**
|
|
|
|
|
* Constructor |
|
|
|
|
*/ |
|
|
|
|
DeviceNode |
|
|
|
|
( |
|
|
|
|
const struct orb_metadata *meta, |
|
|
|
|
const char *name, |
|
|
|
|
const char *path, |
|
|
|
|
int priority |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Destructor |
|
|
|
|
*/ |
|
|
|
|
~DeviceNode(); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method to create a subscriber instance and return the struct
|
|
|
|
|
* pointing to the subscriber as a file pointer. |
|
|
|
|
*/ |
|
|
|
|
virtual int open(struct file *filp); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method to close a subscriber for this topic. |
|
|
|
|
*/ |
|
|
|
|
virtual int close(struct file *filp); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* reads data from a subscriber node to the buffer provided. |
|
|
|
|
* @param filp |
|
|
|
|
* The subscriber from which the data needs to be read from. |
|
|
|
|
* @param buffer |
|
|
|
|
* The buffer into which the data is read into. |
|
|
|
|
* @param buflen |
|
|
|
|
* the length of the buffer |
|
|
|
|
* @return |
|
|
|
|
* ssize_t the number of bytes read. |
|
|
|
|
*/ |
|
|
|
|
virtual ssize_t read(struct file *filp, char *buffer, size_t buflen); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* writes the published data to the internal buffer to be read by |
|
|
|
|
* subscribers later. |
|
|
|
|
* @param filp |
|
|
|
|
* the subscriber; this is not used. |
|
|
|
|
* @param buffer |
|
|
|
|
* The buffer for the input data |
|
|
|
|
* @param buflen |
|
|
|
|
* the length of the buffer. |
|
|
|
|
* @return ssize_t |
|
|
|
|
* The number of bytes that are written |
|
|
|
|
*/ |
|
|
|
|
virtual ssize_t write(struct file *filp, const char *buffer, size_t buflen); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* IOCTL control for the subscriber. |
|
|
|
|
*/ |
|
|
|
|
virtual int ioctl(struct file *filp, int cmd, unsigned long arg); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method to publish a data to this node. |
|
|
|
|
*/ |
|
|
|
|
static ssize_t publish |
|
|
|
|
( |
|
|
|
|
const orb_metadata *meta, |
|
|
|
|
orb_advert_t handle, |
|
|
|
|
const void *data |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* processes a request for add subscription from remote |
|
|
|
|
* @param rateInHz |
|
|
|
|
* Specifies the desired rate for the message. |
|
|
|
|
* @return |
|
|
|
|
* 0 = success |
|
|
|
|
* otherwise failure. |
|
|
|
|
*/ |
|
|
|
|
int16_t process_add_subscription(int32_t rateInHz); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* processes a request to remove a subscription from remote. |
|
|
|
|
*/ |
|
|
|
|
int16_t process_remove_subscription(); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* processed the received data message from remote. |
|
|
|
|
*/ |
|
|
|
|
int16_t process_received_message(int32_t length, uint8_t *data); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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. |
|
|
|
|
* @param sd |
|
|
|
|
* the subscriber to be added. |
|
|
|
|
*/ |
|
|
|
|
void add_internal_subscriber(); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes the subscriber from the list. Also notifies the remote |
|
|
|
|
* if there a uORBCommunicator::IChannel instance. |
|
|
|
|
* @param sd |
|
|
|
|
* the Subscriber to be removed. |
|
|
|
|
*/ |
|
|
|
|
void remove_internal_subscriber(); |
|
|
|
|
|
|
|
|
|
protected: |
|
|
|
|
virtual pollevent_t poll_state(struct file *filp); |
|
|
|
|
virtual void poll_notify_one(struct pollfd *fds, pollevent_t events); |
|
|
|
|
virtual pollevent_t poll_state(struct file *filp); |
|
|
|
|
virtual void poll_notify_one(struct pollfd *fds, pollevent_t events); |
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
struct SubscriberData { |
|
|
|
|
unsigned generation; /**< last generation the subscriber has seen */ |
|
|
|
|
unsigned update_interval; /**< if nonzero minimum interval between updates */ |
|
|
|
|
struct hrt_call update_call; /**< deferred wakeup call if update_period is nonzero */ |
|
|
|
|
void *poll_priv; /**< saved copy of fds->f_priv while poll is active */ |
|
|
|
|
bool update_reported; /**< true if we have reported the update via poll/check */ |
|
|
|
|
int priority; /**< priority of publisher */ |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const struct orb_metadata *_meta; /**< object metadata information */ |
|
|
|
|
uint8_t *_data; /**< allocated object buffer */ |
|
|
|
|
hrt_abstime _last_update; /**< time the object was last updated */ |
|
|
|
|
volatile unsigned _generation; /**< object generation count */ |
|
|
|
|
pid_t _publisher; /**< if nonzero, current publisher */ |
|
|
|
|
const int _priority; /**< priority of topic */ |
|
|
|
|
struct SubscriberData { |
|
|
|
|
unsigned generation; /**< last generation the subscriber has seen */ |
|
|
|
|
unsigned update_interval; /**< if nonzero minimum interval between updates */ |
|
|
|
|
struct hrt_call update_call; /**< deferred wakeup call if update_period is nonzero */ |
|
|
|
|
void *poll_priv; /**< saved copy of fds->f_priv while poll is active */ |
|
|
|
|
bool update_reported; /**< true if we have reported the update via poll/check */ |
|
|
|
|
int priority; /**< priority of publisher */ |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const struct orb_metadata *_meta; /**< object metadata information */ |
|
|
|
|
uint8_t *_data; /**< allocated object buffer */ |
|
|
|
|
hrt_abstime _last_update; /**< time the object was last updated */ |
|
|
|
|
volatile unsigned _generation; /**< object generation count */ |
|
|
|
|
pid_t _publisher; /**< if nonzero, current publisher */ |
|
|
|
|
const int _priority; /**< priority of topic */ |
|
|
|
|
|
|
|
|
|
private: // private class methods.
|
|
|
|
|
|
|
|
|
|
SubscriberData *filp_to_sd(struct file *filp) { |
|
|
|
|
SubscriberData *sd = (SubscriberData *)(filp->f_priv); |
|
|
|
|
return sd; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool _IsRemoteSubscriberPresent; |
|
|
|
|
int32_t _subscriber_count; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Perform a deferred update for a rate-limited subscriber. |
|
|
|
|
*/ |
|
|
|
|
void update_deferred(); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Bridge from hrt_call to update_deferred |
|
|
|
|
* |
|
|
|
|
* void *arg ORBDevNode pointer for which the deferred update is performed. |
|
|
|
|
*/ |
|
|
|
|
static void update_deferred_trampoline(void *arg); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check whether a topic appears updated to a subscriber. |
|
|
|
|
* |
|
|
|
|
* @param sd The subscriber for whom to check. |
|
|
|
|
* @return True if the topic should appear updated to the subscriber |
|
|
|
|
*/ |
|
|
|
|
bool appears_updated(SubscriberData *sd); |
|
|
|
|
|
|
|
|
|
// disable copy and assignment operators
|
|
|
|
|
DeviceNode( const DeviceNode& ); |
|
|
|
|
DeviceNode& operator=( const DeviceNode& ); |
|
|
|
|
SubscriberData *filp_to_sd(struct file *filp) |
|
|
|
|
{ |
|
|
|
|
SubscriberData *sd = (SubscriberData *)(filp->f_priv); |
|
|
|
|
return sd; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool _IsRemoteSubscriberPresent; |
|
|
|
|
int32_t _subscriber_count; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Perform a deferred update for a rate-limited subscriber. |
|
|
|
|
*/ |
|
|
|
|
void update_deferred(); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Bridge from hrt_call to update_deferred |
|
|
|
|
* |
|
|
|
|
* void *arg ORBDevNode pointer for which the deferred update is performed. |
|
|
|
|
*/ |
|
|
|
|
static void update_deferred_trampoline(void *arg); |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check whether a topic appears updated to a subscriber. |
|
|
|
|
* |
|
|
|
|
* @param sd The subscriber for whom to check. |
|
|
|
|
* @return True if the topic should appear updated to the subscriber |
|
|
|
|
*/ |
|
|
|
|
bool appears_updated(SubscriberData *sd); |
|
|
|
|
|
|
|
|
|
// disable copy and assignment operators
|
|
|
|
|
DeviceNode(const DeviceNode &); |
|
|
|
|
DeviceNode &operator=(const DeviceNode &); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -224,14 +225,14 @@ private: // private class methods.
@@ -224,14 +225,14 @@ private: // private class methods.
|
|
|
|
|
class uORB::DeviceMaster : public device::CDev |
|
|
|
|
{ |
|
|
|
|
public: |
|
|
|
|
DeviceMaster(Flavor f); |
|
|
|
|
virtual ~DeviceMaster(); |
|
|
|
|
DeviceMaster(Flavor f); |
|
|
|
|
virtual ~DeviceMaster(); |
|
|
|
|
|
|
|
|
|
static uORB::DeviceNode* GetDeviceNode( const char * node_name ); |
|
|
|
|
virtual int ioctl(struct file *filp, int cmd, unsigned long arg); |
|
|
|
|
static uORB::DeviceNode *GetDeviceNode(const char *node_name); |
|
|
|
|
virtual int ioctl(struct file *filp, int cmd, unsigned long arg); |
|
|
|
|
private: |
|
|
|
|
Flavor _flavor; |
|
|
|
|
static ORBMap _node_map; |
|
|
|
|
Flavor _flavor; |
|
|
|
|
static ORBMap _node_map; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|