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 <QBluetoothDeviceDiscoveryAgent>
24#include <QBluetoothDeviceInfo>
25#include <QBluetoothLocalDevice>
26#include <QBluetoothPermission>
27#include <QBluetoothServiceInfo>
28#include <QBluetoothSocket>
29#include <QLowEnergyController>
30
31#include "traffic/TrafficDataSource_AbstractSocket.h"
32
33using namespace Qt::Literals::StringLiterals;
34
35
36namespace Traffic {
37
72
74 Q_OBJECT
75
76public:
85 TrafficDataSource_BluetoothLowEnergy(bool isCanonical, const QBluetoothDeviceInfo& info, QObject* parent);
86
87 // Standard destructor
88 ~TrafficDataSource_BluetoothLowEnergy() override = default;
89
90
91
92 //
93 // Properties
94 //
95
100 Q_PROPERTY(QBluetoothDeviceInfo sourceInfo READ sourceInfo CONSTANT)
101
102
103
104 //
105 // Getter Methods
106 //
107
108
112 [[nodiscard]] QString dataFormat() const override { return u"FLARM/NMEA"_s; }
113
121 [[nodiscard]] QString icon() const override { return u"/icons/material/ic_bluetooth.svg"_s; }
122
130 [[nodiscard]] QString sourceName() const override;
131
136 [[nodiscard]] QBluetoothDeviceInfo sourceInfo() const
137 {
138 return m_info;
139 }
140
141
142public slots:
149
156
157private slots:
158 // Read and process NMEA sentences
159 void onCharacteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &newValue);
160
161 // Device discovery slots
162 void onDeviceDiscovered(const QBluetoothDeviceInfo &info);
163 void onDiscoveryFinished();
164
165 // Handle errors
166 void onControlerError(QLowEnergyController::Error error);
167
168 void onServiceDiscoveryFinished();
169 void onDiscoveryError(QBluetoothDeviceDiscoveryAgent::Error error);
170
171 void onServiceStateChanged(QLowEnergyService::ServiceState newState);
172
173 void onStateChanged(QLowEnergyController::ControllerState state);
174
175private:
176 Q_DISABLE_COPY_MOVE(TrafficDataSource_BluetoothLowEnergy)
177
178 // Permissions
179 QBluetoothPermission m_bluetoothPermission;
180
181 // Copied from the constructor
182 QBluetoothDeviceInfo m_info;
183
184 // Device discovery
185 QBluetoothDeviceDiscoveryAgent* m_discoveryAgent {nullptr};
186
187 // Helper to setup the controller since we'll recreate it often
188 void setupController(const QBluetoothDeviceInfo &info);
189 QLowEnergyController* m_control {nullptr};
190
191 QLowEnergyService* m_nordicUARTService {nullptr};
192 QBluetoothUuid const nordicUARTServiceUuid {"6e400001-b5a3-f393-e0a9-e50e24dcca9e"};
193 QBluetoothUuid const nordicUARTTxCharacteristicID {"6e400003-b5a3-f393-e0a9-e50e24dcca9e"};
194
195 QLowEnergyService* m_simpleUARTService {nullptr};
196 QBluetoothUuid const simpleUARTServiceUuid {"0000ffe0-0000-1000-8000-00805f9b34fb"};
197 QBluetoothUuid const simpleUARTCharacteristicID {"0000ffe1-0000-1000-8000-00805f9b34fb"};
198};
199
200} // 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.