Browse Source

Modify uORB API to allow cleaner in-app use

sbg
Lorenz Meier 9 years ago
parent
commit
36a556d107
  1. 38
      src/modules/uORB/uORB.cpp
  2. 23
      src/modules/uORB/uORB.h

38
src/modules/uORB/uORB.cpp

@ -96,6 +96,44 @@ orb_advert_t orb_advertise_multi(const struct orb_metadata *meta, const void *da @@ -96,6 +96,44 @@ orb_advert_t orb_advertise_multi(const struct orb_metadata *meta, const void *da
return uORB::Manager::get_instance()->orb_advertise_multi(meta, data, instance, priority);
}
/**
* Advertise as the publisher of a topic.
*
* This performs the initial advertisement of a topic; it creates the topic
* node in /obj if required and publishes the initial data.
*
* Any number of advertisers may publish to a topic; publications are atomic
* but co-ordination between publishers is not provided by the ORB.
*
* @param meta The uORB metadata (usually from the ORB_ID() macro)
* for the topic.
* @param data A pointer to the initial data to be published.
* For topics updated by interrupt handlers, the advertisement
* must be performed from non-interrupt context.
* @param instance Pointer to an integer which will yield the instance ID (0-based)
* of the publication.
* @param priority The priority of the instance. If a subscriber subscribes multiple
* instances, the priority allows the subscriber to prioritize the best
* data source as long as its available.
* @return ERROR on error, zero on success.
* If the topic in question is not known (due to an
* ORB_DEFINE with no corresponding ORB_DECLARE)
* this function will return -1 and set errno to ENOENT.
*/
int orb_publish_auto(const struct orb_metadata *meta, orb_advert_t *handle, const void *data, int *instance,
int priority)
{
if (*handle == nullptr) {
*handle = orb_advertise_multi(meta, data, instance, priority);
if (handle != nullptr) {
return 0;
}
} else {
return orb_publish(meta, handle, data);
}
}
/**
* Publish new data to a topic.

23
src/modules/uORB/uORB.h

@ -181,6 +181,29 @@ extern orb_advert_t orb_advertise(const struct orb_metadata *meta, const void *d @@ -181,6 +181,29 @@ extern orb_advert_t orb_advertise(const struct orb_metadata *meta, const void *d
extern orb_advert_t orb_advertise_multi(const struct orb_metadata *meta, const void *data, int *instance,
int priority) __EXPORT;
/**
* Advertise and publish as the publisher of a topic.
*
* This performs the initial advertisement of a topic; it creates the topic
* node in /obj if required and publishes the initial data.
*
* Any number of advertisers may publish to a topic; publications are atomic
* but co-ordination between publishers is not provided by the ORB.
*
* @param meta The uORB metadata (usually from the ORB_ID() macro)
* for the topic.
* @param data A pointer to the initial data to be published.
* For topics updated by interrupt handlers, the advertisement
* must be performed from non-interrupt context.
* @param instance Pointer to an integer which will yield the instance ID (0-based,
* limited by ORB_MULTI_MAX_INSTANCES) of the publication.
* @param priority The priority of the instance. If a subscriber subscribes multiple
* instances, the priority allows the subscriber to prioritize the best
* data source as long as its available.
* @return zero on success, error number on failure
*/
extern int orb_publish_auto(const struct orb_metadata *meta, orb_advert_t *handle, const void *data, int *instance,
int priority)
/**
* Publish new data to a topic.

Loading…
Cancel
Save