Enroute Flight Navigation
A navigation app for VFR pilots
TrafficDataSource_Ogn.h
1/***************************************************************************
2 * Copyright (C) 2021-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 <QPointer>
24#include <QTcpSocket>
25
26#include "traffic/TrafficDataSource_AbstractSocket.h"
27#include "traffic/TrafficDataSource_OgnParser.h"
28
29using namespace Qt::Literals::StringLiterals;
30
31namespace Traffic {
32
45
47 Q_OBJECT
48
49public:
60 TrafficDataSource_Ogn(bool isCanonical, QString hostName, quint16 port, QObject *parent = nullptr);
61
62 // Standard destructor
63 ~TrafficDataSource_Ogn() override;
64
65 //
66 // Properties
67 //
68
71 Q_PROPERTY(QString host READ host CONSTANT)
72
73
75 Q_PROPERTY(quint16 port READ port CONSTANT)
76
77 //
78 // Getter Methods
79 //
80
85 [[nodiscard]] Traffic::ConnectionInfo connectionInfo() const override {
87 }
88
93 [[nodiscard]] QString dataFormat() const override { return u"APRS-IS"_s; }
94
99 [[nodiscard]] QString host() const
100 {
101 return m_hostName;
102 }
103
111 [[nodiscard]] QString icon() const override { return u"/icons/material/ic_wifi.svg"_s; }
112
120 [[nodiscard]] auto sourceName() const -> QString override
121 {
122 return tr("OGN glidernet.org APRS-IS connection");
123 }
124
129 [[nodiscard]] quint16 port() const
130 {
131 return m_port;
132 }
133
134public slots:
141
148
158 void sendPosition(const QGeoCoordinate& coordinate, double course, double speed, double altitude);
159
160private slots:
161
162 // Read lines from the socket's text stream and passes the string on to
163 // processAprsisMessage.
164 void onReadyRead();
165
166private:
167 Q_DISABLE_COPY_MOVE(TrafficDataSource_Ogn)
168
169 QTcpSocket m_socket;
170 QTextStream m_textStream;
171 QString m_hostName;
172 quint16 m_port;
173
174 Traffic::Ogn::OgnMessage m_ognMessage;
175
176 // our own CallSign
177 QString m_callSign;
178
179 // our own AircraftType
180 Traffic::AircraftType m_aircraftType = {Traffic::AircraftType::Aircraft};
181
182 // Radius around the approximate position for which traffic data is requested.
183 static constexpr Units::Distance m_receiveRadius = Units::Distance::fromKM(50);
184
185 // Periodic update function called once per minute
186 void periodicUpdate();
187
188 // Send a keep-alive message to the APRS-IS server
189 void sendKeepAlive();
190
191 // Verify the connection to the APRS-IS server and reconnect if necessary
192 void verifyConnection();
193};
194
195} // namespace Traffic
Connection to a traffic data receiver.
TrafficDataSource_AbstractSocket(bool isCanonical, QObject *parent)
Default constructor.
void connectToTrafficReceiver() override
Start attempt to connect to traffic receiver.
QString dataFormat() const override
Getter function for the property with the same name.
void sendPosition(const QGeoCoordinate &coordinate, double course, double speed, double altitude)
Send position report to APRS-IS server.
void disconnectFromTrafficReceiver() override
Disconnect from traffic receiver.
quint16 port() const
Getter function for the property with the same name.
TrafficDataSource_Ogn(bool isCanonical, QString hostName, quint16 port, QObject *parent=nullptr)
Default constructor.
QString host() const
Getter function for the property with the same name.
Traffic::ConnectionInfo connectionInfo() const override
Getter function for the property with the same name.
QString icon() const override
Getter function for the property with the same name.
auto sourceName() const -> QString override
Getter function for the property with the same name.
Convenience class for distance computations.
Definition Distance.h:35
static Q_INVOKABLE constexpr Units::Distance fromKM(double distanceInKM)
Constructs a distance.
Definition Distance.h:69
Constructor parameter for OGN connections.