mirror of
https://gitee.com/xiaohuolufeihua/bizhang_-obav.git
synced 2026-05-22 09:28:58 +00:00
orb: add optional queuing of messages
This adds two uORB API calls: - orb_advertise_queue - orb_advertise_multi_queue Both add a queue_size parameter to define a maximum number of buffered item. The existing orb calls use all a queue size of one and thus their behavior is unchanged. If a writer publishes too fast, the oldest elements from the queue are silently dropped. The returned timestamp is always the one from the latest message in the queue. Queue size can be set via ioctl during advertisement phase. After that it cannot be changed anymore.
This commit is contained in:
@@ -87,14 +87,14 @@ int uORB::Manager::orb_exists(const struct orb_metadata *meta, int instance)
|
||||
#endif
|
||||
}
|
||||
|
||||
orb_advert_t uORB::Manager::orb_advertise(const struct orb_metadata *meta, const void *data)
|
||||
orb_advert_t uORB::Manager::orb_advertise(const struct orb_metadata *meta, const void *data, int queue_size)
|
||||
{
|
||||
//warnx("orb_advertise meta = %p", meta);
|
||||
return orb_advertise_multi(meta, data, nullptr, ORB_PRIO_DEFAULT);
|
||||
return orb_advertise_multi(meta, data, nullptr, ORB_PRIO_DEFAULT, queue_size);
|
||||
}
|
||||
|
||||
orb_advert_t uORB::Manager::orb_advertise_multi(const struct orb_metadata *meta, const void *data, int *instance,
|
||||
int priority)
|
||||
int priority, int queue_size)
|
||||
{
|
||||
int result, fd;
|
||||
orb_advert_t advertiser;
|
||||
@@ -109,6 +109,15 @@ orb_advert_t uORB::Manager::orb_advertise_multi(const struct orb_metadata *meta,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* Set the queue size. This must be done before the first publication; thus it fails if
|
||||
* this is not the first advertiser.
|
||||
*/
|
||||
result = px4_ioctl(fd, ORBIOCSETQUEUESIZE, (unsigned long)queue_size);
|
||||
|
||||
if (result < 0 && queue_size > 1) {
|
||||
PX4_WARN("orb_advertise_multi: failed to set queue size");
|
||||
}
|
||||
|
||||
/* get the advertiser handle and close the node */
|
||||
result = px4_ioctl(fd, ORBIOCGADVERTISER, (unsigned long)&advertiser);
|
||||
px4_close(fd);
|
||||
|
||||
Reference in New Issue
Block a user