AP_HAL_SITL: read all available SITL RC input packets

MAVProxy runs on its own clock.  While our clock is stopped for whatever
reason MAVProxy will continue to send RC input.  This patch always gives
us the most recent RC input from MAVProxy.

Also add sanity check on packet received
This commit is contained in:
Peter Barker 2018-05-30 20:18:40 +10:00
parent 4d0ae8c371
commit 80e8f9cdd8
2 changed files with 20 additions and 3 deletions

View File

@ -229,13 +229,26 @@ int SITL_State::sim_fd(const char *name, const char *arg)
*/ */
void SITL_State::_check_rc_input(void) void SITL_State::_check_rc_input(void)
{ {
ssize_t size; uint32_t count = 0;
while (_read_rc_sitl_input()) {
count++;
}
if (count > 100) {
::fprintf(stderr, "Read %u rc inputs\n", count);
}
}
bool SITL_State::_read_rc_sitl_input()
{
struct pwm_packet { struct pwm_packet {
uint16_t pwm[16]; uint16_t pwm[16];
} pwm_pkt; } pwm_pkt;
size = _sitl_rc_in.recv(&pwm_pkt, sizeof(pwm_pkt), 0); const ssize_t size = _sitl_rc_in.recv(&pwm_pkt, sizeof(pwm_pkt), 0);
switch (size) { switch (size) {
case -1:
return false;
case 8*2: case 8*2:
case 16*2: { case 16*2: {
// a packet giving the receiver PWM inputs // a packet giving the receiver PWM inputs
@ -259,9 +272,12 @@ void SITL_State::_check_rc_input(void)
pwm_input[i] = pwm; pwm_input[i] = pwm;
} }
} }
break; return true;
} }
default:
fprintf(stderr, "Malformed SITL RC input (%li)", size);
} }
return false;
} }
/* /*

View File

@ -133,6 +133,7 @@ private:
void _update_airspeed(float airspeed); void _update_airspeed(float airspeed);
void _update_gps_instance(SITL::SITL::GPSType gps_type, const struct gps_data *d, uint8_t instance); void _update_gps_instance(SITL::SITL::GPSType gps_type, const struct gps_data *d, uint8_t instance);
void _check_rc_input(void); void _check_rc_input(void);
bool _read_rc_sitl_input();
void _fdm_input_local(void); void _fdm_input_local(void);
void _output_to_flightgear(void); void _output_to_flightgear(void);
void _simulator_servos(struct sitl_input &input); void _simulator_servos(struct sitl_input &input);