SITL: added SITL_State::loop_hook()
this prevents us using so much CPU time, and ensures stdout is flushed
This commit is contained in:
parent
69bebbcaf8
commit
7be507948f
@ -5,9 +5,12 @@
|
||||
#if CONFIG_HAL_BOARD == HAL_BOARD_AVR_SITL
|
||||
#define AP_HAL_MAIN() extern "C" {\
|
||||
int main (int argc, char * const argv[]) { \
|
||||
hal.init(argc, argv); \
|
||||
setup();\
|
||||
for(;;) loop();\
|
||||
hal.init(argc, argv); \
|
||||
setup(); \
|
||||
for(;;) { \
|
||||
loop(); \
|
||||
AVR_SITL::SITL_State::loop_hook(); \
|
||||
} \
|
||||
return 0;\
|
||||
}\
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#include <AP_Param.h>
|
||||
|
||||
@ -450,4 +451,35 @@ void SITL_State::init(int argc, char * const argv[])
|
||||
_parse_command_line(argc, argv);
|
||||
}
|
||||
|
||||
// wait for serial input, or 100usec
|
||||
void SITL_State::loop_hook(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
fd_set fds;
|
||||
int fd, max_fd = 0;
|
||||
|
||||
FD_ZERO(&fds);
|
||||
fd = ((AVR_SITL::SITLUARTDriver*)hal.uartA)->_fd;
|
||||
if (fd != -1) {
|
||||
FD_SET(fd, &fds);
|
||||
max_fd = max(fd, max_fd);
|
||||
}
|
||||
fd = ((AVR_SITL::SITLUARTDriver*)hal.uartB)->_fd;
|
||||
if (fd != -1) {
|
||||
FD_SET(fd, &fds);
|
||||
max_fd = max(fd, max_fd);
|
||||
}
|
||||
fd = ((AVR_SITL::SITLUARTDriver*)hal.uartC)->_fd;
|
||||
if (fd != -1) {
|
||||
FD_SET(fd, &fds);
|
||||
max_fd = max(fd, max_fd);
|
||||
}
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 100;
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
select(max_fd+1, &fds, NULL, NULL, &tv);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
ssize_t gps_read(int fd, void *buf, size_t count);
|
||||
static uint16_t pwm_output[11];
|
||||
static uint16_t pwm_input[8];
|
||||
static void loop_hook(void);
|
||||
|
||||
private:
|
||||
void _parse_command_line(int argc, char * const argv[]);
|
||||
|
@ -56,11 +56,13 @@ public:
|
||||
/* Implementations of Print virtual methods */
|
||||
size_t write(uint8_t c);
|
||||
|
||||
// file descriptor, exposed so SITL_State::loop_hook() can use it
|
||||
int _fd;
|
||||
|
||||
private:
|
||||
uint8_t _portNumber;
|
||||
bool _connected; // true if a client has connected
|
||||
int _listen_fd; // socket we are listening on
|
||||
int _fd; // data socket
|
||||
int _serial_port;
|
||||
static bool _console;
|
||||
bool _nonblocking_writes;
|
||||
|
Loading…
Reference in New Issue
Block a user