QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
SerialPortManager Class Reference

Shared serial inventory and exclusive claims. Called on the application thread. More...

#include <SerialPortManager.h>

Inheritance diagram for SerialPortManager:
Collaboration diagram for SerialPortManager:

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

Detailed Description

Shared serial inventory and exclusive claims. Called on the application thread.

Definition at line 19 of file SerialPortManager.h.

Member Typedef Documentation

◆ Enumerator

using SerialPortManager::Enumerator = std::function<QList<Port>()>

Definition at line 66 of file SerialPortManager.h.

◆ ReservationPtr

using SerialPortManager::ReservationPtr = std::shared_ptr<const Reservation>

Definition at line 65 of file SerialPortManager.h.

Constructor & Destructor Documentation

◆ SerialPortManager()

SerialPortManager::SerialPortManager ( QObject * parent = nullptr,
Enumerator enumerator = {} )
explicit

Member Function Documentation

◆ accessDenied()

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.

◆ availablePorts()

QList< SerialPortManager::Port > SerialPortManager::availablePorts ( )

◆ canAutoConnectPort()

bool SerialPortManager::canAutoConnectPort ( const QString & systemLocation) const

Definition at line 278 of file SerialPortManager.cc.

References canReservePort(), and isAutoConnectExcluded().

◆ canReservePort()

bool SerialPortManager::canReservePort ( const QString & systemLocation) const

Definition at line 256 of file SerialPortManager.cc.

References isPortReserved().

Referenced by canAutoConnectPort(), and reservePort().

◆ displayName()

QString SerialPortManager::displayName ( const QString & systemLocation)

Definition at line 114 of file SerialPortManager.cc.

References availablePorts(), and port().

Referenced by SerialConfiguration::cleanPortDisplayName().

◆ excludeFromAutoConnect()

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().

◆ hasAccess()

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.

◆ instance()

◆ isAutoConnectExcluded()

bool SerialPortManager::isAutoConnectExcluded ( const QString & systemLocation) const

Definition at line 338 of file SerialPortManager.cc.

Referenced by canAutoConnectPort().

◆ isPortReserved()

bool SerialPortManager::isPortReserved ( const QString & systemLocation) const

Definition at line 175 of file SerialPortManager.cc.

Referenced by canReservePort().

◆ isPrimaryInterface()

bool SerialPortManager::isPrimaryInterface ( const Port & port,
QSet< QString > & seenDevices )
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().

◆ isSamePort()

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.

◆ persistentName()

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().

◆ 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().

◆ portsEnumerated

void SerialPortManager::portsEnumerated ( const QStringList & availablePorts)
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().

◆ requestAccess()

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.

◆ rescan()

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().

◆ reservationOwner()

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.

◆ reservePort()

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().

◆ serialPorts()

QStringList SerialPortManager::serialPorts ( ) const
inline

Definition at line 88 of file SerialPortManager.h.

Referenced by availablePorts(), and LinkManagerTest.

◆ serialPortsChanged

void SerialPortManager::serialPortsChanged ( )
signal

Referenced by availablePorts(), and LinkManagerTest.

◆ supportedBaudRates()

QStringList SerialPortManager::supportedBaudRates ( )
static

◆ GPSReceiverConnectionPolicyTest

friend class GPSReceiverConnectionPolicyTest
friend

Definition at line 25 of file SerialPortManager.h.

References GPSReceiverConnectionPolicyTest.

Referenced by GPSReceiverConnectionPolicyTest.

◆ LinkManagerTest

friend class LinkManagerTest
friend

Definition at line 26 of file SerialPortManager.h.

References LinkManagerTest, serialPorts(), serialPortsChanged(), and supportedBaudRates().

Referenced by LinkManagerTest.

Member Data Documentation

◆ NEW_PORT_SETTLE_DELAY

std::chrono::milliseconds SerialPortManager::NEW_PORT_SETTLE_DELAY {1000}
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().


The documentation for this class was generated from the following files: