|
|
|
@ -135,7 +135,8 @@ static const char* get_frame_type(uint8_t byte)
@@ -135,7 +135,8 @@ static const char* get_frame_type(uint8_t byte)
|
|
|
|
|
#define CRSF_INTER_FRAME_TIME_US_250HZ 4000U // At fastest, frames are sent by the transmitter every 4 ms, 250 Hz
|
|
|
|
|
#define CRSF_INTER_FRAME_TIME_US_150HZ 6667U // At medium, frames are sent by the transmitter every 6.667 ms, 150 Hz
|
|
|
|
|
#define CRSF_INTER_FRAME_TIME_US_50HZ 20000U // At slowest, frames are sent by the transmitter every 20ms, 50 Hz
|
|
|
|
|
#define CSRF_HEADER_LEN 2 |
|
|
|
|
#define CSRF_HEADER_LEN 2 // header length
|
|
|
|
|
#define CSRF_HEADER_TYPE_LEN (CSRF_HEADER_LEN + 1) // header length including type
|
|
|
|
|
|
|
|
|
|
#define CRSF_DIGITAL_CHANNEL_MIN 172 |
|
|
|
|
#define CRSF_DIGITAL_CHANNEL_MAX 1811 |
|
|
|
@ -200,12 +201,13 @@ void AP_RCProtocol_CRSF::_process_byte(uint32_t timestamp_us, uint8_t byte)
@@ -200,12 +201,13 @@ void AP_RCProtocol_CRSF::_process_byte(uint32_t timestamp_us, uint8_t byte)
|
|
|
|
|
add_to_buffer(_frame_ofs++, byte); |
|
|
|
|
|
|
|
|
|
// need a header to get the length
|
|
|
|
|
if (_frame_ofs < CSRF_HEADER_LEN) { |
|
|
|
|
if (_frame_ofs < CSRF_HEADER_TYPE_LEN) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// parse the length
|
|
|
|
|
if (_frame_ofs == CSRF_HEADER_LEN) { |
|
|
|
|
if (_frame_ofs == CSRF_HEADER_TYPE_LEN) { |
|
|
|
|
_frame_crc = crc8_dvb_s2(0, _frame.type); |
|
|
|
|
// check for garbage frame
|
|
|
|
|
if (_frame.length > CRSF_FRAMELEN_MAX) { |
|
|
|
|
_frame_ofs = 0; |
|
|
|
@ -213,6 +215,11 @@ void AP_RCProtocol_CRSF::_process_byte(uint32_t timestamp_us, uint8_t byte)
@@ -213,6 +215,11 @@ void AP_RCProtocol_CRSF::_process_byte(uint32_t timestamp_us, uint8_t byte)
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// update crc
|
|
|
|
|
if (_frame_ofs < _frame.length + CSRF_HEADER_LEN) { |
|
|
|
|
_frame_crc = crc8_dvb_s2(_frame_crc, byte); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// overflow check
|
|
|
|
|
if (_frame_ofs > _frame.length + CSRF_HEADER_LEN) { |
|
|
|
|
_frame_ofs = 0; |
|
|
|
@ -226,13 +233,8 @@ void AP_RCProtocol_CRSF::_process_byte(uint32_t timestamp_us, uint8_t byte)
@@ -226,13 +233,8 @@ void AP_RCProtocol_CRSF::_process_byte(uint32_t timestamp_us, uint8_t byte)
|
|
|
|
|
// we consumed the partial frame, reset
|
|
|
|
|
_frame_ofs = 0; |
|
|
|
|
|
|
|
|
|
uint8_t crc = crc8_dvb_s2(0, _frame.type); |
|
|
|
|
for (uint8_t i = 0; i < _frame.length - 2; i++) { |
|
|
|
|
crc = crc8_dvb_s2(crc, _frame.payload[i]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// bad CRC
|
|
|
|
|
if (crc != _frame.payload[_frame.length - CSRF_HEADER_LEN]) { |
|
|
|
|
if (_frame_crc != _frame.payload[_frame.length - CSRF_HEADER_LEN]) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|