Enroute Flight Navigation
A navigation app for VFR pilots
TrafficDataSource_Abstract.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 <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/Warning.h"
30
31
32namespace Traffic {
33
42class TrafficDataSource_Abstract : public QObject {
43 Q_OBJECT
44
45public:
52 TrafficDataSource_Abstract(bool isCanonical, QObject* parent);
53
54 // Standard destructor
55 ~TrafficDataSource_Abstract() override = default;
56
57
58
59 //
60 // Properties
61 //
62
68 Q_PROPERTY(bool canonical READ canonical CONSTANT)
69
70
82
88 Q_PROPERTY(Traffic::ConnectionInfo connectionInfo READ connectionInfo CONSTANT)
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
116
128
135 Q_PROPERTY(QString sourceName READ sourceName CONSTANT)
136
145
154
155
156
157 //
158 // Getter methods
159 //
160
165 [[nodiscard]] bool canonical() const
166 {
167 return m_canonical;
168 }
169
174 [[nodiscard]] virtual Traffic::ConnectionInfo connectionInfo() const { return {}; }
175
180 [[nodiscard]] QString connectivityStatus() const
181 {
182 return m_connectivityStatus;
183 }
184
189 [[nodiscard]] virtual QString dataFormat() const = 0;
190
195 [[nodiscard]] QString errorString() const
196 {
197 return m_errorString;
198 }
199
204 [[nodiscard]] virtual QString icon() const = 0;
205
210 [[nodiscard]] Units::Distance pressureAltitude() const {return m_pressureAltitude.value();}
211
216 [[nodiscard]] QBindable<Units::Distance> bindablePressureAltitude() const
217 {
218 return &m_pressureAltitude;
219 }
220
225 [[nodiscard]] bool receivingHeartbeat() const
226 {
227 return m_receivingHeartbeat.value();
228 }
229
234 [[nodiscard]] QBindable<bool> bindableReceivingHeartbeat() const
235 {
236 return &m_receivingHeartbeat;
237 }
238
243 [[nodiscard]] virtual QString sourceName() const = 0;
244
249 [[nodiscard]] QString trafficReceiverRuntimeError() const
250 {
251 return m_trafficReceiverRuntimeError.value();
252 }
253
258 [[nodiscard]] QBindable<QString> bindableTrafficReceiverRuntimeError()
259 {
260 return &m_trafficReceiverRuntimeError;
261 }
262
267 [[nodiscard]] QString trafficReceiverSelfTestError() const
268 {
269 return m_trafficReceiverSelfTestError.value();
270 }
271
276 [[nodiscard]] QBindable<QString> bindableTrafficReceiverSelfTestError()
277 {
278 return &m_trafficReceiverSelfTestError;
279 }
280
281
282signals:
284 void connectivityStatusChanged(QString newStatus);
285
287 void errorStringChanged(QString newError);
288
297
306
307 /* \brief Password request
308 *
309 * This signal is emitted whenever the traffic receiver asks for a
310 * password. Note that this is not the WiFi-Password.
311 *
312 * @param SSID Name of the WiFi network that is currently in use.
313 */
314 void passwordRequest(const QString& SSID);
315
316 /* \brief Password storage request
317 *
318 * This signal is emitted whenever the traffic receiver has successfully
319 * connected using a password that was not yet in the database.
320 *
321 * @param SSID Name of the WiFi network that is was used in use.
322 */
323 void passwordStorageRequest(const QString& SSID, const QString& password);
324
331
334
342 void trafficReceiverHwVersion(QString result);
343
351 void trafficReceiverObVersion(QString result);
352
360 void trafficReceiverSwVersion(QString result);
361
372
373public slots:
380 virtual void connectToTrafficReceiver() = 0;
381
390
399 virtual void setPassword(const QString& SSID, const QString& password)
400 {
401 Q_UNUSED(SSID)
402 Q_UNUSED(password)
403 }
404
405protected:
412 void processAPRS(const QString& data);
413
421 void processFLARMData(const QString& data);
422
432 void processGDLMessage(const QByteArray& message);
433
445 void processXGPSString(const QByteArray& data);
446
452
457 void setConnectivityStatus(const QString& newConnectivityStatus);
458
463 void setErrorString(const QString& newErrorString = QString());
464
473 void setPressureAltitude(Units::Distance newPressureAltitude);
474
482 void setReceivingHeartbeat(bool newReceivingHeartbeat);
483
484 QProperty<QString> m_trafficReceiverRuntimeError;
485 QProperty<QString> m_trafficReceiverSelfTestError;
486
487private:
488 Q_DISABLE_COPY_MOVE(TrafficDataSource_Abstract)
489
490 /* This method expects exactly one line containing a valid FLARM/NMEA
491 * sentence. This is a string typically looks like
492 * "$PFLAA,0,1587,1588,40,1,AA1237,225,,37,-1.6,1*7F". The method
493 * interprets the string and updates the properties and emits signals as
494 * appropriate. Invalid strings are silently ignored.
495 */
496 void processFLARMSentence(const QString& sentence);
497 // Methods interpreting specific FLARM/NMEA messages
498 void processFLARMMessageGPGGA(const QStringList& arguments); // NMEA GPS 3D-fix data
499 void processFLARMMessageGPRMC(const QStringList& arguments); // Recommended minimum specific GPS/Transit data
500 void processFLARMMessagePFLAA(const QStringList& arguments); // Data on other proximate aircraft
501 void processFLARMMessagePFLAE(const QStringList& arguments); // Self-test result and errors codes
502 static void processFLARMMessagePFLAS(const QStringList& arguments); // Debug Information
503 void processFLARMMessagePFLAU(const QStringList& arguments); // FLARM Heartbeat
504 void processFLARMMessagePFLAV(const QStringList& arguments); // Version information
505 void processFLARMMessagePGRMZ(const QStringList& arguments); // Garmin's barometric altitude
506 static void processFLARMMessagePXCV(const QStringList& arguments); // XCVario
507 QString m_FLARMDataBuffer;
508
509 // Property caches
510 bool m_canonical {false};
511 QString m_connectivityStatus;
512 QString m_errorString;
513
514 // True altitude of own aircraft. We store these values because the
515 // necessary information to compile a PositionInfo class does not always
516 // come in one piece. Whenever a valid altitude is set, the timer should be
517 // started. The timer can then be used to check if the altitude information
518 // is recent enough to be used. Whenever an invalid altitude is set, the
519 // timer should be stopped.
520 Units::Distance m_trueAltitude;
521 Units::Distance m_trueAltitudeFOM; // Fig. of Merit
522 QTimer m_trueAltitudeTimer;
523
524 // Pressure altitude of own aircraft. The timer will reset the pressureAltitude
525 // to an invalid value if no data is received for a while.
526 QProperty<Units::Distance> m_pressureAltitude;
527 QTimer m_pressureAltitudeTimer;
528
529 // Heartbeat timer
530 QTimer m_heartbeatTimer;
531 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(Traffic::TrafficDataSource_Abstract, bool, m_receivingHeartbeat, false, &Traffic::TrafficDataSource_Abstract::receivingHeartbeatChanged);
532
533 // Targets
535 Traffic::TrafficFactor_DistanceOnly m_factorDistanceOnly;
536};
537
538} // 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.
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.
TrafficDataSource_Abstract(bool isCanonical, QObject *parent)
Default constructor.
void errorStringChanged(QString newError)
Notifier signal.
void connectivityStatusChanged(QString newStatus)
Notifier signal.
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.
virtual Traffic::ConnectionInfo connectionInfo() 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.
void factorWithPosition(const Traffic::TrafficFactor_WithPosition &factor)
Traffic factor with position.
Units::Distance pressureAltitude() const
Getter method for property with the same name.
QString trafficReceiverRuntimeError
String describing the last traffic data receiver runtime error.
void receivingHeartbeatChanged(bool)
Notifier signal.
QBindable< QString > bindableTrafficReceiverSelfTestError()
Getter function for the property with the same name.
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 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.
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.
QString errorString
String describing the last socket error.
QString errorString() const
Getter function for the property with the same name.
void factorWithoutPosition(const Traffic::TrafficFactor_DistanceOnly &factor)
Traffic factor without position.
void positionUpdated(Positioning::PositionInfo pInfo)
Position info.
QString trafficReceiverSelfTestError
String describing the last traffic data receiver self-test error.
void trafficReceiverObVersion(QString result)
Traffic receiver obstacle database version.
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 factor where only distance is known.
Traffic factor whose precise position is known.
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