Enroute Flight Navigation
A navigation app for VFR pilots
TrafficDataSource_Abstract.h
1/***************************************************************************
2 * Copyright (C) 2021-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 <QProperty>
24
25#include "positioning/PositionInfo.h"
26#include "traffic/ConnectionInfo.h"
27#include "traffic/TrafficFactor_DistanceOnly.h"
28#include "traffic/TrafficFactor_WithPosition.h"
29#include "traffic/TrafficFactorData.h"
30#include "traffic/Warning.h"
31
32
33namespace Traffic {
34
43class TrafficDataSource_Abstract : public QObject {
44 Q_OBJECT
45
46public:
53 TrafficDataSource_Abstract(bool isCanonical, QObject* parent);
54
55 // Standard destructor
56 ~TrafficDataSource_Abstract() override = default;
57
58
59 //
60 // Properties
61 //
62
68 Q_PROPERTY(bool canonical READ canonical CONSTANT)
69
70
82
89
94 Q_PROPERTY(QString dataFormat READ dataFormat CONSTANT)
95
102 Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged)
103
105 Q_PROPERTY(QString icon READ icon CONSTANT)
106
114 Q_PROPERTY(Positioning::PositionInfo positionInfo READ positionInfo BINDABLE bindablePositionInfo)
115
125
137
144 Q_PROPERTY(QString sourceName READ sourceName CONSTANT)
145
154
163
164
165
166 //
167 // Getter methods
168 //
169
174 [[nodiscard]] bool canonical() const
175 {
176 return m_canonical;
177 }
178
183 [[nodiscard]] Traffic::ConnectionInfo connectionInfo() const { return m_connectionInfo.value(); }
184
189 [[nodiscard]] QBindable<Traffic::ConnectionInfo> bindableConnectionInfo() const { return &m_connectionInfo; }
190
195 [[nodiscard]] QString connectivityStatus() const
196 {
197 return m_connectivityStatus;
198 }
199
204 [[nodiscard]] virtual QString dataFormat() const = 0;
205
210 [[nodiscard]] QString errorString() const
211 {
212 return m_errorString;
213 }
214
219 [[nodiscard]] virtual QString icon() const = 0;
220
226 {
227 return m_positionInfo.value();
228 }
229
234 [[nodiscard]] QBindable<Positioning::PositionInfo> bindablePositionInfo() const
235 {
236 return &m_positionInfo;
237 }
238
243 [[nodiscard]] Units::Distance pressureAltitude() const {return m_pressureAltitude.value();}
244
249 [[nodiscard]] QBindable<Units::Distance> bindablePressureAltitude() const
250 {
251 return &m_pressureAltitude;
252 }
253
258 [[nodiscard]] bool receivingHeartbeat() const
259 {
260 return m_receivingHeartbeat.value();
261 }
262
267 [[nodiscard]] QBindable<bool> bindableReceivingHeartbeat() const
268 {
269 return &m_receivingHeartbeat;
270 }
271
276 [[nodiscard]] virtual QString sourceName() const = 0;
277
282 [[nodiscard]] QString trafficReceiverRuntimeError() const
283 {
284 return m_trafficReceiverRuntimeError.value();
285 }
286
291 [[nodiscard]] QBindable<QString> bindableTrafficReceiverRuntimeError()
292 {
293 return &m_trafficReceiverRuntimeError;
294 }
295
300 [[nodiscard]] QString trafficReceiverSelfTestError() const
301 {
302 return m_trafficReceiverSelfTestError.value();
303 }
304
309 [[nodiscard]] QBindable<QString> bindableTrafficReceiverSelfTestError()
310 {
311 return &m_trafficReceiverSelfTestError;
312 }
313
314
315signals:
320 void connectivityStatusChanged(QString newStatus);
321
326 void dataReceived(QString data);
327
332 void errorStringChanged(QString newError);
333
342
351
359 void passwordRequest(const QString& SSID);
360
370 void passwordStorageRequest(const QString& SSID, const QString& password);
371
376 void receivingHeartbeatChanged(bool newReceivingHeartbeat);
377
385 void trafficReceiverHwVersion(QString result);
386
394 void trafficReceiverObVersion(QString result);
395
403 void trafficReceiverSwVersion(QString result);
404
415
416public slots:
423 virtual void connectToTrafficReceiver() = 0;
424
433
442 virtual void setPassword(const QString& SSID, const QString& password)
443 {
444 Q_UNUSED(SSID)
445 Q_UNUSED(password)
446 }
447
448protected:
455 void processAPRS(const QString& data);
456
464 void processFLARMData(const QString& data);
465
475 void processGDLMessage(const QByteArray& message);
476
489 void processXGPSString(const QByteArray& data);
490
496
501 void setConnectivityStatus(const QString& newConnectivityStatus);
502
507 void setErrorString(const QString& newErrorString = QString());
508
518
527 void setPressureAltitude(Units::Distance newPressureAltitude);
528
536 void setReceivingHeartbeat(bool newReceivingHeartbeat);
537
538protected:
539 QProperty<QString> m_trafficReceiverRuntimeError;
540 QProperty<QString> m_trafficReceiverSelfTestError;
541 QProperty<Traffic::ConnectionInfo> m_connectionInfo;
542
543private:
544 Q_DISABLE_COPY_MOVE(TrafficDataSource_Abstract)
545
546 /* This method expects exactly one line containing a valid FLARM/NMEA
547 * sentence. This is a string typically looks like
548 * "$PFLAA,0,1587,1588,40,1,AA1237,225,,37,-1.6,1*7F". The method
549 * interprets the string and updates the properties and emits signals as
550 * appropriate. Invalid strings are silently ignored.
551 */
552 void processFLARMSentence(const QString& sentence);
553 // Methods interpreting specific FLARM/NMEA messages
554 void processFLARMMessageGxGGA(const QStringList& arguments); // NMEA GPS 3D-fix data
555 void processFLARMMessageGxRMC(const QStringList& arguments); // Recommended minimum specific GPS/Transit data
556 void processFLARMMessagePFLAA(const QStringList& arguments); // Data on other proximate aircraft
557 void processFLARMMessagePFLAE(const QStringList& arguments); // Self-test result and errors codes
558 static void processFLARMMessagePFLAS(const QStringList& arguments); // Debug Information
559 void processFLARMMessagePFLAU(const QStringList& arguments); // FLARM Heartbeat
560 void processFLARMMessagePFLAV(const QStringList& arguments); // Version information
561 void processFLARMMessagePGRMZ(const QStringList& arguments); // Garmin's barometric altitude
562 void processFLARMMessagePXCV(const QStringList& arguments); // XCVario
563 QString m_FLARMDataBuffer;
564
565 // Property caches
566 bool m_canonical = false;
567 QString m_connectivityStatus;
568 QString m_errorString;
569
570 // True altitude of own aircraft. We store these values because the
571 // necessary information to compile a PositionInfo class does not always
572 // come in one piece. Whenever a valid altitude is set, the timer should be
573 // started. The timer can then be used to check if the altitude information
574 // is recent enough to be used. Whenever an invalid altitude is set, the
575 // timer should be stopped.
576 Units::Distance m_trueAltitude;
577 Units::Distance m_trueAltitudeFOM; // Fig. of Merit
578 QTimer m_trueAltitudeTimer;
579
580 // Pressure altitude of own aircraft. The timer will reset the pressureAltitude
581 // to an invalid value if no data is received for a while.
582 QProperty<Units::Distance> m_pressureAltitude;
583 QTimer m_pressureAltitudeTimer;
584
585 // Heartbeat timer
586 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(Traffic::TrafficDataSource_Abstract, bool, m_receivingHeartbeat, false, &Traffic::TrafficDataSource_Abstract::receivingHeartbeatChanged);
587 QTimer m_heartbeatTimer;
588
589 // Position Info for ownship
590 QProperty<Positioning::PositionInfo> m_positionInfo;
591 QTimer m_positionInfoTimer;
592};
593
594} // namespace Traffic
Geographic position.
Connection to a traffic data receiver.
Base class for all traffic receiver data sources.
virtual QString dataFormat() const =0
Getter function for the property with the same name.
Positioning::PositionInfo positionInfo
Position information.
Positioning::PositionInfo positionInfo() const
Getter method for property with the same name.
QString icon
Icon that can be used to represent the connection in a GUI.
bool receivingHeartbeat() const
Getter function for the property with the same name.
QString trafficReceiverRuntimeError() const
Getter function for the property with the same name.
void processAPRS(const QString &data)
Process APRS-IS data.
QBindable< Traffic::ConnectionInfo > bindableConnectionInfo() const
Getter function for the property with the same name.
TrafficDataSource_Abstract(bool isCanonical, QObject *parent)
Default constructor.
void errorStringChanged(QString newError)
Notifier signal.
void connectivityStatusChanged(QString newStatus)
Notifier signal.
Traffic::ConnectionInfo connectionInfo() const
Getter function for the property with the same name.
QString trafficReceiverSelfTestError() const
Getter function for the property with the same name.
void processXGPSString(const QByteArray &data)
Process one XGPS string.
QString connectivityStatus() const
Getter function for the property with the same name.
void setReceivingHeartbeat(bool newReceivingHeartbeat)
Setter method for the property with the same name.
void setErrorString(const QString &newErrorString=QString())
Setter function for the property with the same name.
virtual void setPassword(const QString &SSID, const QString &password)
Set password.
void warning(const Traffic::Warning &warning)
Traffic warning.
void resetReceivingHeartbeat()
Resetter method for the property with the same name.
Units::Distance pressureAltitude
Pressure altitude.
void processGDLMessage(const QByteArray &message)
Process one GDL90 message.
void trafficReceiverHwVersion(QString result)
Traffic receiver hardware version.
Units::Distance pressureAltitude() const
Getter method for property with the same name.
void setPositionInfo(const Positioning::PositionInfo &info)
Setter function for the property with the same name.
QString trafficReceiverRuntimeError
String describing the last traffic data receiver runtime error.
void dataReceived(QString data)
Indicates new data has arrived, can be used in the GUI for monitoring purposes.
QBindable< QString > bindableTrafficReceiverSelfTestError()
Getter function for the property with the same name.
void passwordStorageRequest(const QString &SSID, const QString &password)
Password storage request.
virtual void connectToTrafficReceiver()=0
Start attempt to connect to traffic receiver.
QBindable< bool > bindableReceivingHeartbeat() const
Getter function for the property with the same name.
void factorWithoutPosition(const Traffic::TrafficFactorData_DistanceOnly &factor)
Traffic factor without position.
void processFLARMData(const QString &data)
Process FLARM/NMEA data.
virtual QString icon() const =0
Getter function for the property with the same name.
Traffic::ConnectionInfo connectionInfo
Connection Info.
void passwordRequest(const QString &SSID)
Password request.
QBindable< Units::Distance > bindablePressureAltitude() const
Getter method for property with the same name.
void setPressureAltitude(Units::Distance newPressureAltitude)
Setter function for the property with the same name.
virtual void disconnectFromTrafficReceiver()=0
Disconnect from traffic receiver.
void setConnectivityStatus(const QString &newConnectivityStatus)
Setter function for the property with the same name.
void trafficReceiverSwVersion(QString result)
Traffic receiver software version.
QBindable< Positioning::PositionInfo > bindablePositionInfo() const
Getter method for property with the same name.
QString errorString
String describing the last socket error.
void factorWithPosition(const Traffic::TrafficFactorData_WithPosition &factor)
Traffic factor with position.
QString errorString() const
Getter function for the property with the same name.
QString trafficReceiverSelfTestError
String describing the last traffic data receiver self-test error.
void trafficReceiverObVersion(QString result)
Traffic receiver obstacle database version.
void receivingHeartbeatChanged(bool newReceivingHeartbeat)
Notifier signal.
virtual QString sourceName() const =0
Getter function for the property with the same name.
QBindable< QString > bindableTrafficReceiverRuntimeError()
Getter function for the property with the same name.
Traffic warning.
Definition Warning.h:40
Convenience class for distance computations.
Definition Distance.h:35
Conversion between units used in aviation.
Definition Angle.h:34
Plain-data record of a traffic factor whose position is not known.
Plain-data record of a traffic factor whose precise position is known.