mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-26 07:03:33 +08:00
Let's use poll. It's more friendlier.
This commit is contained in:
+14
-4
@@ -45,6 +45,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <poll.h>
|
||||||
|
|
||||||
#include <nuttx/clock.h>
|
#include <nuttx/clock.h>
|
||||||
|
|
||||||
@@ -81,7 +82,6 @@ comms_check(void)
|
|||||||
{
|
{
|
||||||
static hrt_abstime last_report_time;
|
static hrt_abstime last_report_time;
|
||||||
hrt_abstime now, delta;
|
hrt_abstime now, delta;
|
||||||
uint8_t c;
|
|
||||||
|
|
||||||
/* should we send a report to the FMU? */
|
/* should we send a report to the FMU? */
|
||||||
now = hrt_absolute_time();
|
now = hrt_absolute_time();
|
||||||
@@ -102,9 +102,19 @@ comms_check(void)
|
|||||||
hx_stream_send(stream, &report, sizeof(report));
|
hx_stream_send(stream, &report, sizeof(report));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* feed any received bytes to the HDLC receive engine */
|
/*
|
||||||
while (read(fmu_fd, &c, 1) == 1)
|
* Check for bytes and feed them to the RX engine.
|
||||||
hx_stream_rx(stream, c);
|
* Limit the number of bytes we actually process on any one iteration.
|
||||||
|
*/
|
||||||
|
struct pollfd fds[1];
|
||||||
|
fds[0].fd = fmu_fd;
|
||||||
|
fds[0].revents = POLLIN;
|
||||||
|
if (poll(fds, 1, 0) > 0) {
|
||||||
|
char buf[8];
|
||||||
|
ssize_t count = read(fmu_fd, buf, sizeof(buf));
|
||||||
|
for (int i = 0; i < count; i++)
|
||||||
|
hx_stream_rx(stream, buf[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
Reference in New Issue
Block a user