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

View file

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