Skip to content

Commit a551612

Browse files
Donny9xiaoxiang781216
authored andcommitted
uorb/flush: support flush operation
After you call orb_flush(), you can determine whether the flush is completed by listening to the POLLPRI event of fd and getting the event in orb_get_events. After calling orb_get_events, the flush events will be cleared. Signed-off-by: dongjiuzhu1 <[email protected]>
1 parent b0b4ac0 commit a551612

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

system/uorb/uORB/uORB.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,16 @@ int orb_get_state(int fd, FAR struct orb_state *state)
229229
return ret;
230230
}
231231

232+
int orb_get_events(int fd, FAR unsigned int *events)
233+
{
234+
if (!events)
235+
{
236+
return -EINVAL;
237+
}
238+
239+
return ioctl(fd, SNIOC_GET_EVENTS, (unsigned long)(uintptr_t)events);
240+
}
241+
232242
int orb_check(int fd, FAR bool *updated)
233243
{
234244
return ioctl(fd, SNIOC_UPDATED, (unsigned long)(uintptr_t)updated);
@@ -239,6 +249,11 @@ int orb_ioctl(int fd, int cmd, unsigned long arg)
239249
return ioctl(fd, cmd, arg);
240250
}
241251

252+
int orb_flush(int fd)
253+
{
254+
return ioctl(fd, SNIOC_FLUSH, 0);
255+
}
256+
242257
int orb_set_interval(int fd, unsigned interval)
243258
{
244259
return ioctl(fd, SNIOC_SET_INTERVAL, (unsigned long)interval);

system/uorb/uORB/uORB.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ struct orb_handle_s
114114
* Pre-processor Definitions
115115
****************************************************************************/
116116

117+
#define ORB_EVENT_FLUSH_COMPLETE SENSOR_EVENT_FLUSH_COMPLETE
118+
117119
#define ORB_SENSOR_PATH "/dev/uorb/"
118120
#define ORB_USENSOR_PATH "/dev/usensor"
119121
#define ORB_PATH_MAX (NAME_MAX + 16)
@@ -521,6 +523,23 @@ static inline int orb_copy(FAR const struct orb_metadata *meta,
521523

522524
int orb_get_state(int fd, FAR struct orb_state *state);
523525

526+
/****************************************************************************
527+
* Name: orb_get_events
528+
*
529+
* Description:
530+
* Get the events about the specify subscriber of topic.
531+
*
532+
* Input Parameters:
533+
* fd The fd returned from orb_advertise / orb_subscribe.
534+
* events Pointer to events, type is unsigned int pointer.
535+
* eg: ORB_EVENT_FLUSH_COMPLETE
536+
*
537+
* Returned Value:
538+
* -1 on error.
539+
****************************************************************************/
540+
541+
int orb_get_events(int fd, FAR unsigned int *events);
542+
524543
/****************************************************************************
525544
* Name: orb_check
526545
*
@@ -563,6 +582,27 @@ int orb_check(int fd, FAR bool *updated);
563582

564583
int orb_ioctl(int fd, int cmd, unsigned long arg);
565584

585+
/****************************************************************************
586+
* Name: orb_flush
587+
*
588+
* Description:
589+
* When topic data accumulates in the hardware buffer but does not reach
590+
* the watermark, you can mmediately read the fifo data through the flush
591+
* operation. You can call the flush operation at any time.
592+
*
593+
* After you call flush, you can determine whether the flush is completed
594+
* by listening to the POLLPRI event of fd and getting the event in
595+
* orb_get_events
596+
*
597+
* Input Parameters:
598+
* fd A fd returned from orb_advertise / orb_subscribe.
599+
*
600+
* Returned Value:
601+
* 0 on success.
602+
****************************************************************************/
603+
604+
int orb_flush(int fd);
605+
566606
/****************************************************************************
567607
* Name: orb_set_batch_interval
568608
*

0 commit comments

Comments
 (0)