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;
252 }
253
258 [[nodiscard]] QString trafficReceiverSelfTestError() const
259 {
260 return m_trafficReceiverSelfTestError;
261 }
262
263
264signals:
266 void connectivityStatusChanged(QString newStatus);
267
269 void errorStringChanged(QString newError);
270
279
288
289 /* \brief Password request
290 *
291 * This signal is emitted whenever the traffic receiver asks for a
292 * password. Note that this is not the WiFi-Password.
293 *
294 * @param SSID Name of the WiFi network that is currently in use.
295 */
296 void passwordRequest(const QString& SSID);
297
298 /* \brief Password storage request
299 *
300 * This signal is emitted whenever the traffic receiver has successfully
301 * connected using a password that was not yet in the database.
302 *
303 * @param SSID Name of the WiFi network that is was used in use.
304 */
305 void passwordStorageRequest(const QString& SSID, const QString& password);
306
313
316
319
322
330 void trafficReceiverHwVersion(QString result);
331
339 void trafficReceiverObVersion(QString result);
340
348 void trafficReceiverSwVersion(QString result);
349
360
361public slots:
368 virtual void connectToTrafficReceiver() = 0;
369
378
387 virtual void setPassword(const QString& SSID, const QString& password)
388 {
389 Q_UNUSED(SSID)
390 Q_UNUSED(password)
391 }
392
393protected:
400 void processAPRS(const QString& data);
401
409 void processFLARMData(const QString& data);
410
420 void processGDLMessage(const QByteArray& message);
421
433 void processXGPSString(const QByteArray& data);
434
440
445 void setConnectivityStatus(const QString& newConnectivityStatus);
446
451 void setErrorString(const QString& newErrorString = QString());
452
461 void setPressureAltitude(Units::Distance newPressureAltitude);
462
470 void setReceivingHeartbeat(bool newReceivingHeartbeat);
471
476 void setTrafficReceiverRuntimeError(const QString& newErrorString);
477
482 void setTrafficReceiverSelfTestError(const QString& newErrorString);
483
484private:
485 Q_DISABLE_COPY_MOVE(TrafficDataSource_Abstract)
486
487 /* This method expects exactly one line containing a valid FLARM/NMEA
488 * sentence. This is a string typically looks like
489 * "$PFLAA,0,1587,1588,40,1,AA1237,225,,37,-1.6,1*7F". The method
490 * interprets the string and updates the properties and emits signals as
491 * appropriate. Invalid strings are silently ignored.
492 */
493 void processFLARMSentence(const QString& sentence);
494 // Methods interpreting specific FLARM/NMEA messages
495 void processFLARMMessageGPGGA(const QStringList& arguments); // NMEA GPS 3D-fix data
496 void processFLARMMessageGPRMC(const QStringList& arguments); // Recommended minimum specific GPS/Transit data
497 void processFLARMMessagePFLAA(const QStringList& arguments); // Data on other proximate aircraft
498 void processFLARMMessagePFLAE(const QStringList& arguments); // Self-test result and errors codes
499 static void processFLARMMessagePFLAS(const QStringList& arguments); // Debug Information
500 void processFLARMMessagePFLAU(const QStringList& arguments); // FLARM Heartbeat
501 void processFLARMMessagePFLAV(const QStringList& arguments); // Version information
502 void processFLARMMessagePGRMZ(const QStringList& arguments); // Garmin's barometric altitude
503 static void processFLARMMessagePXCV(const QStringList& arguments); // XCVario
504 QString m_FLARMDataBuffer;
505
506 // Property caches
507 bool m_canonical {false};
508 QString m_connectivityStatus;
509 QString m_errorString;
510 QString m_trafficReceiverRuntimeError;
511 QString m_trafficReceiverSelfTestError;
512
513 // True altitude of own aircraft. We store these values because the
514 // necessary information to compile a PositionInfo class does not always
515 // come in one piece. Whenever a valid altitude is set, the timer should be
516 // started. The timer can then be used to check if the altitude information
517 // is recent enough to be used. Whenever an invalid altitude is set, the
518 // timer should be stopped.
519 Units::Distance m_trueAltitude;
520 Units::Distance m_trueAltitudeFOM; // Fig. of Merit
521 QTimer m_trueAltitudeTimer;
522
523 // Pressure altitude of own aircraft. The timer will reset the pressureAltitude
524 // to an invalid value if no data is received for a while.
525 QProperty<Units::Distance> m_pressureAltitude;
526 QTimer m_pressureAltitudeTimer;
527
528 // Heartbeat timer
529 QTimer m_heartbeatTimer;
530 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(Traffic::TrafficDataSource_Abstract, bool, m_receivingHeartbeat, false, &Traffic::TrafficDataSource_Abstract::receivingHeartbeatChanged);
531
532 // Targets
534 Traffic::TrafficFactor_DistanceOnly m_factorDistanceOnly;
535};
536
537} // namespace Traffic
Geographic position.
Connection to a traffic data receiver.
Base class for all traffic receiver data sources.
void trafficReceiverSelfTestErrorChanged()
Notifier signal.
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.
void setTrafficReceiverSelfTestError(const QString &newErrorString)
Setter function for the property with the same name.
QString trafficReceiverRuntimeError
String describing the last traffic data receiver runtime error.
void receivingHeartbeatChanged(bool)
Notifier signal.
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.
void setTrafficReceiverRuntimeError(const QString &newErrorString)
Setter function for the property with the same name.
QString errorString() const
Getter function for the property with the same name.
void factorWithoutPosition(const Traffic::TrafficFactor_DistanceOnly &factor)
Traffic factor without position.
void trafficReceiverRuntimeErrorChanged()
Notifier signal.
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.
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