Enroute Flight Navigation
A navigation app for VFR pilots
ConnectionInfo.h
1/***************************************************************************
2 * Copyright (C) 2024-2026 by Stefan Kebekus *
3 * stefan.kebekus@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#pragma once
22
23#include <QBluetoothDeviceInfo>
24#include <QQmlEngine>
25
26#if __has_include (<QSerialPortInfo>)
27#include <QSerialPort>
28#include <QSerialPortInfo>
29#endif
30
31using namespace Qt::Literals::StringLiterals;
32
33
34namespace Traffic {
35
43 Q_GADGET
44 QML_VALUE_TYPE(connectionInfo)
45
46 friend QDataStream& operator<<(QDataStream& stream, const Traffic::ConnectionInfo &connectionInfo);
47 friend QDataStream& operator>>(QDataStream& stream, Traffic::ConnectionInfo& connectionInfo);
48
49public:
61 Q_ENUM(Type)
62
63 // Duplicated from QSerialPort, in order to make it available to QML
64 enum BaudRate : int {
65 Baud1200 = 1200,
66 Baud2400 = 2400,
67 Baud4800 = 4800,
68 Baud9600 = 9600,
69 Baud19200 = 19200,
70 Baud38400 = 38400,
71 Baud57600 = 57600,
72 Baud115200 = 115200
73 };
74 Q_ENUM(BaudRate)
75
76 // Duplicated from QSerialPort, in order to make it available to QML
77 enum StopBits : int {
78 OneStop = 1,
79 TwoStop = 2
80 };
81 Q_ENUM(StopBits)
82
83 // Duplicated from QSerialPort, in order to make it available to QML
84 enum FlowControl : int {
85 NoFlowControl = 0,
86 HardwareControl = 1,
87 SoftwareControl = 2
88 };
89 Q_ENUM(FlowControl)
90
91
96 ConnectionInfo() = default;
97
108 explicit ConnectionInfo(const QBluetoothDeviceInfo& info, bool canonical=false);
109
125 explicit ConnectionInfo(const QString& serialPortNameOrDescription,
126 ConnectionInfo::BaudRate baudRate = ConnectionInfo::BaudRate::Baud9600,
127 ConnectionInfo::StopBits stopBits = ConnectionInfo::StopBits::OneStop,
128 ConnectionInfo::FlowControl flowControl = ConnectionInfo::FlowControl::NoFlowControl,
129 bool canonical = false);
130
140 explicit ConnectionInfo(quint16 port, bool canonical=false);
141
153 explicit ConnectionInfo(const QString& host, quint16 port, bool canonical=false);
154
158 struct OgnInfo{};
159
167 explicit ConnectionInfo(const OgnInfo& info);
168
169
170 //
171 // Properties
172 //
173
182 Q_PROPERTY(bool canConnect READ canConnect CONSTANT)
183 [[nodiscard]] bool canConnect() const { return m_canConnect; }
184
192 Q_PROPERTY(bool canonical READ canonical CONSTANT)
193 [[nodiscard]] bool canonical() const { return m_canonical; }
194
201 Q_PROPERTY(QString description READ description CONSTANT)
202 [[nodiscard]] QString description() const { return m_description; }
203
209 Q_PROPERTY(QString host READ host CONSTANT)
210 [[nodiscard]] QString host() const { return m_host; }
211
218 Q_PROPERTY(QString icon READ icon CONSTANT)
219 [[nodiscard]] QString icon() const { return m_icon; }
220
226 Q_PROPERTY(QString name READ name CONSTANT)
227 [[nodiscard]] QString name() const { return m_name; }
228
234 Q_PROPERTY(Traffic::ConnectionInfo::Type type READ type CONSTANT)
235 [[nodiscard]] Traffic::ConnectionInfo::Type type() const { return m_type; }
236
237
238 //
239 // Methods
240 //
241
247 [[nodiscard]] BaudRate baudRate() const {return m_baudRate;}
248
257 [[nodiscard]] QBluetoothDeviceInfo bluetoothDeviceInfo() const { return m_bluetoothDeviceInfo; }
258
264 [[nodiscard]] FlowControl flowControl() const {return m_flowControl;}
265
272 [[nodiscard]] quint16 port() const { return m_port; }
273
287 [[nodiscard]] bool sameConnectionAs(const Traffic::ConnectionInfo& other) const;
288
294 [[nodiscard]] StopBits stopBits() const {return m_stopBits;}
295
307 [[nodiscard]] bool operator== (const Traffic::ConnectionInfo& other) const = default;
308
319 bool operator< (const Traffic::ConnectionInfo& other) const;
320
321private:
322 //
323 // Properties
324 //
325 bool m_canConnect = false;
326 bool m_canonical = false;
327 QString m_description;
328 QString m_icon = u"/icons/material/ic_delete.svg"_s;
329 QString m_name = QObject::tr("Invalid Device", "Traffic::ConnectionInfo");
331
332 //
333 // Private members, depending on m_type
334 //
335 QBluetoothDeviceInfo m_bluetoothDeviceInfo;
336 quint16 m_port = 0;
337 QString m_host;
338
339 BaudRate m_baudRate = BaudRate::Baud9600;
340 StopBits m_stopBits = StopBits::OneStop;
341 FlowControl m_flowControl = FlowControl::NoFlowControl;
342
343};
344
350QDataStream& operator<<(QDataStream& stream, const Traffic::ConnectionInfo &connectionInfo);
351
357QDataStream& operator>>(QDataStream& stream, Traffic::ConnectionInfo& connectionInfo);
358
359} // namespace Traffic
360
361// Make enums available in QML
362namespace ConnectionInfoQML {
363Q_NAMESPACE
364QML_FOREIGN_NAMESPACE(Traffic::ConnectionInfo)
365QML_NAMED_ELEMENT(ConnectionInfo)
366} // Namespace ConnectionInfoQML
367
368// Declare meta types
369//Q_DECLARE_METATYPE(Navigation::Aircraft)
Connection to a traffic data receiver.
bool operator==(const Traffic::ConnectionInfo &other) const =default
Equality of ConnectionInfos.
Traffic::ConnectionInfo::Type type
Type.
quint16 port() const
Port.
bool canonical
Canonicity.
ConnectionInfo()=default
Default constructor.
ConnectionInfo(const OgnInfo &info)
Constructor for OGN Connections.
bool sameConnectionAs(const Traffic::ConnectionInfo &other) const
Equality of connection.
QBluetoothDeviceInfo bluetoothDeviceInfo() const
Bluetooth Device Info.
StopBits stopBits() const
Stop Bits.
bool canConnect
Connectability.
FlowControl flowControl() const
Flow Control.
bool operator<(const Traffic::ConnectionInfo &other) const
Comparison.
BaudRate baudRate() const
Baud Rate.
QString description
Description.
Constructor parameter for OGN connections.