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

Method process_pulse

libraries/AP_RCProtocol/AP_RCProtocol.cpp:151–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149}
150
151void AP_RCProtocol::process_pulse(uint32_t width_s0, uint32_t width_s1)
152{
153 uint32_t now = AP_HAL::millis();
154 bool searching = should_search(now);
155
156#if AP_RC_CHANNEL_ENABLED
157 rc_protocols_mask = rc().enabled_protocols();
158#endif
159
160 if (_detected_protocol != AP_RCProtocol::NONE &&
161 !protocol_enabled(_detected_protocol)) {
162 _detected_protocol = AP_RCProtocol::NONE;
163 }
164
165 if (_detected_protocol != AP_RCProtocol::NONE && _detected_with_bytes && !searching) {
166 // we're using byte inputs, discard pulses
167 return;
168 }
169 // first try current protocol
170 if (_detected_protocol != AP_RCProtocol::NONE && !searching) {
171 backend[_detected_protocol]->process_pulse(width_s0, width_s1);
172 if (backend[_detected_protocol]->new_input()) {
173 _new_input = true;
174 _last_input_ms = now;
175 }
176 return;
177 }
178
179 // otherwise scan all protocols
180 for (uint8_t i = 0; i < ARRAY_SIZE(backend); i++) {
181 if (_disabled_for_pulses & (1U << i)) {
182 // this protocol is disabled for pulse input
183 continue;
184 }
185 if (backend[i] != nullptr) {
186 if (!protocol_enabled(rcprotocol_t(i))) {
187 continue;
188 }
189 const uint32_t frame_count = backend[i]->get_rc_frame_count();
190 const uint32_t input_count = backend[i]->get_rc_input_count();
191 backend[i]->process_pulse(width_s0, width_s1);
192 const uint32_t frame_count2 = backend[i]->get_rc_frame_count();
193 if (frame_count2 > frame_count) {
194 if (requires_3_frames((rcprotocol_t)i) && frame_count2 < 3) {
195 continue;
196 }
197 _new_input = (input_count != backend[i]->get_rc_input_count());
198 _detected_protocol = (enum AP_RCProtocol::rcprotocol_t)i;
199 for (uint8_t j = 0; j < ARRAY_SIZE(backend); j++) {
200 if (backend[j]) {
201 backend[j]->reset_rc_frame_count();
202 }
203 }
204 _last_input_ms = now;
205 _detected_with_bytes = false;
206 break;
207 }
208 }

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected