Enroute Flight Navigation
A navigation app for VFR pilots
TrafficDataSource_SerialPort.h
1/***************************************************************************
2 * Copyright (C) 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#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
85 Q_PROPERTY(ConnectionInfo::BaudRate baudRate READ baudRate BINDABLE bindableBaudRate WRITE setBaudRate)
86 [[nodiscard]] ConnectionInfo::BaudRate baudRate() { return m_baudRate.value();};
87 [[nodiscard]] QBindable<ConnectionInfo::BaudRate> bindableBaudRate() { return &m_baudRate;};
88 void setBaudRate(ConnectionInfo::BaudRate rate);
89
91 Q_PROPERTY(ConnectionInfo::StopBits stopBits READ stopBits BINDABLE bindableStopBits WRITE setStopBits)
92 [[nodiscard]] ConnectionInfo::StopBits stopBits() { return m_stopBits.value();};
93 [[nodiscard]] QBindable<ConnectionInfo::StopBits> bindableStopBits() { return &m_stopBits;};
94 void setStopBits(ConnectionInfo::StopBits sb);
95
97 Q_PROPERTY(ConnectionInfo::FlowControl flowControl READ flowControl BINDABLE bindableFlowControl WRITE setFlowControl)
98 [[nodiscard]] ConnectionInfo::FlowControl flowControl() { return m_flowControl.value();};
99 [[nodiscard]] QBindable<ConnectionInfo::FlowControl> bindableFlowControl() { return &m_flowControl;};
100 void setFlowControl(ConnectionInfo::FlowControl fc);
101
102
103 //
104 // Getter Methods
105 //
106
111 [[nodiscard]] QString dataFormat() const override { return u"FLARM/NMEA"_s; }
112
120 [[nodiscard]] QString icon() const override { return u"/icons/material/ic_settings_ethernet.svg"_s; }
121
129 [[nodiscard]] QString sourceName() const override;
130
131
132public slots:
139
146
147private slots:
148#if __has_include(<QSerialPortInfo>)
149 // Handle serial port errors
150 void onErrorOccurred(QSerialPort::SerialPortError error);
151#endif
152
153 // Read and process received NMEA sentences
154 void onReadyRead();
155
156private:
157 Q_DISABLE_COPY_MOVE(TrafficDataSource_SerialPort)
158
159 // Copied from the constructor
160#if __has_include(<QSerialPortInfo>)
161 QSerialPort* m_port {nullptr};
162 QTextStream* m_textStream {nullptr};
163#endif
164 QString m_portNameOrDescription;
165 QProperty<ConnectionInfo::BaudRate> m_baudRate {ConnectionInfo::BaudRate::Baud9600};
166 QProperty<ConnectionInfo::StopBits> m_stopBits {ConnectionInfo::StopBits::OneStop};
167 QProperty<ConnectionInfo::FlowControl> m_flowControl {ConnectionInfo::FlowControl::NoFlowControl};
168};
169
170} // 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.