Enroute Flight Navigation
A navigation app for VFR pilots
TrafficDataSource_SerialPort.h
1/***************************************************************************
2 * Copyright (C) 2025-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#if __has_include(<QSerialPortInfo>)
24#include <QSerialPort>
25#include <QSerialPortInfo>
26#endif
27
28#include <QPropertyNotifier>
29
30#include "traffic/TrafficDataSource_Abstract.h"
31
32using namespace Qt::Literals::StringLiterals;
33
34
35namespace Traffic {
36
41
43 Q_OBJECT
44
45public:
67 TrafficDataSource_SerialPort(bool isCanonical, const QString& portNameOrDescription,
68 ConnectionInfo::BaudRate baudRate,
69 ConnectionInfo::StopBits stopBits,
70 ConnectionInfo::FlowControl flowControl,
71 QObject* parent);
72
73 // Standard destructor
75
76
81 Q_PROPERTY(QString portNameOrDescription READ portNameOrDescription CONSTANT)
82 [[nodiscard]] QString portNameOrDescription() const {return m_portNameOrDescription;};
83
88 Q_PROPERTY(ConnectionInfo::BaudRate baudRate READ baudRate BINDABLE bindableBaudRate WRITE setBaudRate)
89 [[nodiscard]] ConnectionInfo::BaudRate baudRate() { return m_baudRate.value();};
90 [[nodiscard]] QBindable<ConnectionInfo::BaudRate> bindableBaudRate() { return &m_baudRate;};
91 void setBaudRate(ConnectionInfo::BaudRate rate);
92
97 Q_PROPERTY(ConnectionInfo::StopBits stopBits READ stopBits BINDABLE bindableStopBits WRITE setStopBits)
98 [[nodiscard]] ConnectionInfo::StopBits stopBits() { return m_stopBits.value();};
99 [[nodiscard]] QBindable<ConnectionInfo::StopBits> bindableStopBits() { return &m_stopBits;};
100 void setStopBits(ConnectionInfo::StopBits sb);
101
106 Q_PROPERTY(ConnectionInfo::FlowControl flowControl READ flowControl BINDABLE bindableFlowControl WRITE setFlowControl)
107 [[nodiscard]] ConnectionInfo::FlowControl flowControl() { return m_flowControl.value();};
108 [[nodiscard]] QBindable<ConnectionInfo::FlowControl> bindableFlowControl() { return &m_flowControl;};
109 void setFlowControl(ConnectionInfo::FlowControl fc);
110
111
112 //
113 // Getter Methods
114 //
115
120 [[nodiscard]] QString dataFormat() const override { return u"FLARM/NMEA"_s; }
121
129 [[nodiscard]] QString icon() const override { return u"/icons/material/ic_settings_ethernet.svg"_s; }
130
138 [[nodiscard]] QString sourceName() const override;
139
140
141public slots:
148
155
156private slots:
157#if __has_include(<QSerialPortInfo>)
158 // Handle serial port errors
159 void onErrorOccurred(QSerialPort::SerialPortError error);
160
161 // Read and process received NMEA sentences
162 void onReadyRead();
163#endif
164
165#if defined(Q_OS_ANDROID)
166 // Read and process received NMEA sentences
167 void read();
168#endif
169
170private:
171 Q_DISABLE_COPY_MOVE(TrafficDataSource_SerialPort)
172
173#if defined(Q_OS_ANDROID)
174 QTimer pollTimer;
175 void setParameters();
176#endif
177#if __has_include(<QSerialPortInfo>)
178 QSerialPort* m_port = nullptr;
179 QTextStream* m_textStream = nullptr;
180#endif
181 QString m_portNameOrDescription;
182 QProperty<ConnectionInfo::BaudRate> m_baudRate {ConnectionInfo::BaudRate::Baud9600};
183 QProperty<ConnectionInfo::StopBits> m_stopBits {ConnectionInfo::StopBits::OneStop};
184 QProperty<ConnectionInfo::FlowControl> m_flowControl {ConnectionInfo::FlowControl::NoFlowControl};
185};
186
187} // namespace Traffic
TrafficDataSource_Abstract(bool isCanonical, QObject *parent)
Default constructor.
QString sourceName() const override
Getter function for the property with the same name.
void disconnectFromTrafficReceiver() override
Disconnect from traffic receiver.
ConnectionInfo::StopBits stopBits
Stop Bits of the Serial Port Connection.
ConnectionInfo::BaudRate baudRate
Baud Rate of the Serial Port Connection.
QString icon() const override
Getter function for the property with the same name.
ConnectionInfo::FlowControl flowControl
Flow Control.
void connectToTrafficReceiver() override
Start attempt to connect to traffic receiver.
QString portNameOrDescription
Port Name or Description.
QString dataFormat() const override
Getter function for the property with the same name.
TrafficDataSource_SerialPort(bool isCanonical, const QString &portNameOrDescription, ConnectionInfo::BaudRate baudRate, ConnectionInfo::StopBits stopBits, ConnectionInfo::FlowControl flowControl, QObject *parent)
Default constructor.