Enroute Flight Navigation
A navigation app for VFR pilots
ConnectionInfo.h
1/***************************************************************************
2 * Copyright (C) 2024-2025 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 {
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 {
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 {
85 NoFlowControl,
86 HardwareControl,
87 SoftwareControl
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
303 [[nodiscard]] bool operator== (const Traffic::ConnectionInfo& other) const = default;
304
315 bool operator< (const Traffic::ConnectionInfo& other) const;
316
317private:
318 //
319 // Properties
320 //
321 bool m_canConnect { false };
322 bool m_canonical { false };
323 QString m_description;
324 QString m_icon{u"/icons/material/ic_delete.svg"_s};
325 QString m_name { QObject::tr("Invalid Device", "Traffic::ConnectionInfo") };
327
328 //
329 // Private members, depending on m_type
330 //
331 QBluetoothDeviceInfo m_bluetoothDeviceInfo;
332 quint16 m_port{0};
333 QString m_host;
334
335 BaudRate m_baudRate {BaudRate::Baud9600};
336 StopBits m_stopBits {StopBits::OneStop};
337 FlowControl m_flowControl {FlowControl::NoFlowControl};
338
339};
340
346QDataStream& operator<<(QDataStream& stream, const Traffic::ConnectionInfo &connectionInfo);
347
353QDataStream& operator>>(QDataStream& stream, Traffic::ConnectionInfo& connectionInfo);
354
355} // namespace Traffic
356
357// Make enums available in QML
358namespace ConnectionInfoQML {
359Q_NAMESPACE
360QML_FOREIGN_NAMESPACE(Traffic::ConnectionInfo)
361QML_NAMED_ELEMENT(ConnectionInfo)
362} // Namespace ConnectionInfoQML
363
364// Declare meta types
365//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.