mirror of https://github.com/ArduPilot/ardupilot
make desktop serial more responsive
This commit is contained in:
parent
4e09ea5fa2
commit
de0a7117a8
|
@ -45,6 +45,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include "desktop.h"
|
||||
|
||||
#define LISTEN_BASE_PORT 5760
|
||||
#define BUFFER_SIZE 128
|
||||
|
@ -305,3 +306,19 @@ void FastSerial::_freeBuffer(Buffer *buffer)
|
|||
{
|
||||
}
|
||||
|
||||
/*
|
||||
return true if any bytes are pending
|
||||
*/
|
||||
void desktop_serial_select_setup(fd_set *fds, int *fd_high)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<FS_MAX_PORTS; i++) {
|
||||
if (tcp_state[i].connected) {
|
||||
FD_SET(tcp_state[i].fd, fds);
|
||||
if (tcp_state[i].fd > *fd_high) {
|
||||
*fd_high = tcp_state[i].fd;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <sys/time.h>
|
||||
#include <sched.h>
|
||||
#include <wiring.h>
|
||||
#include "desktop.h"
|
||||
|
||||
void setup(void);
|
||||
void loop(void);
|
||||
|
@ -16,15 +17,17 @@ int main(void)
|
|||
setup();
|
||||
while (true) {
|
||||
struct timeval tv;
|
||||
unsigned long t1, t2;
|
||||
t1 = micros();
|
||||
fd_set fds;
|
||||
int fd_high = 0;
|
||||
|
||||
FD_ZERO(&fds);
|
||||
loop();
|
||||
t2 = micros();
|
||||
if (t2 - t1 < 2) {
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 1;
|
||||
select(0, NULL, NULL, NULL, &tv);
|
||||
}
|
||||
|
||||
desktop_serial_select_setup(&fds, &fd_high);
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 100;
|
||||
|
||||
select(fd_high+1, &fds, NULL, NULL, &tv);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue