AP_RCProtocol: greatly increase robustness of DSM decoding

this prevents other protocols being decoded as DSM
This commit is contained in:
Andrew Tridgell 2020-08-13 13:28:42 +10:00
parent 017f005737
commit 380e9d3075
2 changed files with 12 additions and 2 deletions

View File

@ -48,6 +48,11 @@ public:
return rc_frame_count;
}
// reset valid rc frame count
void reset_rc_frame_count(void) {
rc_frame_count = 0;
}
// get number of frames, honoring failsafe
uint32_t get_rc_input_count(void) const {
return rc_input_count;

View File

@ -237,6 +237,7 @@ bool AP_RCProtocol_DSM::dsm_parse_byte(uint32_t frame_time_us, uint8_t b, uint16
if (byte_input.ofs > 0 && (frame_time_us - start_frame_time_us) > 6000U) {
start_frame_time_us = frame_time_us;
byte_input.ofs = 0;
reset_rc_frame_count();
}
// there will be at least a 5ms gap between successive DSM frames. if we see it
@ -250,6 +251,7 @@ bool AP_RCProtocol_DSM::dsm_parse_byte(uint32_t frame_time_us, uint8_t b, uint16
if (byte_input.ofs >= AP_DSM_FRAME_SIZE) {
start_frame_time_us = frame_time_us;
byte_input.ofs = 0;
reset_rc_frame_count();
}
if (byte_input.ofs == 1) {
@ -268,6 +270,10 @@ bool AP_RCProtocol_DSM::dsm_parse_byte(uint32_t frame_time_us, uint8_t b, uint16
} else {
start_frame_time_us = frame_time_us;
byte_input.ofs = 0;
// reset protocol detection. Any bad data during detection
// and we need to not detect as DSM. This is needed as DSM
// is such a weak protocol.
reset_rc_frame_count();
}
}
@ -298,8 +304,7 @@ bool AP_RCProtocol_DSM::dsm_parse_byte(uint32_t frame_time_us, uint8_t b, uint16
last_rx_time_us = frame_time_us;
/* return false as default */
return decode_ret;
return decode_ret;
}
// support byte input