Enroute Flight Navigation
A navigation app for VFR pilots
TrafficDataSource_BluetoothClassic.h
1/***************************************************************************
2 * Copyright (C) 2024 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 <QBluetoothDeviceInfo>
24#include <QBluetoothPermission>
25#include <QBluetoothSocket>
26
27#include "traffic/TrafficDataSource_AbstractSocket.h"
28
29using namespace Qt::Literals::StringLiterals;
30
31
32namespace Traffic {
33
39
41 Q_OBJECT
42
43public:
53 TrafficDataSource_BluetoothClassic(bool isCanonical, const QBluetoothDeviceInfo& info, QObject* parent);
54
55 // Standard destructor
56 ~TrafficDataSource_BluetoothClassic() override = default;
57
58
59
60 //
61 // Properties
62 //
63
68 Q_PROPERTY(QBluetoothDeviceInfo sourceInfo READ sourceInfo CONSTANT)
69
70
71
72 //
73 // Getter Methods
74 //
75
76
80 [[nodiscard]] QString dataFormat() const override { return u"FLARM/NMEA"_s; }
81
89 [[nodiscard]] QString icon() const override { return u"/icons/material/ic_bluetooth.svg"_s; }
90
98 [[nodiscard]] QString sourceName() const override;
99
104 [[nodiscard]] QBluetoothDeviceInfo sourceInfo() const
105 {
106 return m_info;
107 }
108
109
110public slots:
117
124
125private slots:
126 // Handle BT socket errors
127 void onErrorOccurred(QBluetoothSocket::SocketError error);
128
129 // Handle BT socket state changes
130 void onStateChanged(QBluetoothSocket::SocketState state);
131
132 // Read and process received NMEA sentences
133 void onReadyRead();
134
135private:
136 Q_DISABLE_COPY_MOVE(TrafficDataSource_BluetoothClassic)
137
138 // Copied from the constructor
139 QBluetoothDeviceInfo m_info;
140
141 // Permissions
142 QBluetoothPermission m_bluetoothPermission;
143
144 // Bluetooth socket used for reading data
145 QBluetoothSocket m_socket {QBluetoothServiceInfo::RfcommProtocol};
146
147 // Text stream used for reading NMEA sentences
148 QTextStream m_textStream {&m_socket};
149};
150
151} // namespace Traffic
TrafficDataSource_AbstractSocket(bool isCanonical, QObject *parent)
Default constructor.
void connectToTrafficReceiver() override
Start attempt to connect to traffic receiver.
QString dataFormat() const override
Getter function for the property with the same name.
void disconnectFromTrafficReceiver() override
Disconnect from traffic receiver.
QString sourceName() const override
Getter function for the property with the same name.
TrafficDataSource_BluetoothClassic(bool isCanonical, const QBluetoothDeviceInfo &info, QObject *parent)
Default constructor.
QString icon() const override
Getter function for the property with the same name.
QBluetoothDeviceInfo sourceInfo() const
Getter function for the property with the same name.