| 596 | |
| 597 | |
| 598 | const 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 |