Shared serial inventory and exclusive claims. Called on the application thread. More...
#include <SerialPortManager.h>
Classes | |
| struct | Port |
| struct | Reservation |
Public Types | |
| using | ReservationPtr = std::shared_ptr<const Reservation> |
| using | Enumerator = std::function<QList<Port>()> |
Signals | |
| void | serialPortsChanged () |
| void | portsEnumerated (const QStringList &availablePorts) |
| Emitted only after a fresh scan, with every name of the ports it lists. | |
Public Member Functions | |
| SerialPortManager (QObject *parent=nullptr, Enumerator enumerator={}) | |
| QList< Port > | availablePorts () |
| void | rescan () |
| As availablePorts(), without reusing a scan made less than a second ago. | |
| QString | displayName (const QString &systemLocation) |
| QStringList | serialPorts () const |
| ReservationPtr | reservePort (const QString &systemLocation, const QString &owner={}) |
| bool | canReservePort (const QString &systemLocation) const |
| bool | isPortReserved (const QString &systemLocation) const |
| QString | reservationOwner (const QString &systemLocation) const |
| The owner the port is reserved with; empty when it is not reserved or its holder gave none. | |
| bool | isSamePort (const QString &first, const QString &second) const |
| Whether both names are of one listed port, or are the same name. | |
| QString | persistentName (const QString &name) const |
| std::optional< Port > | port (const QString &name) const |
| bool | hasAccess (const QString &name) const |
| bool | requestAccess (const QString &name) |
| bool | accessDenied (const QString &name) const |
| ReservationPtr | excludeFromAutoConnect (const QString &systemLocation) |
| Routing exclusions survive reconnects without marking the hardware occupied. | |
| bool | canAutoConnectPort (const QString &systemLocation) const |
| bool | isAutoConnectExcluded (const QString &systemLocation) const |
Static Public Member Functions | |
| static SerialPortManager * | instance () |
| static bool | isPrimaryInterface (const Port &port, QSet< QString > &seenDevices) |
| static QStringList | supportedBaudRates () |
Static Public Attributes | |
| static constexpr std::chrono::milliseconds | NEW_PORT_SETTLE_DELAY {1000} |
| How long a newly listed port settles before automatic connection opens it. | |
Friends | |
| class | GPSReceiverConnectionPolicyTest |
| class | LinkManagerTest |
Shared serial inventory and exclusive claims. Called on the application thread.
Definition at line 19 of file SerialPortManager.h.
| using SerialPortManager::Enumerator = std::function<QList<Port>()> |
Definition at line 66 of file SerialPortManager.h.
| using SerialPortManager::ReservationPtr = std::shared_ptr<const Reservation> |
Definition at line 65 of file SerialPortManager.h.
|
explicit |
Definition at line 20 of file SerialPortManager.cc.
References AndroidSerial::DeviceWatcher::devicesChanged(), AndroidSerial::DeviceWatcher::instance(), rescan(), and SerialPortManager().
Referenced by instance(), and SerialPortManager().
| bool SerialPortManager::accessDenied | ( | const QString & | name | ) | const |
Whether the user has refused to let QGC open the port, and has not been asked again since. A scan of the ports follows a refusal, as it follows a grant.
Definition at line 251 of file SerialPortManager.cc.
| QList< SerialPortManager::Port > SerialPortManager::availablePorts | ( | ) |
Definition at line 77 of file SerialPortManager.cc.
References port(), portsEnumerated(), serialPorts(), and serialPortsChanged().
Referenced by SerialConfiguration::connectionSettings(), displayName(), portsEnumerated(), and rescan().
| bool SerialPortManager::canAutoConnectPort | ( | const QString & | systemLocation | ) | const |
Definition at line 278 of file SerialPortManager.cc.
References canReservePort(), and isAutoConnectExcluded().
| bool SerialPortManager::canReservePort | ( | const QString & | systemLocation | ) | const |
Definition at line 256 of file SerialPortManager.cc.
References isPortReserved().
Referenced by canAutoConnectPort(), and reservePort().
| QString SerialPortManager::displayName | ( | const QString & | systemLocation | ) |
Definition at line 114 of file SerialPortManager.cc.
References availablePorts(), and port().
Referenced by SerialConfiguration::cleanPortDisplayName().
| SerialPortManager::ReservationPtr SerialPortManager::excludeFromAutoConnect | ( | const QString & | systemLocation | ) |
Routing exclusions survive reconnects without marking the hardware occupied.
Definition at line 261 of file SerialPortManager.cc.
References port().
| bool SerialPortManager::hasAccess | ( | const QString & | name | ) | const |
Whether QGC has the user's permission to open the port, or needs none. Android alone has such a permission, for the device of a USB port: such a port has access only while its device is attached and the user has let QGC open it.
Definition at line 241 of file SerialPortManager.cc.
|
static |
Definition at line 31 of file SerialPortManager.cc.
References SerialPortManager().
Referenced by SerialConfiguration::cleanPortDisplayName(), SerialConfiguration::connectionSettings(), LinkManager::createConnectedLink(), LinkManager::init(), LinkManager::LinkManager(), Q_APPLICATION_STATIC(), SerialLink::SerialLink(), LinkManager::serialPortHasFlowControl(), QGroundControlQmlGlobal::serialPortManager(), and LinkManager::startConfigurationEditing().
| bool SerialPortManager::isAutoConnectExcluded | ( | const QString & | systemLocation | ) | const |
Definition at line 338 of file SerialPortManager.cc.
Referenced by canAutoConnectPort().
| bool SerialPortManager::isPortReserved | ( | const QString & | systemLocation | ) | const |
Definition at line 175 of file SerialPortManager.cc.
Referenced by canReservePort().
|
static |
Whether port is the first interface listed of its physical device, which this records in seenDevices. A port without a device identity is always primary.
Definition at line 36 of file SerialPortManager.cc.
References port().
Referenced by SerialAutoConnect::update().
| bool SerialPortManager::isSamePort | ( | const QString & | first, |
| const QString & | second ) const |
Whether both names are of one listed port, or are the same name.
Definition at line 186 of file SerialPortManager.cc.
| QString SerialPortManager::persistentName | ( | const QString & | name | ) | const |
The name for a saved configuration to keep of the listed port with this system location or port name: the port's stable name if it has one that no other listed port shares, else its system location. Any other name is returned as it is.
Definition at line 191 of file SerialPortManager.cc.
References port().
| std::optional< SerialPortManager::Port > SerialPortManager::port | ( | const QString & | name | ) | const |
The only listed port with this name, whichever of its names that is. None when no listed port has the name, or when several share it as their stable name.
Definition at line 206 of file SerialPortManager.cc.
References port().
Referenced by availablePorts(), displayName(), excludeFromAutoConnect(), isPrimaryInterface(), persistentName(), port(), reservePort(), and LinkManager::serialPortHasFlowControl().
|
signal |
Emitted only after a fresh scan, with every name of the ports it lists.
References availablePorts().
Referenced by availablePorts(), GPSReceiver::GPSReceiver(), LinkManager::LinkManager(), and SerialLink::SerialLink().
| bool SerialPortManager::requestAccess | ( | const QString & | name | ) |
Asks the user to let QGC open the port, and returns whether it did. It does not for a port that has access already, that takes no permission, or whose device is not attached. The user answers later, and the port does not open until then; a scan of the ports follows a grant. Opening a port asks by itself, once for each time its device is attached. This asks whenever it is called, also after a denial, so call it only for a connection that the user has asked for.
Definition at line 246 of file SerialPortManager.cc.
| void SerialPortManager::rescan | ( | ) |
As availablePorts(), without reusing a scan made less than a second ago.
Definition at line 108 of file SerialPortManager.cc.
References availablePorts().
Referenced by LinkManager::init(), and SerialPortManager().
| QString SerialPortManager::reservationOwner | ( | const QString & | systemLocation | ) | const |
The owner the port is reserved with; empty when it is not reserved or its holder gave none.
Definition at line 180 of file SerialPortManager.cc.
| SerialPortManager::ReservationPtr SerialPortManager::reservePort | ( | const QString & | systemLocation, |
| const QString & | owner = {} ) |
Definition at line 124 of file SerialPortManager.cc.
References canReservePort(), and port().
Referenced by LinkManager::createConnectedLink().
|
inline |
Definition at line 88 of file SerialPortManager.h.
Referenced by availablePorts(), and LinkManagerTest.
|
signal |
Referenced by availablePorts(), and LinkManagerTest.
|
static |
Definition at line 283 of file SerialPortManager.cc.
References QSerialPortInfo::standardBaudRates().
Referenced by LinkManagerTest, GPSReceiver::serialBaudRates(), and SerialConfiguration::supportedBaudRates().
|
friend |
Definition at line 25 of file SerialPortManager.h.
References GPSReceiverConnectionPolicyTest.
Referenced by GPSReceiverConnectionPolicyTest.
|
friend |
Definition at line 26 of file SerialPortManager.h.
References LinkManagerTest, serialPorts(), serialPortsChanged(), and supportedBaudRates().
Referenced by LinkManagerTest.
|
staticconstexpr |
How long a newly listed port settles before automatic connection opens it.
Definition at line 73 of file SerialPortManager.h.
Referenced by SerialPortSettleTracker::settled().