From c682b7deab03d5066523427e909f274a59c9b55f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 20 Dec 2021 15:46:07 +1100 Subject: [PATCH] AP_SerialManager: added have_serial() method this checks if we have the protocol without setting the options on the uart --- libraries/AP_SerialManager/AP_SerialManager.cpp | 6 ++++++ libraries/AP_SerialManager/AP_SerialManager.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/libraries/AP_SerialManager/AP_SerialManager.cpp b/libraries/AP_SerialManager/AP_SerialManager.cpp index 6532251773..73e23aee96 100644 --- a/libraries/AP_SerialManager/AP_SerialManager.cpp +++ b/libraries/AP_SerialManager/AP_SerialManager.cpp @@ -578,6 +578,12 @@ AP_HAL::UARTDriver *AP_SerialManager::find_serial(enum SerialProtocol protocol, return port; } +// have_serial - return true if we have the given serial protocol configured +bool AP_SerialManager::have_serial(enum SerialProtocol protocol, uint8_t instance) const +{ + return find_protocol_instance(protocol, instance) != nullptr; +} + // find_baudrate - searches available serial ports for the first instance that allows the given protocol // instance should be zero if searching for the first instance, 1 for the second, etc // returns baudrate on success, 0 if a serial port cannot be found diff --git a/libraries/AP_SerialManager/AP_SerialManager.h b/libraries/AP_SerialManager/AP_SerialManager.h index d6cb2604b0..114bccf105 100644 --- a/libraries/AP_SerialManager/AP_SerialManager.h +++ b/libraries/AP_SerialManager/AP_SerialManager.h @@ -169,8 +169,12 @@ public: // find_serial - searches available serial ports that allows the given protocol // instance should be zero if searching for the first instance, 1 for the second, etc // returns uart on success, nullptr if a serial port cannot be found + // note that the SERIALn_OPTIONS are applied if the port is found AP_HAL::UARTDriver *find_serial(enum SerialProtocol protocol, uint8_t instance) const; + // have_serial - return true if we have the corresponding serial protocol configured + bool have_serial(enum SerialProtocol protocol, uint8_t instance) const; + // find_baudrate - searches available serial ports for the first instance that allows the given protocol // instance should be zero if searching for the first instance, 1 for the second, etc // returns the baudrate of that protocol on success, 0 if a serial port cannot be found