QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
AndroidSerialPortInfo.cc
Go to the documentation of this file.
2
3#include <iterator>
4
6#include "AndroidSerialJni.h"
7#include "AndroidSerialPort.h"
8
9namespace {
10
11// A name that still opens a USB port after its device is replugged starts with this, as QGCUsbSerialPortName.java
12// builds it.
13constexpr QLatin1String kStableUsbNamePrefix("usb:");
14
15constexpr qint32 kStandardBaudRates[] = {
16 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800,
17 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 500000,
18 576000, 921600, 1000000, 1152000, 1500000, 2000000, 2500000, 3000000, 3500000, 4000000,
19};
20
21} // namespace
22
24{
25 const QList<QSerialPortInfo> ports = availablePorts();
26 for (const QSerialPortInfo& port : ports) {
27 // A port that was opened by its stable name goes by that name.
28 if ((name == port.portName()) || (!name.isEmpty() && (name == port.stableName()))) {
29 *this = port;
30 break;
31 }
32 }
33}
34
38
40 : _data(data)
41{}
42
44{
45 return QList<qint32>(std::begin(kStandardBaudRates), std::end(kStandardBaudRates));
46}
47
48QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
49{
50 return availablePorts(QStringLiteral("/dev"), QStringLiteral("/sys/class/tty"));
51}
52
53QList<QSerialPortInfo> QSerialPortInfo::availablePorts(const QString& devDir, const QString& sysTtyDir)
54{
55 QList<QSerialPortInfo> ports = AndroidSerial::availablePorts();
57 ports += posixPorts(devDir, sysTtyDir, ports);
58 }
59
60 return ports;
61}
62
64{
65 // A stable name of a USB port is not the name of a device node, and Java opens the port by it as it is.
66 return (portName.startsWith(QLatin1Char('/')) || portName.startsWith(QLatin1String("./")) ||
67 portName.startsWith(QLatin1String("../")) || portName.startsWith(kStableUsbNamePrefix))
68 ? portName
69 : (QLatin1String("/dev/") + portName);
70}
71
73{
74 return systemLocation.startsWith(QLatin1String("/dev/")) ? systemLocation.mid(5) : systemLocation;
75}
76
78{
79 return systemLocation.startsWith(QLatin1String("/dev/bus/usb/")) || systemLocation.startsWith(kStableUsbNamePrefix);
80}
static QString portNameFromSystemLocation(const QString &systemLocation)
static bool isUsbLocation(const QString &systemLocation)
QString portName() const
QSerialPortInfo()=default
A null port info, which describes no port.
static QList< QSerialPortInfo > posixPorts(const QString &devDir, const QString &sysTtyDir, const QList< QSerialPortInfo > &usbPorts={})
static QList< QSerialPortInfo > availablePorts()
QString systemLocation() const
static QString portNameToSystemLocation(const QString &portName)
static QList< qint32 > standardBaudRates()
QList< QSerialPortInfo > availablePorts()
What is known of a port.