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 // Properties
60 //
61
67 Q_PROPERTY(bool canonical READ canonical CONSTANT)
68
69
81
88
93 Q_PROPERTY(QString dataFormat READ dataFormat CONSTANT)
94
101 Q_PROPERTY(QString errorString READ errorString WRITE setErrorString NOTIFY errorStringChanged)
102
104 Q_PROPERTY(QString icon READ icon CONSTANT)
105
113 Q_PROPERTY(Positioning::PositionInfo positionInfo READ positionInfo BINDABLE bindablePositionInfo)
114
124
136
143 Q_PROPERTY(QString sourceName READ sourceName CONSTANT)
144
153
162
163
164
165 //
166 // Getter methods
167 //
168
173 [[nodiscard]] bool canonical() const
174 {
175 return m_canonical;
176 }
177
182 [[nodiscard]] Traffic::ConnectionInfo connectionInfo() const { return m_connectionInfo.value(); }
183
188 [[nodiscard]] QBindable<Traffic::ConnectionInfo> bindableConnectionInfo() const { return &m_connectionInfo; }
189
194 [[nodiscard]] QString connectivityStatus() const
195 {
196 return m_connectivityStatus;
197 }
198
203 [[nodiscard]] virtual QString dataFormat() const = 0;
204
209 [[nodiscard]] QString errorString() const
210 {
211 return m_errorString;
212 }
213
218 [[nodiscard]] virtual QString icon() const = 0;
219
225 {
226 return m_positionInfo.value();
227 }
228
233 [[nodiscard]] QBindable<Positioning::PositionInfo> bindablePositionInfo() const
234 {
235 return &m_positionInfo;
236 }
237
242 [[nodiscard]] Units::Distance pressureAltitude() const {return m_pressureAltitude.value();}
243
248 [[nodiscard]] QBindable<Units::Distance> bindablePressureAltitude() const
249 {
250 return &m_pressureAltitude;
251 }
252
257 [[nodiscard]] bool receivingHeartbeat() const
258 {
259 return m_receivingHeartbeat.value();
260 }
261
266 [[nodiscard]] QBindable<bool> bindableReceivingHeartbeat() const
267 {
268 return &m_receivingHeartbeat;
269 }
270
275 [[nodiscard]] virtual QString sourceName() const = 0;
276
281 [[nodiscard]] QString trafficReceiverRuntimeError() const
282 {
283 return m_trafficReceiverRuntimeError.value();
284 }
285
290 [[nodiscard]] QBindable<QString> bindableTrafficReceiverRuntimeError()
291 {
292 return &m_trafficReceiverRuntimeError;
293 }
294
299 [[nodiscard]] QString trafficReceiverSelfTestError() const
300 {
301 return m_trafficReceiverSelfTestError.value();
302 }
303
308 [[nodiscard]] QBindable<QString> bindableTrafficReceiverSelfTestError()
309 {
310 return &m_trafficReceiverSelfTestError;
311 }
312
313
314signals:
316 void connectivityStatusChanged(QString newStatus);
317
319 void dataReceived(QString data);
320
322 void errorStringChanged(QString newError);
323
332
341
342 /* \brief Password request
343 *
344 * This signal is emitted whenever the traffic receiver asks for a
345 * password. Note that this is not the WiFi-Password.
346 *
347 * @param SSID Name of the WiFi network that is currently in use.
348 */
349 void passwordRequest(const QString& SSID);
350
351 /* \brief Password storage request
352 *
353 * This signal is emitted whenever the traffic receiver has successfully
354 * connected using a password that was not yet in the database.
355 *
356 * @param SSID Name of the WiFi network that is was used in use.
357 */
358 void passwordStorageRequest(const QString& SSID, const QString& password);
359
362
370 void trafficReceiverHwVersion(QString result);
371
379 void trafficReceiverObVersion(QString result);
380
388 void trafficReceiverSwVersion(QString result);
389
400
401public slots:
408 virtual void connectToTrafficReceiver() = 0;
409
418
427 virtual void setPassword(const QString& SSID, const QString& password)
428 {
429 Q_UNUSED(SSID)
430 Q_UNUSED(password)
431 }
432
433protected:
440 void processAPRS(const QString& data);
441
449 void processFLARMData(const QString& data);
450
460 void processGDLMessage(const QByteArray& message);
461
473 void processXGPSString(const QByteArray& data);
474
480
485 void setConnectivityStatus(const QString& newConnectivityStatus);
486
491 void setErrorString(const QString& newErrorString = QString());
492
502
511 void setPressureAltitude(Units::Distance newPressureAltitude);
512
520 void setReceivingHeartbeat(bool newReceivingHeartbeat);
521
522protected:
523 QProperty<QString> m_trafficReceiverRuntimeError;
524 QProperty<QString> m_trafficReceiverSelfTestError;
525 QProperty<Traffic::ConnectionInfo> m_connectionInfo;
526
527private:
528 Q_DISABLE_COPY_MOVE(TrafficDataSource_Abstract)
529
530 /* This method expects exactly one line containing a valid FLARM/NMEA
531 * sentence. This is a string typically looks like
532 * "$PFLAA,0,1587,1588,40,1,AA1237,225,,37,-1.6,1*7F". The method
533 * interprets the string and updates the properties and emits signals as
534 * appropriate. Invalid strings are silently ignored.
535 */
536 void processFLARMSentence(const QString& sentence);
537 // Methods interpreting specific FLARM/NMEA messages
538 void processFLARMMessageGPGGA(const QStringList& arguments); // NMEA GPS 3D-fix data
539 void processFLARMMessageGPRMC(const QStringList& arguments); // Recommended minimum specific GPS/Transit data
540 void processFLARMMessagePFLAA(const QStringList& arguments); // Data on other proximate aircraft
541 void processFLARMMessagePFLAE(const QStringList& arguments); // Self-test result and errors codes
542 static void processFLARMMessagePFLAS(const QStringList& arguments); // Debug Information
543 void processFLARMMessagePFLAU(const QStringList& arguments); // FLARM Heartbeat
544 void processFLARMMessagePFLAV(const QStringList& arguments); // Version information
545 void processFLARMMessagePGRMZ(const QStringList& arguments); // Garmin's barometric altitude
546 static void processFLARMMessagePXCV(const QStringList& arguments); // XCVario
547 QString m_FLARMDataBuffer;
548
549 // Property caches
550 bool m_canonical {false};
551 QString m_connectivityStatus;
552 QString m_errorString;
553
554 // True altitude of own aircraft. We store these values because the
555 // necessary information to compile a PositionInfo class does not always
556 // come in one piece. Whenever a valid altitude is set, the timer should be
557 // started. The timer can then be used to check if the altitude information
558 // is recent enough to be used. Whenever an invalid altitude is set, the
559 // timer should be stopped.
560 Units::Distance m_trueAltitude;
561 Units::Distance m_trueAltitudeFOM; // Fig. of Merit
562 QTimer m_trueAltitudeTimer;
563
564 // Pressure altitude of own aircraft. The timer will reset the pressureAltitude
565 // to an invalid value if no data is received for a while.
566 QProperty<Units::Distance> m_pressureAltitude;
567 QTimer m_pressureAltitudeTimer;
568
569 // Heartbeat timer
570 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(Traffic::TrafficDataSource_Abstract, bool, m_receivingHeartbeat, false, &Traffic::TrafficDataSource_Abstract::receivingHeartbeatChanged);
571 QTimer m_heartbeatTimer;
572
573 // Targets
575 Traffic::TrafficFactor_DistanceOnly m_factorDistanceOnly;
576
577 // Position Info for ownship
578 QProperty<Positioning::PositionInfo> m_positionInfo;
579 QTimer m_positionInfoTimer;
580};
581
582} // 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.
void factorWithPosition(const Traffic::TrafficFactor_WithPosition &factor)
Traffic factor with position.
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 receivingHeartbeatChanged(bool)
Notifier signal.
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.
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.
QBindable< Positioning::PositionInfo > bindablePositionInfo() const
Getter method for property with the same name.
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.
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