system/uorb: support new api
orb_advertise_multi_queue_persist Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
parent
37f1e453b1
commit
f02c5a5d7e
@ -73,6 +73,7 @@ static int orb_advsub_open(FAR const struct orb_metadata *meta, int flags,
|
|||||||
reginfo.path = path;
|
reginfo.path = path;
|
||||||
reginfo.esize = meta->o_size;
|
reginfo.esize = meta->o_size;
|
||||||
reginfo.nbuffer = queue_size;
|
reginfo.nbuffer = queue_size;
|
||||||
|
reginfo.persist = !!(flags & SENSOR_PERSIST);
|
||||||
|
|
||||||
fd = open(ORB_USENSOR_PATH, O_WRONLY);
|
fd = open(ORB_USENSOR_PATH, O_WRONLY);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
@ -111,26 +112,10 @@ static int orb_advsub_open(FAR const struct orb_metadata *meta, int flags,
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
static int
|
||||||
* Public Functions
|
orb_advertise_multi_queue_flags(FAR const struct orb_metadata *meta,
|
||||||
****************************************************************************/
|
FAR const void *data, FAR int *instance,
|
||||||
|
unsigned int queue_size, int flags)
|
||||||
int orb_open(FAR const char *name, int instance, int flags)
|
|
||||||
{
|
|
||||||
char path[ORB_PATH_MAX];
|
|
||||||
|
|
||||||
snprintf(path, ORB_PATH_MAX, ORB_SENSOR_PATH"%s%d", name, instance);
|
|
||||||
return open(path, O_CLOEXEC | flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
int orb_close(int fd)
|
|
||||||
{
|
|
||||||
return close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
int orb_advertise_multi_queue(FAR const struct orb_metadata *meta,
|
|
||||||
FAR const void *data, FAR int *instance,
|
|
||||||
unsigned int queue_size)
|
|
||||||
{
|
{
|
||||||
int inst;
|
int inst;
|
||||||
int fd;
|
int fd;
|
||||||
@ -139,7 +124,7 @@ int orb_advertise_multi_queue(FAR const struct orb_metadata *meta,
|
|||||||
|
|
||||||
inst = instance ? *instance : orb_group_count(meta);
|
inst = instance ? *instance : orb_group_count(meta);
|
||||||
|
|
||||||
fd = orb_advsub_open(meta, O_WRONLY, inst, queue_size);
|
fd = orb_advsub_open(meta, flags, inst, queue_size);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
{
|
{
|
||||||
uorberr("%s advertise failed (%i)", meta->o_name, fd);
|
uorberr("%s advertise failed (%i)", meta->o_name, fd);
|
||||||
@ -165,6 +150,40 @@ int orb_advertise_multi_queue(FAR const struct orb_metadata *meta,
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int orb_open(FAR const char *name, int instance, int flags)
|
||||||
|
{
|
||||||
|
char path[ORB_PATH_MAX];
|
||||||
|
|
||||||
|
snprintf(path, ORB_PATH_MAX, ORB_SENSOR_PATH"%s%d", name, instance);
|
||||||
|
return open(path, O_CLOEXEC | flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
int orb_close(int fd)
|
||||||
|
{
|
||||||
|
return close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
int orb_advertise_multi_queue(FAR const struct orb_metadata *meta,
|
||||||
|
FAR const void *data, FAR int *instance,
|
||||||
|
unsigned int queue_size)
|
||||||
|
{
|
||||||
|
return orb_advertise_multi_queue_flags(meta, data, instance,
|
||||||
|
queue_size, O_WRONLY);
|
||||||
|
}
|
||||||
|
|
||||||
|
int orb_advertise_multi_queue_persist(FAR const struct orb_metadata *meta,
|
||||||
|
FAR const void *data,
|
||||||
|
FAR int *instance,
|
||||||
|
unsigned int queue_size)
|
||||||
|
{
|
||||||
|
return orb_advertise_multi_queue_flags(meta, data, instance, queue_size,
|
||||||
|
O_WRONLY | SENSOR_PERSIST);
|
||||||
|
}
|
||||||
|
|
||||||
ssize_t orb_publish_multi(int fd, const void *data, size_t len)
|
ssize_t orb_publish_multi(int fd, const void *data, size_t len)
|
||||||
{
|
{
|
||||||
return write(fd, data, len);
|
return write(fd, data, len);
|
||||||
|
@ -256,6 +256,33 @@ static inline int orb_advertise_multi(FAR const struct orb_metadata *meta,
|
|||||||
return orb_advertise_multi_queue(meta, data, instance, 1);
|
return orb_advertise_multi_queue(meta, data, instance, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: orb_advertise_multi_queue_persist
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* orb_advertise_multi_queue_persist is similar to orb_advertise_mult and
|
||||||
|
* it can ensures that every subscriber has access to current and
|
||||||
|
* future data.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* meta The uORB metadata (usually from the ORB_ID() macro)
|
||||||
|
* data A pointer to the initial data to be published.
|
||||||
|
* instance Pointer to an integer which yield the instance ID,
|
||||||
|
* (has default 0 if pointer is NULL).
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* -1 on error, otherwise returns an file descriptor
|
||||||
|
* that can be used to publish to the topic.
|
||||||
|
* 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_advertise_multi_queue_persist(FAR const struct orb_metadata *meta,
|
||||||
|
FAR const void *data,
|
||||||
|
FAR int *instance,
|
||||||
|
unsigned int queue_size);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: orb_unadvertise
|
* Name: orb_unadvertise
|
||||||
*
|
*
|
||||||
@ -316,7 +343,7 @@ static inline int orb_publish_auto(FAR const struct orb_metadata *meta,
|
|||||||
{
|
{
|
||||||
int tmp;
|
int tmp;
|
||||||
|
|
||||||
tmp = orb_advertise_multi(meta, data, instance);
|
tmp = orb_advertise_multi_queue_persist(meta, data, instance, 1);
|
||||||
if (tmp < 0)
|
if (tmp < 0)
|
||||||
{
|
{
|
||||||
return tmp;
|
return tmp;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user