Enroute Flight Navigation
A navigation app for VFR pilots
TrafficDataSource_BluetoothLowEnergy.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#include <QBluetoothDeviceInfo>
24#include <QBluetoothLocalDevice>
25#include <QBluetoothPermission>
26#include <QBluetoothServiceInfo>
27#include <QBluetoothSocket>
28#include <QLowEnergyController>
29
30#include "traffic/TrafficDataSource_AbstractSocket.h"
31
32using namespace Qt::Literals::StringLiterals;
33
34
35namespace Traffic {
36
71
73 Q_OBJECT
74
75public:
84 TrafficDataSource_BluetoothLowEnergy(bool isCanonical, const QBluetoothDeviceInfo& info, QObject* parent);
85
86 // Standard destructor
87 ~TrafficDataSource_BluetoothLowEnergy() override = default;
88
89
90
91 //
92 // Properties
93 //
94
99 Q_PROPERTY(QBluetoothDeviceInfo sourceInfo READ sourceInfo CONSTANT)
100
101
102
103 //
104 // Getter Methods
105 //
106
107
111 [[nodiscard]] QString dataFormat() const override { return u"FLARM/NMEA"_s; }
112
120 [[nodiscard]] QString icon() const override { return u"/icons/material/ic_bluetooth.svg"_s; }
121
129 [[nodiscard]] QString sourceName() const override;
130
135 [[nodiscard]] QBluetoothDeviceInfo sourceInfo() const
136 {
137 return m_info;
138 }
139
140
141public slots:
148
155
156private slots:
157 // Read and process NMEA sentences
158 void onCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue);
159
160 // Handle errors
161 void onErrorOccurred(QLowEnergyController::Error error);
162
163 void onServiceDiscoveryFinished();
164
165 void onServiceStateChanged(QLowEnergyService::ServiceState newState);
166
167 void onStateChanged(QLowEnergyController::ControllerState state);
168
169private:
170 Q_DISABLE_COPY_MOVE(TrafficDataSource_BluetoothLowEnergy)
171
172 // Permissions
173 QBluetoothPermission m_bluetoothPermission;
174
175 // Copied from the constructor
176 QBluetoothDeviceInfo m_info;
177
178 QLowEnergyController* m_control {nullptr};
179
180 QLowEnergyService* m_nordicUARTService {nullptr};
181 QBluetoothUuid const nordicUARTServiceUuid {"6e400001-b5a3-f393-e0a9-e50e24dcca9e"};
182 QBluetoothUuid const nordicUARTTxCharacteristicID {"6e400003-b5a3-f393-e0a9-e50e24dcca9e"};
183
184 QLowEnergyService* m_simpleUARTService {nullptr};
185 QBluetoothUuid const simpleUARTServiceUuid {"0000ffe0-0000-1000-8000-00805f9b34fb"};
186 QBluetoothUuid const simpleUARTCharacteristicID {"0000ffe1-0000-1000-8000-00805f9b34fb"};
187};
188
189} // namespace Traffic
TrafficDataSource_AbstractSocket(bool isCanonical, QObject *parent)
Default constructor.
QString icon() const override
Getter function for the property with the same name.
TrafficDataSource_BluetoothLowEnergy(bool isCanonical, const QBluetoothDeviceInfo &info, QObject *parent)
Default constructor.
QBluetoothDeviceInfo sourceInfo() const
Getter function for the property with the same name.
QString dataFormat() const override
Getter function for the property with the same name.
void connectToTrafficReceiver() override
Start attempt to connect to traffic receiver.
void disconnectFromTrafficReceiver() override
Disconnect from traffic receiver.
QString sourceName() const override
Getter function for the property with the same name.