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

Method find_protocol_instance

libraries/AP_SerialManager/AP_SerialManager.cpp:598–625  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

596
597
598const AP_SerialManager::UARTState *AP_SerialManager::find_protocol_instance(enum SerialProtocol protocol, uint8_t instance) const
599{
600 uint8_t found_instance = 0;
601
602 // search for matching protocol
603 for(uint8_t i=0; i<SERIALMANAGER_NUM_PORTS; i++) {
604 if (protocol_match(protocol, (enum SerialProtocol)state[i].protocol.get())) {
605 if (found_instance == instance) {
606 return &state[i];
607 }
608 found_instance++;
609 }
610 }
611
612#if AP_SERIALMANAGER_REGISTER_ENABLED
613 for (auto p = registered_ports; p; p = p->next) {
614 if (protocol_match(protocol, (enum SerialProtocol)p->state.protocol.get())) {
615 if (found_instance == instance) {
616 return &p->state;
617 }
618 found_instance++;
619 }
620 }
621#endif
622
623 // if we got this far we did not find the uart
624 return nullptr;
625}
626
627// find_serial - searches available serial ports for the first instance that allows the given protocol
628// instance should be zero if searching for the first instance, 1 for the second, etc

Callers 1

initMethod · 0.80

Calls 1

getMethod · 0.45

Tested by

no test coverage detected