mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-27 10:20:35 +08:00
mavlink: replace MavlinkOrbSubscription with uORB::Subscription
* uORB orb_stat() and update(uint64_t *time, void *dst) are now obsolete and have been deleted * mavlink messages add more advertised checks in streams get_size() check to improve data rate calculation across different scenarios
This commit is contained in:
@@ -94,19 +94,4 @@ void Subscription::unsubscribe()
|
||||
_last_generation = 0;
|
||||
}
|
||||
|
||||
bool Subscription::update(uint64_t *time, void *dst)
|
||||
{
|
||||
if ((time != nullptr) && (dst != nullptr) && advertised()) {
|
||||
// always copy data to dst regardless of update
|
||||
const uint64_t t = _node->copy_and_get_timestamp(dst, _last_generation);
|
||||
|
||||
if (*time == 0 || *time != t) {
|
||||
*time = t;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace uORB
|
||||
|
||||
@@ -118,17 +118,6 @@ public:
|
||||
*/
|
||||
bool update(void *dst) { return updated() ? copy(dst) : false; }
|
||||
|
||||
/**
|
||||
* Check if subscription updated based on timestamp.
|
||||
*
|
||||
* @return true only if topic was updated based on a timestamp and
|
||||
* copied to buffer successfully.
|
||||
* If topic was not updated since last check it will return false but
|
||||
* still copy the data.
|
||||
* If no data available data buffer will be filled with zeros.
|
||||
*/
|
||||
bool update(uint64_t *time, void *dst);
|
||||
|
||||
/**
|
||||
* Copy the struct
|
||||
* @param data The uORB message struct we are updating.
|
||||
|
||||
@@ -97,11 +97,6 @@ int orb_check(int handle, bool *updated)
|
||||
return uORB::Manager::get_instance()->orb_check(handle, updated);
|
||||
}
|
||||
|
||||
int orb_stat(int handle, uint64_t *time)
|
||||
{
|
||||
return uORB::Manager::get_instance()->orb_stat(handle, time);
|
||||
}
|
||||
|
||||
int orb_exists(const struct orb_metadata *meta, int instance)
|
||||
{
|
||||
return uORB::Manager::get_instance()->orb_exists(meta, instance);
|
||||
|
||||
@@ -221,11 +221,6 @@ extern int orb_copy(const struct orb_metadata *meta, int handle, void *buffer) _
|
||||
*/
|
||||
extern int orb_check(int handle, bool *updated) __EXPORT;
|
||||
|
||||
/**
|
||||
* @see uORB::Manager::orb_stat()
|
||||
*/
|
||||
extern int orb_stat(int handle, uint64_t *time) __EXPORT;
|
||||
|
||||
/**
|
||||
* @see uORB::Manager::orb_exists()
|
||||
*/
|
||||
|
||||
@@ -183,19 +183,6 @@ uORB::DeviceNode::copy(void *dst, unsigned &generation)
|
||||
return updated;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
uORB::DeviceNode::copy_and_get_timestamp(void *dst, unsigned &generation)
|
||||
{
|
||||
ATOMIC_ENTER;
|
||||
|
||||
const hrt_abstime update_time = _last_update;
|
||||
copy_locked(dst, generation);
|
||||
|
||||
ATOMIC_LEAVE;
|
||||
|
||||
return update_time;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
uORB::DeviceNode::read(cdev::file_t *filp, char *buffer, size_t buflen)
|
||||
{
|
||||
@@ -216,13 +203,13 @@ uORB::DeviceNode::read(cdev::file_t *filp, char *buffer, size_t buflen)
|
||||
*/
|
||||
ATOMIC_ENTER;
|
||||
|
||||
copy_locked(buffer, sd->generation);
|
||||
|
||||
// if subscriber has an interval track the last update time
|
||||
if (sd->update_interval) {
|
||||
sd->update_interval->last_update = _last_update;
|
||||
sd->update_interval->last_update = hrt_absolute_time();
|
||||
}
|
||||
|
||||
copy_locked(buffer, sd->generation);
|
||||
|
||||
ATOMIC_LEAVE;
|
||||
|
||||
return _meta->o_size;
|
||||
@@ -279,10 +266,6 @@ uORB::DeviceNode::write(cdev::file_t *filp, const char *buffer, size_t buflen)
|
||||
|
||||
memcpy(_data + (_meta->o_size * (generation % _queue_size)), buffer, _meta->o_size);
|
||||
|
||||
/* update the timestamp and generation count */
|
||||
_last_update = hrt_absolute_time();
|
||||
|
||||
|
||||
// callbacks
|
||||
for (auto item : _callbacks) {
|
||||
item->call();
|
||||
@@ -302,13 +285,6 @@ uORB::DeviceNode::ioctl(cdev::file_t *filp, int cmd, unsigned long arg)
|
||||
SubscriberData *sd = filp_to_sd(filp);
|
||||
|
||||
switch (cmd) {
|
||||
case ORBIOCLASTUPDATE: {
|
||||
ATOMIC_ENTER;
|
||||
*(hrt_abstime *)arg = _last_update;
|
||||
ATOMIC_LEAVE;
|
||||
return PX4_OK;
|
||||
}
|
||||
|
||||
case ORBIOCUPDATED: {
|
||||
ATOMIC_ENTER;
|
||||
*(bool *)arg = appears_updated(sd);
|
||||
|
||||
@@ -214,21 +214,6 @@ public:
|
||||
*/
|
||||
bool copy(void *dst, unsigned &generation);
|
||||
|
||||
/**
|
||||
* Copies data and the corresponding generation
|
||||
* from a node to the buffer provided.
|
||||
*
|
||||
* @param 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.
|
||||
* @param generation
|
||||
* The generation that was copied.
|
||||
* @return uint64_t
|
||||
* Returns the timestamp of the copied data.
|
||||
*/
|
||||
uint64_t copy_and_get_timestamp(void *dst, unsigned &generation);
|
||||
|
||||
// add item to list of work items to schedule on node update
|
||||
bool register_callback(SubscriptionCallback *callback_sub);
|
||||
|
||||
@@ -269,20 +254,21 @@ private:
|
||||
};
|
||||
|
||||
const orb_metadata *_meta; /**< object metadata information */
|
||||
const uint8_t _instance; /**< orb multi instance identifier */
|
||||
|
||||
uint8_t *_data{nullptr}; /**< allocated object buffer */
|
||||
hrt_abstime _last_update{0}; /**< time the object was last updated */
|
||||
px4::atomic<unsigned> _generation{0}; /**< object generation count */
|
||||
List<uORB::SubscriptionCallback *> _callbacks;
|
||||
uint8_t _priority; /**< priority of the topic */
|
||||
bool _advertised{false}; /**< has ever been advertised (not necessarily published data yet) */
|
||||
uint8_t _queue_size; /**< maximum number of elements in the queue */
|
||||
int8_t _subscriber_count{0};
|
||||
|
||||
// statistics
|
||||
uint32_t _lost_messages = 0; /**< nr of lost messages for all subscribers. If two subscribers lose the same
|
||||
message, it is counted as two. */
|
||||
|
||||
const uint8_t _instance; /**< orb multi instance identifier */
|
||||
uint8_t _priority; /**< priority of the topic */
|
||||
bool _advertised{false}; /**< has ever been advertised (not necessarily published data yet) */
|
||||
uint8_t _queue_size; /**< maximum number of elements in the queue */
|
||||
int8_t _subscriber_count{0};
|
||||
|
||||
inline static SubscriberData *filp_to_sd(cdev::file_t *filp);
|
||||
|
||||
/**
|
||||
|
||||
@@ -305,11 +305,6 @@ int uORB::Manager::orb_check(int handle, bool *updated)
|
||||
return px4_ioctl(handle, ORBIOCUPDATED, (unsigned long)(uintptr_t)updated);
|
||||
}
|
||||
|
||||
int uORB::Manager::orb_stat(int handle, uint64_t *time)
|
||||
{
|
||||
return px4_ioctl(handle, ORBIOCLASTUPDATE, (unsigned long)(uintptr_t)time);
|
||||
}
|
||||
|
||||
int uORB::Manager::orb_priority(int handle, int32_t *priority)
|
||||
{
|
||||
return px4_ioctl(handle, ORBIOCGPRIORITY, (unsigned long)(uintptr_t)priority);
|
||||
|
||||
@@ -177,7 +177,7 @@ public:
|
||||
*
|
||||
* The data is atomically published to the topic and any waiting subscribers
|
||||
* will be notified. Subscribers that are not waiting can check the topic
|
||||
* for updates using orb_check and/or orb_stat.
|
||||
* for updates using orb_check.
|
||||
*
|
||||
* @param meta The uORB metadata (usually from the ORB_ID() macro)
|
||||
* for the topic.
|
||||
@@ -192,7 +192,7 @@ public:
|
||||
*
|
||||
* The returned value is a file descriptor that can be passed to poll()
|
||||
* in order to wait for updates to a topic, as well as topic_read,
|
||||
* orb_check and orb_stat.
|
||||
* orb_check.
|
||||
*
|
||||
* If there were any publications of the topic prior to the subscription,
|
||||
* an orb_check right after orb_subscribe will return true.
|
||||
@@ -222,7 +222,7 @@ public:
|
||||
*
|
||||
* The returned value is a file descriptor that can be passed to poll()
|
||||
* in order to wait for updates to a topic, as well as topic_read,
|
||||
* orb_check and orb_stat.
|
||||
* orb_check.
|
||||
*
|
||||
* If there were any publications of the topic prior to the subscription,
|
||||
* an orb_check right after orb_subscribe_multi will return true.
|
||||
@@ -289,9 +289,7 @@ public:
|
||||
* topic is likely to have updated.
|
||||
*
|
||||
* Updates are tracked on a per-handle basis; this call will continue to
|
||||
* return true until orb_copy is called using the same handle. This interface
|
||||
* should be preferred over calling orb_stat due to the race window between
|
||||
* stat and copy that can lead to missed updates.
|
||||
* return true until orb_copy is called using the same handle.
|
||||
*
|
||||
* @param handle A handle returned from orb_subscribe.
|
||||
* @param updated Set to true if the topic has been updated since the
|
||||
@@ -301,17 +299,6 @@ public:
|
||||
*/
|
||||
int orb_check(int handle, bool *updated);
|
||||
|
||||
/**
|
||||
* Return the last time that the topic was updated. If a queue is used, it returns
|
||||
* the timestamp of the latest element in the queue.
|
||||
*
|
||||
* @param handle A handle returned from orb_subscribe.
|
||||
* @param time Returns the absolute time that the topic was updated, or zero if it has
|
||||
* never been updated. Time is measured in microseconds.
|
||||
* @return OK on success, PX4_ERROR otherwise with errno set accordingly.
|
||||
*/
|
||||
int orb_stat(int handle, uint64_t *time);
|
||||
|
||||
/**
|
||||
* Check if a topic has already been created and published (advertised)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user