MCPcopy Create free account
hub / github.com/ArduPilot/ardupilot / process_byte

Method process_byte

libraries/AP_RCProtocol/AP_RCProtocol.cpp:235–294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

233}
234
235bool AP_RCProtocol::process_byte(uint8_t byte, uint32_t baudrate)
236{
237 uint32_t now = AP_HAL::millis();
238 bool searching = should_search(now);
239
240#if AP_RC_CHANNEL_ENABLED
241 rc_protocols_mask = rc().enabled_protocols();
242#endif
243
244 if (_detected_protocol != AP_RCProtocol::NONE &&
245 !protocol_enabled(_detected_protocol)) {
246 _detected_protocol = AP_RCProtocol::NONE;
247 }
248
249 if (_detected_protocol != AP_RCProtocol::NONE && !_detected_with_bytes && !searching) {
250 // we're using pulse inputs, discard bytes
251 return false;
252 }
253
254 // first try current protocol
255 if (_detected_protocol != AP_RCProtocol::NONE && !searching) {
256 backend[_detected_protocol]->process_byte(byte, baudrate);
257 if (backend[_detected_protocol]->new_input()) {
258 _new_input = true;
259 _last_input_ms = now;
260 }
261 return true;
262 }
263
264 // otherwise scan all protocols
265 for (uint8_t i = 0; i < ARRAY_SIZE(backend); i++) {
266 if (backend[i] != nullptr) {
267 if (!protocol_enabled(rcprotocol_t(i))) {
268 continue;
269 }
270 const uint32_t frame_count = backend[i]->get_rc_frame_count();
271 const uint32_t input_count = backend[i]->get_rc_input_count();
272 backend[i]->process_byte(byte, baudrate);
273 const uint32_t frame_count2 = backend[i]->get_rc_frame_count();
274 if (frame_count2 > frame_count) {
275 if (requires_3_frames((rcprotocol_t)i) && frame_count2 < 3) {
276 continue;
277 }
278 _new_input = (input_count != backend[i]->get_rc_input_count());
279 _detected_protocol = (enum AP_RCProtocol::rcprotocol_t)i;
280 _last_input_ms = now;
281 _detected_with_bytes = true;
282 for (uint8_t j = 0; j < ARRAY_SIZE(backend); j++) {
283 if (backend[j]) {
284 backend[j]->reset_rc_frame_count();
285 }
286 }
287 // stop decoding pulses to save CPU
288 hal.rcin->pulse_input_enable(false);
289 return true;
290 }
291 }
292 }

Callers 5

_timer_tickMethod · 0.45
test_byte_protocolFunction · 0.45
test_randomFunction · 0.45
loopFunction · 0.45
rcin_serial_updateMethod · 0.45

Calls 8

rcprotocol_tEnum · 0.85
enabled_protocolsMethod · 0.80
get_rc_frame_countMethod · 0.80
get_rc_input_countMethod · 0.80
reset_rc_frame_countMethod · 0.80
millisFunction · 0.50
new_inputMethod · 0.45
pulse_input_enableMethod · 0.45

Tested by 2

test_byte_protocolFunction · 0.36
test_randomFunction · 0.36