This repository has been archived on 2026-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
2019-10-09 09:48:07 +02:00

106 lines
3.2 KiB
C++

#ifndef BLUETOOTHSERVER_H
#define BLUETOOTHSERVER_H
#include <QObject>
#include <QTimer>
#include <QObject>
#include <QPointer>
#include <QLowEnergyHandle>
#include <QLowEnergyService>
#include <QBluetoothLocalDevice>
#include <QLowEnergyController>
#include <QLowEnergyServiceData>
#include <QLowEnergyCharacteristic>
#include <QLowEnergyDescriptorData>
#include <QLowEnergyAdvertisingData>
#include <QLowEnergyCharacteristicData>
#include <QLowEnergyConnectionParameters>
#include <QLowEnergyAdvertisingParameters>
#include "networkservice.h"
#include "wirelessservice.h"
class NetworkManager;
class BluetoothServer : public QObject
{
Q_OBJECT
public:
explicit BluetoothServer(NetworkManager *networkManager);
~BluetoothServer();
// Information for the device info service
QString modelName() const;
void setModelName(const QString &modelName);
QString serverName() const;
void setServerName(const QString &serverName);
QString softwareVersion() const;
void setSoftwareVersion(const QString &softwareVersion);
QString hardwareVersion() const;
void setHardwareVersion(const QString &hardwareVersion);
bool running() const;
bool connected() const;
private:
QString m_modelName;
QString m_serverName;
QString m_softwareVersion;
QString m_hardwareVersion;
NetworkManager *m_networkManager = nullptr;
QBluetoothLocalDevice *m_localDevice = nullptr;
QLowEnergyController *m_controller = nullptr;
QLowEnergyService *m_deviceInfoService = nullptr;
QLowEnergyService *m_genericAccessService = nullptr;
QLowEnergyService *m_genericAttributeService = nullptr;
NetworkService *m_networkService = nullptr;
WirelessService *m_wirelessService = nullptr;
bool m_running = false;
bool m_connected = false;
QLowEnergyServiceData deviceInformationServiceData();
QLowEnergyServiceData genericAccessServiceData();
QLowEnergyServiceData genericAttributeServiceData();
void setRunning(bool running);
void setConnected(bool connected);
signals:
void runningChanged(const bool &running);
void connectedChanged(const bool &connected);
private slots:
// Local bluetooth device
void onHostModeStateChanged(QBluetoothLocalDevice::HostMode mode);
void onDeviceConnected(const QBluetoothAddress &address);
void onDeviceDisconnected(const QBluetoothAddress &address);
void onError(QLowEnergyController::Error error);
// Bluetooth controller
void onConnected();
void onDisconnected();
void onControllerStateChanged(QLowEnergyController::ControllerState state);
// Services
void characteristicChanged(const QLowEnergyCharacteristic &characteristic, const QByteArray &value);
void characteristicRead(const QLowEnergyCharacteristic &characteristic, const QByteArray &value);
void characteristicWritten(const QLowEnergyCharacteristic &characteristic, const QByteArray &value);
void descriptorRead(const QLowEnergyDescriptor &descriptor, const QByteArray &value);
void descriptorWritten(const QLowEnergyDescriptor &descriptor, const QByteArray &value);
void serviceError(QLowEnergyService::ServiceError error);
public slots:
void start();
void stop();
};
#endif // BLUETOOTHSERVER_H