some renaming

This commit is contained in:
Dorian Zedler 2020-10-17 21:51:06 +02:00
parent 76e457593e
commit 1ec609e7c2
Signed by: dorian
GPG key ID: D3B255CB8BC7CD37
2 changed files with 51 additions and 51 deletions

View file

@ -1,6 +1,6 @@
#include "qbluetoothleuart.h" #include "qbluetoothleuartclient.h"
QBluetoothLeUart::QBluetoothLeUart(QObject *parent) : QObject(parent) QBluetoothLeUartClient::QBluetoothLeUartClient(QObject *parent) : QObject(parent)
{ {
currentBluetoothDevice = nullptr; currentBluetoothDevice = nullptr;
bluetoothController = nullptr; bluetoothController = nullptr;
@ -13,16 +13,16 @@ QBluetoothLeUart::QBluetoothLeUart(QObject *parent) : QObject(parent)
// init device discovery agent for scanning // init device discovery agent for scanning
this->bluetoothDeviceDiscoveryAgent = new QBluetoothDeviceDiscoveryAgent(this); this->bluetoothDeviceDiscoveryAgent = new QBluetoothDeviceDiscoveryAgent(this);
connect(this->bluetoothDeviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &QBluetoothLeUart::handleDeviceDiscovered); connect(this->bluetoothDeviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::deviceDiscovered, this, &QBluetoothLeUartClient::handleDeviceDiscovered);
connect(bluetoothDeviceDiscoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)), connect(bluetoothDeviceDiscoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)),
this, SLOT(handleDeviceScanError(QBluetoothDeviceDiscoveryAgent::Error))); this, SLOT(handleDeviceScanError(QBluetoothDeviceDiscoveryAgent::Error)));
connect(this->bluetoothDeviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished, this, &QBluetoothLeUart::handleScanFinished); connect(this->bluetoothDeviceDiscoveryAgent, &QBluetoothDeviceDiscoveryAgent::finished, this, &QBluetoothLeUartClient::handleScanFinished);
// device model for QML // device model for QML
this->availableDevicesModel = new QBluetoothLeUartDeviceModel(this->availableDevices, this); this->availableDevicesModel = new QBluetoothLeUartDeviceModel(this->availableDevices, this);
} }
QBluetoothLeUart::~QBluetoothLeUart(){ QBluetoothLeUartClient::~QBluetoothLeUartClient(){
} }
@ -30,7 +30,7 @@ QBluetoothLeUart::~QBluetoothLeUart(){
// - Slots for QBluetoothLeUart - // - Slots for QBluetoothLeUart -
// ------------------------------ // ------------------------------
bool QBluetoothLeUart::startScanningForDevices(){ bool QBluetoothLeUartClient::startScanningForDevices(){
if(this->state != Idle && this->state != ScanFinished) if(this->state != Idle && this->state != ScanFinished)
return false; return false;
@ -47,7 +47,7 @@ bool QBluetoothLeUart::startScanningForDevices(){
return true; return true;
} }
bool QBluetoothLeUart::stopScanningForDevices() { bool QBluetoothLeUartClient::stopScanningForDevices() {
if(this->state != Scanning) if(this->state != Scanning)
return false; return false;
@ -56,11 +56,11 @@ bool QBluetoothLeUart::stopScanningForDevices() {
return true; return true;
} }
QList<QBluetoothLeUartDevice*> QBluetoothLeUart::getAvailableDevices() { QList<QBluetoothLeUartDevice*> QBluetoothLeUartClient::getAvailableDevices() {
return this->availableDevices; return this->availableDevices;
} }
QVariantList QBluetoothLeUart::getAvailableDevicesDetailList() { QVariantList QBluetoothLeUartClient::getAvailableDevicesDetailList() {
QVariantList result; QVariantList result;
@ -80,15 +80,15 @@ QVariantList QBluetoothLeUart::getAvailableDevicesDetailList() {
return result; return result;
} }
QBluetoothLeUartDeviceModel* QBluetoothLeUart::getAvailableDevicesModel() { QBluetoothLeUartDeviceModel* QBluetoothLeUartClient::getAvailableDevicesModel() {
return this->availableDevicesModel; return this->availableDevicesModel;
} }
QBluetoothLeUartDevice* QBluetoothLeUart::getCurrentDevice() { QBluetoothLeUartDevice* QBluetoothLeUartClient::getCurrentDevice() {
return this->currentBluetoothDevice; return this->currentBluetoothDevice;
} }
bool QBluetoothLeUart::connectToDevice(int deviceId) { bool QBluetoothLeUartClient::connectToDevice(int deviceId) {
if(deviceId < 0 || deviceId >= this->availableDevices.length()) if(deviceId < 0 || deviceId >= this->availableDevices.length())
return false; return false;
@ -96,7 +96,7 @@ bool QBluetoothLeUart::connectToDevice(int deviceId) {
return true; return true;
} }
bool QBluetoothLeUart::connectToDevice(QBluetoothLeUartDevice *device){ bool QBluetoothLeUartClient::connectToDevice(QBluetoothLeUartDevice *device){
if(!this->availableDevices.contains(device)) if(!this->availableDevices.contains(device))
return false; return false;
@ -116,12 +116,12 @@ bool QBluetoothLeUart::connectToDevice(QBluetoothLeUartDevice *device){
bluetoothController = new QLowEnergyController(currentBluetoothDevice->getDevice(), this); bluetoothController = new QLowEnergyController(currentBluetoothDevice->getDevice(), this);
bluetoothController->setRemoteAddressType(QLowEnergyController::RandomAddress); bluetoothController->setRemoteAddressType(QLowEnergyController::RandomAddress);
connect(this->bluetoothController, &QLowEnergyController::serviceDiscovered, this, &QBluetoothLeUart::handleServiceDiscovered); connect(this->bluetoothController, &QLowEnergyController::serviceDiscovered, this, &QBluetoothLeUartClient::handleServiceDiscovered);
connect(this->bluetoothController, &QLowEnergyController::discoveryFinished, this, &QBluetoothLeUart::handleServiceScanDone); connect(this->bluetoothController, &QLowEnergyController::discoveryFinished, this, &QBluetoothLeUartClient::handleServiceScanDone);
connect(bluetoothController, SIGNAL(error(QLowEnergyController::Error)), connect(bluetoothController, SIGNAL(error(QLowEnergyController::Error)),
this, SLOT(handleControllerError(QLowEnergyController::Error))); this, SLOT(handleControllerError(QLowEnergyController::Error)));
connect(this->bluetoothController, &QLowEnergyController::connected, this, &QBluetoothLeUart::handleDeviceConnected); connect(this->bluetoothController, &QLowEnergyController::connected, this, &QBluetoothLeUartClient::handleDeviceConnected);
connect(this->bluetoothController, &QLowEnergyController::disconnected, this, &QBluetoothLeUart::handleDeviceDisconnected); connect(this->bluetoothController, &QLowEnergyController::disconnected, this, &QBluetoothLeUartClient::handleDeviceDisconnected);
/* Start connecting to device */ /* Start connecting to device */
bluetoothController->connectToDevice(); bluetoothController->connectToDevice();
@ -130,7 +130,7 @@ bool QBluetoothLeUart::connectToDevice(QBluetoothLeUartDevice *device){
return true; return true;
} }
bool QBluetoothLeUart::disconnectFromDevice() { bool QBluetoothLeUartClient::disconnectFromDevice() {
if(this->state < Connecting) if(this->state < Connecting)
return false; return false;
@ -154,7 +154,7 @@ bool QBluetoothLeUart::disconnectFromDevice() {
return true; return true;
} }
bool QBluetoothLeUart::sendData(QString data, bool asynchronous){ bool QBluetoothLeUartClient::sendData(QString data, bool asynchronous){
Q_UNUSED(asynchronous) Q_UNUSED(asynchronous)
if(this->state != Connected) if(this->state != Connected)
return false; return false;
@ -173,7 +173,7 @@ bool QBluetoothLeUart::sendData(QString data, bool asynchronous){
// - Slots for QBluetothDeviceDiscoveryAgent - // - Slots for QBluetothDeviceDiscoveryAgent -
// ------------------------------------------- // -------------------------------------------
void QBluetoothLeUart::handleDeviceDiscovered(const QBluetoothDeviceInfo &device) void QBluetoothLeUartClient::handleDeviceDiscovered(const QBluetoothDeviceInfo &device)
{ {
// Is it a BLE device? // Is it a BLE device?
if (device.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration) { if (device.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration) {
@ -190,7 +190,7 @@ void QBluetoothLeUart::handleDeviceDiscovered(const QBluetoothDeviceInfo &device
} }
} }
void QBluetoothLeUart::handleScanFinished() void QBluetoothLeUartClient::handleScanFinished()
{ {
if (this->availableDevices.size() == 0) if (this->availableDevices.size() == 0)
{ {
@ -202,7 +202,7 @@ void QBluetoothLeUart::handleScanFinished()
setState(ScanFinished); setState(ScanFinished);
} }
void QBluetoothLeUart::handleDeviceScanError(QBluetoothDeviceDiscoveryAgent::Error error) void QBluetoothLeUartClient::handleDeviceScanError(QBluetoothDeviceDiscoveryAgent::Error error)
{ {
if (error == QBluetoothDeviceDiscoveryAgent::PoweredOffError) if (error == QBluetoothDeviceDiscoveryAgent::PoweredOffError)
emit this->scanningErrorOccured(AdapterTurnedOffError); emit this->scanningErrorOccured(AdapterTurnedOffError);
@ -216,7 +216,7 @@ void QBluetoothLeUart::handleDeviceScanError(QBluetoothDeviceDiscoveryAgent::Err
// - Slots for QLowEnergyController - // - Slots for QLowEnergyController -
// ---------------------------------- // ----------------------------------
void QBluetoothLeUart::handleServiceDiscovered(const QBluetoothUuid &uuid){ void QBluetoothLeUartClient::handleServiceDiscovered(const QBluetoothUuid &uuid){
qDebug() << "Found service with ID: " << uuid; qDebug() << "Found service with ID: " << uuid;
@ -226,7 +226,7 @@ void QBluetoothLeUart::handleServiceDiscovered(const QBluetoothUuid &uuid){
} }
} }
void QBluetoothLeUart::handleServiceScanDone(){ void QBluetoothLeUartClient::handleServiceScanDone(){
delete bluetoothService; delete bluetoothService;
bluetoothService=0; bluetoothService=0;
@ -243,29 +243,29 @@ void QBluetoothLeUart::handleServiceScanDone(){
} }
/* 3 Step: Service Discovery */ /* 3 Step: Service Discovery */
connect(this->bluetoothService, &QLowEnergyService::stateChanged, this, &QBluetoothLeUart::handleServiceStateChange); connect(this->bluetoothService, &QLowEnergyService::stateChanged, this, &QBluetoothLeUartClient::handleServiceStateChange);
connect(this->bluetoothService, &QLowEnergyService::characteristicChanged, this, &QBluetoothLeUart::handleServiceCharacteristicChange); connect(this->bluetoothService, &QLowEnergyService::characteristicChanged, this, &QBluetoothLeUartClient::handleServiceCharacteristicChange);
connect(this->bluetoothService, &QLowEnergyService::descriptorWritten, this, &QBluetoothLeUart::handleServiceDescriptorWritten); connect(this->bluetoothService, &QLowEnergyService::descriptorWritten, this, &QBluetoothLeUartClient::handleServiceDescriptorWritten);
bluetoothService->discoverDetails(); bluetoothService->discoverDetails();
setState(ServiceFound); setState(ServiceFound);
} }
void QBluetoothLeUart::handleControllerError(QLowEnergyController::Error error) void QBluetoothLeUartClient::handleControllerError(QLowEnergyController::Error error)
{ {
qDebug() << "Cannot connect to remote device."; qDebug() << "Cannot connect to remote device.";
qWarning() << "Controller Error:" << error; qWarning() << "Controller Error:" << error;
this->disconnectFromDevice(); this->disconnectFromDevice();
} }
void QBluetoothLeUart::handleDeviceConnected() void QBluetoothLeUartClient::handleDeviceConnected()
{ {
qDebug() << "Device connected"; qDebug() << "Device connected";
bluetoothController->discoverServices(); bluetoothController->discoverServices();
setState(ScanningForService); setState(ScanningForService);
} }
void QBluetoothLeUart::handleDeviceDisconnected() void QBluetoothLeUartClient::handleDeviceDisconnected()
{ {
this->setState(Idle); this->setState(Idle);
qDebug() << "UART service disconnected"; qDebug() << "UART service disconnected";
@ -276,7 +276,7 @@ void QBluetoothLeUart::handleDeviceDisconnected()
// - Slots for QLowEnergyService - // - Slots for QLowEnergyService -
// ------------------------------- // -------------------------------
void QBluetoothLeUart::handleServiceStateChange(QLowEnergyService::ServiceState s) void QBluetoothLeUartClient::handleServiceStateChange(QLowEnergyService::ServiceState s)
{ {
// A descriptoc can only be written if the service is in the ServiceDiscovered state // A descriptoc can only be written if the service is in the ServiceDiscovered state
@ -321,7 +321,7 @@ void QBluetoothLeUart::handleServiceStateChange(QLowEnergyService::ServiceState
} }
} }
void QBluetoothLeUart::handleServiceCharacteristicChange(const QLowEnergyCharacteristic &c,const QByteArray &value) void QBluetoothLeUartClient::handleServiceCharacteristicChange(const QLowEnergyCharacteristic &c,const QByteArray &value)
{ {
// ignore any other characteristic change // ignore any other characteristic change
if (c.uuid() != QBluetoothUuid(QUuid(this->rxUUID))) if (c.uuid() != QBluetoothUuid(QUuid(this->rxUUID)))
@ -330,7 +330,7 @@ void QBluetoothLeUart::handleServiceCharacteristicChange(const QLowEnergyCharact
emit dataReceived((QString) value); emit dataReceived((QString) value);
} }
void QBluetoothLeUart::handleServiceDescriptorWritten(const QLowEnergyDescriptor &d, void QBluetoothLeUartClient::handleServiceDescriptorWritten(const QLowEnergyDescriptor &d,
const QByteArray &value) const QByteArray &value)
{ {
if (d.isValid() && d == bluetoothTransmissionDescriptor && value == QByteArray("0000")) { if (d.isValid() && d == bluetoothTransmissionDescriptor && value == QByteArray("0000")) {
@ -343,17 +343,17 @@ void QBluetoothLeUart::handleServiceDescriptorWritten(const QLowEnergyDescriptor
// - Helper functions - // - Helper functions -
// -------------------- // --------------------
void QBluetoothLeUart::init() { void QBluetoothLeUartClient::init() {
#ifdef QBluetoothLeUart_QML #ifdef QBluetoothLeUart_QML
qmlRegisterUncreatableType<QBluetoothLeUartDevice>("de.itsblue.bluetoothleuart", 1, 0, "QBluetoothLeUartDevice", "QBluetoothLeUartDevice cannot be created"); qmlRegisterUncreatableType<QBluetoothLeUartDevice>("de.itsblue.bluetoothleuart", 1, 0, "QBluetoothLeUartDevice", "QBluetoothLeUartDevice cannot be created");
qmlRegisterUncreatableType<QBluetoothLeUartDeviceModel>("de.itsblue.bluetoothleuart", 1, 0, "QBluetoothLeUartDeviceModel", "QBluetoothLeUartDeviceModel cannot be created"); qmlRegisterUncreatableType<QBluetoothLeUartDeviceModel>("de.itsblue.bluetoothleuart", 1, 0, "QBluetoothLeUartDeviceModel", "QBluetoothLeUartDeviceModel cannot be created");
qmlRegisterType<QBluetoothLeUart>("de.itsblue.bluetoothleuart", 1, 0, "QBluetoothLeUart"); qmlRegisterType<QBluetoothLeUartClient>("de.itsblue.bluetoothleuart", 1, 0, "QBluetoothLeUart");
qRegisterMetaType<QBluetoothLeUart::BluetoothLeUartState>("QBluetoothLeUart::BluetoothLeUartState"); qRegisterMetaType<QBluetoothLeUartClient::BluetoothLeUartClientState>("QBluetoothLeUart::BluetoothLeUartState");
qRegisterMetaType<QBluetoothLeUart::BluetoothScanError>("QBluetoothLeUart::BluetoothScanError"); qRegisterMetaType<QBluetoothLeUartClient::BluetoothScanError>("QBluetoothLeUart::BluetoothScanError");
#endif #endif
} }
void QBluetoothLeUart::setState(QBluetoothLeUart::BluetoothLeUartState newState) void QBluetoothLeUartClient::setState(QBluetoothLeUartClient::BluetoothLeUartClientState newState)
{ {
if (state == newState) if (state == newState)
return; return;
@ -362,11 +362,11 @@ void QBluetoothLeUart::setState(QBluetoothLeUart::BluetoothLeUartState newState)
emit stateChanged(newState); emit stateChanged(newState);
} }
QBluetoothLeUart::BluetoothLeUartState QBluetoothLeUart::getState() const { QBluetoothLeUartClient::BluetoothLeUartClientState QBluetoothLeUartClient::getState() const {
return state; return state;
} }
void QBluetoothLeUart::setUUIDs(const char uartServiceUUID[36], const char txUUID[36], const char rxUUID[36]) { void QBluetoothLeUartClient::setUUIDs(const char uartServiceUUID[36], const char txUUID[36], const char rxUUID[36]) {
this->uartServiceUUID = uartServiceUUID; this->uartServiceUUID = uartServiceUUID;
this->txUUID = txUUID; this->txUUID = txUUID;
this->rxUUID = rxUUID; this->rxUUID = rxUUID;

View file

@ -113,19 +113,19 @@
* } * }
* \endcode * \endcode
*/ */
class QBluetoothLeUart : public QObject class QBluetoothLeUartClient : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QVariantList availableDevices READ getAvailableDevicesDetailList NOTIFY avaliableDevicesChanged) Q_PROPERTY(QVariantList availableDevices READ getAvailableDevicesDetailList NOTIFY avaliableDevicesChanged)
Q_PROPERTY(QBluetoothLeUartDeviceModel* availableDevicesModel READ getAvailableDevicesModel NOTIFY avaliableDevicesModelChanged) Q_PROPERTY(QBluetoothLeUartDeviceModel* availableDevicesModel READ getAvailableDevicesModel NOTIFY avaliableDevicesModelChanged)
Q_PROPERTY(QBluetoothLeUartDevice* currentDevice READ getCurrentDevice NOTIFY currentDeviceChanged) Q_PROPERTY(QBluetoothLeUartDevice* currentDevice READ getCurrentDevice NOTIFY currentDeviceChanged)
Q_PROPERTY(BluetoothLeUartState state READ getState NOTIFY stateChanged) Q_PROPERTY(BluetoothLeUartClientState state READ getState NOTIFY stateChanged)
public: public:
/*! /*!
* \brief The BluetoothLeUartState enum contains all state of the QBluetoothLeUart class. * \brief The BluetoothLeUartState enum contains all state of the QBluetoothLeUart class.
*/ */
enum BluetoothLeUartState { enum BluetoothLeUartClientState {
Idle = 0, /*!< Waiting for instrucions */ Idle = 0, /*!< Waiting for instrucions */
Scanning, /*!< Scanning for devices */ Scanning, /*!< Scanning for devices */
ScanFinished, /*!< Scanning has finished, we are ready to connect */ ScanFinished, /*!< Scanning has finished, we are ready to connect */
@ -134,7 +134,7 @@ public:
ServiceFound, /*!< Services were found */ ServiceFound, /*!< Services were found */
Connected /*!< Connected. We are now ready to send and receive */ Connected /*!< Connected. We are now ready to send and receive */
}; };
Q_ENUM(BluetoothLeUartState) Q_ENUM(BluetoothLeUartClientState)
enum BluetoothScanError { enum BluetoothScanError {
UnknownError, UnknownError,
@ -143,8 +143,8 @@ public:
}; };
Q_ENUM(BluetoothScanError); Q_ENUM(BluetoothScanError);
QBluetoothLeUart(QObject *parent = nullptr); QBluetoothLeUartClient(QObject *parent = nullptr);
~QBluetoothLeUart(); ~QBluetoothLeUartClient();
/*! /*!
* \brief Function to register QMl types * \brief Function to register QMl types
@ -167,7 +167,7 @@ private:
QString rxUUID; QString rxUUID;
// current state // current state
QBluetoothLeUart::BluetoothLeUartState state; QBluetoothLeUartClient::BluetoothLeUartClientState state;
// QBluetooth controllers // QBluetooth controllers
QBluetoothDeviceDiscoveryAgent *bluetoothDeviceDiscoveryAgent; QBluetoothDeviceDiscoveryAgent *bluetoothDeviceDiscoveryAgent;
@ -307,10 +307,10 @@ public slots:
* \see BluetoothLeUartState * \see BluetoothLeUartState
* \return The current state * \return The current state
*/ */
Q_INVOKABLE QBluetoothLeUart::BluetoothLeUartState getState() const; Q_INVOKABLE QBluetoothLeUartClient::BluetoothLeUartClientState getState() const;
private slots: private slots:
void setState(QBluetoothLeUart::BluetoothLeUartState newState); void setState(QBluetoothLeUartClient::BluetoothLeUartClientState newState);
// Slots for QBluetothDeviceDiscoveryAgent // Slots for QBluetothDeviceDiscoveryAgent
void handleDeviceDiscovered(const QBluetoothDeviceInfo&); void handleDeviceDiscovered(const QBluetoothDeviceInfo&);
@ -330,14 +330,14 @@ private slots:
void handleServiceDescriptorWritten(const QLowEnergyDescriptor &d, const QByteArray &value); void handleServiceDescriptorWritten(const QLowEnergyDescriptor &d, const QByteArray &value);
signals: signals:
void stateChanged(QBluetoothLeUart::BluetoothLeUartState newState); void stateChanged(QBluetoothLeUartClient::BluetoothLeUartClientState newState);
void foundNewDevice(QBluetoothLeUartDevice* device); void foundNewDevice(QBluetoothLeUartDevice* device);
void avaliableDevicesChanged(QList<QBluetoothLeUartDevice*> avaliableDevices); void avaliableDevicesChanged(QList<QBluetoothLeUartDevice*> avaliableDevices);
void avaliableDevicesModelChanged(); void avaliableDevicesModelChanged();
void currentDeviceChanged(); void currentDeviceChanged();
void scanFinished(QList<QBluetoothLeUartDevice*> availableDevices); void scanFinished(QList<QBluetoothLeUartDevice*> availableDevices);
void scanningErrorOccured(QBluetoothLeUart::BluetoothScanError error); void scanningErrorOccured(QBluetoothLeUartClient::BluetoothScanError error);
void connectedToDevice(); void connectedToDevice();