Enroute Flight Navigation
A navigation app for VFR pilots
TrafficDataSource_Udp.h
1/***************************************************************************
2 * Copyright (C) 2021-2024 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 <QPointer>
24#include <QUdpSocket>
25
26#include "traffic/TrafficDataSource_AbstractSocket.h"
27
28using namespace Qt::Literals::StringLiterals;
29
30
31namespace Traffic {
32
44 Q_OBJECT
45
46public:
55 TrafficDataSource_Udp(bool isCanonical, quint16 port, QObject *parent = nullptr);
56
57 // Standard destructor
58 ~TrafficDataSource_Udp() override;
59
60
61
62 //
63 // Properties
64 //
65
68 Q_PROPERTY(quint16 port READ port CONSTANT)
69
70
71
72 //
73 // Getter Methods
74 //
75
76
80 [[nodiscard]] QString dataFormat() const override { return u"GDL90, XGPS"_s; }
81
89 [[nodiscard]] QString icon() const override { return u"/icons/material/ic_wifi.svg"_s; }
90
98 [[nodiscard]] auto sourceName() const -> QString override
99 {
100 return tr("UDP connection to port %1").arg(m_port);
101 }
102
107 [[nodiscard]] quint16 port() const
108 {
109 return m_port;
110 }
111
112
113public slots:
120
127
128private slots:
129 // Read messages from the socket datagrams and passes the messages on to
130 // processGDLMessage
131 void onReadyRead();
132
133private:
134 Q_DISABLE_COPY_MOVE(TrafficDataSource_Udp)
135
136 QPointer<QUdpSocket> m_socket;
137 quint16 m_port;
138
139 // We use this vector to store the last 512 datatgram hashes in a circular
140 // array. This is used to sort out doubly sent datagrams. The nextHashIndex
141 // points to the next vector entry that will be re-written.
142 QVector<uint> receivedDatagramHashes {512, 0};
143 qsizetype nextHashIndex {0};
144
145 // GPS altitude of owncraft
146 Units::Distance m_trueAltitude;
147 Units::Distance m_trueAltitude_FOM;
148 QTimer m_trueAltitudeTimer;
149
150};
151
152} // namespace Traffic
TrafficDataSource_AbstractSocket(bool isCanonical, QObject *parent)
Default constructor.
void disconnectFromTrafficReceiver() override
Disconnect from traffic receiver.
auto sourceName() const -> QString override
Getter function for the property with the same name.
TrafficDataSource_Udp(bool isCanonical, quint16 port, QObject *parent=nullptr)
Default constructor.
QString dataFormat() const override
Getter function for the property with the same name.
void connectToTrafficReceiver() override
Start attempt to connect to traffic receiver.
quint16 port() const
Getter function for the property with the same name.
QString icon() const override
Getter function for the property with the same name.
Convenience class for distance computations.
Definition Distance.h:35