11#include <QtBluetooth/QBluetoothLocalDevice>
12#include <QtCore/QLoggingCategory>
15#if QT_CONFIG(bluez) && !defined(QT_BLUEZ_NO_BTLE)
19#elif defined(QT_ANDROID_BLUETOOTH)
22#elif defined(QT_WINRT_BLUETOOTH)
25#elif defined(Q_OS_DARWIN)
37 QLowEnergyController__ControllerState)
39 QLowEnergyController__RemoteAddressType)
43#if defined(QT_ANDROID_BLUETOOTH)
296 static bool initDone =
false;
298 qRegisterMetaType<QLowEnergyController::ControllerState>();
299 qRegisterMetaType<QLowEnergyController::Error>();
300 qRegisterMetaType<QLowEnergyConnectionParameters>();
301 qRegisterMetaType<QLowEnergyCharacteristic>();
302 qRegisterMetaType<QLowEnergyDescriptor>();
311#if QT_CONFIG(bluez) && !defined(QT_BLUEZ_NO_BTLE)
325 QString adapterPathWithPeripheralSupport;
334 qCDebug(QT_BT) <<
"Using BlueZ LE DBus API for central";
336 }
else if (!adapterPathWithPeripheralSupport.
isEmpty()) {
337 qCDebug(QT_BT) <<
"Using BlueZ LE DBus API for peripheral";
340 qCDebug(QT_BT) <<
"Using BlueZ kernel ATT interface for"
344#elif defined(QT_ANDROID_BLUETOOTH)
348#elif defined(QT_WINRT_BLUETOOTH)
352#elif defined(Q_OS_DARWIN)
378QLowEnergyController::QLowEnergyController(
388 d->role = CentralRole;
390 d->remoteDevice = remoteDevice.
address();
392 if (localDevice.isNull())
395 d->localAdapter = localDevice;
398 d->remoteName = remoteDevice.
name();
490 if (localDevice.isNull())
493 d->localAdapter = localDevice;
626 qCWarning(QT_BT) <<
"Connection can only be established while in central role";
630 if (!
d->isValidLocalAdapter()) {
631 qCWarning(QT_BT) <<
"connectToDevice() LE controller has invalid adapter";
639 d->connectToDevice();
666 d->invalidateServices();
667 d->disconnectFromDevice();
691 qCWarning(QT_BT) <<
"Cannot discover services in peripheral role";
698 d->discoverServices();
745 ServiceDataMap::const_iterator
it =
d->serviceList.constFind(serviceUuid);
746 if (
it !=
d->serviceList.constEnd()) {
782 qCWarning(QT_BT) <<
"Cannot start advertising in central role" <<
state();
786 qCWarning(QT_BT) <<
"Cannot start advertising in state" <<
state();
789 d->startAdvertising(parameters, advertisingData, scanResponseData);
805 qCDebug(QT_BT) <<
"stopAdvertising called in state" <<
state();
808 d->stopAdvertising();
830 qCWarning(QT_BT) <<
"Services can only be added in the peripheral role";
834 qCWarning(QT_BT) <<
"Services can only be added in unconnected state";
837 if (!service.isValid()) {
838 qCWarning(QT_BT) <<
"Not adding invalid service";
842#if defined(QT_ANDROID_BLUETOOTH)
844 qCWarning(QT_BT_ANDROID) <<
"addService() failed due to missing permissions";
888 qCWarning(QT_BT) <<
"Connection update request only possible in connected state";
966 qCWarning(QT_BT,
"Invalid role (peripheral), cannot read RSSI");
974 qCWarning(QT_BT,
"Cannot read RSSI while not in 'Connected' state, connect first");
983#include "moc_qlowenergycontroller.cpp"
QT_BEGIN_NAMESPACE bool ensureAndroidPermission(QBluetoothPermission::CommunicationModes modes)
QString adapterWithDBusPeripheralInterface(const QBluetoothAddress &localAddress)
QVersionNumber bluetoothdVersion()
QBluetoothAddress address() const
Returns the address of the device.
QBluetoothUuid deviceUuid() const
Returns a unique identifier for a Bluetooth device without an address.
QString name() const
Returns the name assigned to the device.
QBluetoothAddress address() const
Returns the MAC address of this Bluetooth device.
The QLowEnergyAdvertisingData class represents the data to be broadcast during Bluetooth Low Energy a...
The QLowEnergyAdvertisingParameters class represents the parameters used for Bluetooth Low Energy adv...
The QLowEnergyConnectionParameters class is used when requesting or reporting an update of the parame...
QLowEnergyController::RemoteAddressType addressType
virtual int mtu() const =0
ServiceDataMap serviceList
QLowEnergyController::Error error
void setError(QLowEnergyController::Error newError)
QLowEnergyController::Role role
QBluetoothAddress localAdapter
QBluetoothUuid deviceUuid
virtual void requestConnectionUpdate(const QLowEnergyConnectionParameters ¶ms)=0
QLowEnergyController::ControllerState state
QBluetoothAddress remoteDevice
RemoteAddressType
Indicates what type of Bluetooth address the remote device uses.
void connectToDevice()
Connects to the remote Bluetooth Low Energy device.
ControllerState
Indicates the state of the controller object.
static QLowEnergyController * createCentral(const QBluetoothDeviceInfo &remoteDevice, QObject *parent=nullptr)
Returns a new object of this class that is in the \l CentralRole and has the parent object parent.
Role
Indicates the role of the controller object.
Role role() const
Returns the role that this controller object is in.
void disconnectFromDevice()
Disconnects from the remote device.
~QLowEnergyController()
Destroys the QLowEnergyController instance.
QBluetoothAddress localAddress() const
Returns the address of the local Bluetooth adapter being used for the communication.
QString errorString() const
Returns a textual representation of the last occurred error.
void requestConnectionUpdate(const QLowEnergyConnectionParameters ¶meters)
Requests the controller to update the connection according to parameters.
void stopAdvertising()
Stops advertising, if this object is currently in the advertising state.
QString remoteName() const
Returns the name of the remote Bluetooth Low Energy device, if the controller is in the \l CentralRol...
QLowEnergyService * addService(const QLowEnergyServiceData &service, QObject *parent=nullptr)
Constructs and returns a \l QLowEnergyService object with parent from service.
RemoteAddressType remoteAddressType() const
Returns the type of \l remoteAddress().
Error error() const
Returns the last occurred error or \l NoError.
static QLowEnergyController * createPeripheral(const QBluetoothAddress &localDevice, QObject *parent=nullptr)
Returns a new object of this class that is in the \l PeripheralRole and has the parent object parent ...
Error
Indicates all possible error conditions found during the controller's existence.
@ InvalidBluetoothAdapterError
QList< QBluetoothUuid > services() const
Returns the list of services offered by the remote device, if the controller is in the \l CentralRole...
void discoverServices()
Initiates the service discovery process.
QLowEnergyService * createServiceObject(const QBluetoothUuid &service, QObject *parent=nullptr)
Creates an instance of the service represented by serviceUuid.
QBluetoothAddress remoteAddress() const
Returns the address of the remote Bluetooth Low Energy device.
ControllerState state() const
Returns the current state of the controller.
void readRssi()
readRssi() reads RSSI (received signal strength indicator) for a connected remote device.
void startAdvertising(const QLowEnergyAdvertisingParameters ¶meters, const QLowEnergyAdvertisingData &advertisingData, const QLowEnergyAdvertisingData &scanResponseData=QLowEnergyAdvertisingData())
Starts advertising the data given in advertisingData and scanResponseData, using the parameters set i...
QBluetoothUuid remoteDeviceUuid() const
Returns the unique identifier of the remote Bluetooth Low Energy device.
int mtu() const
Returns the MTU size.
void setRemoteAddressType(RemoteAddressType type)
Sets the remote address type.
The QLowEnergyServiceData class is used to set up GATT service data. \inmodule QtBluetooth.
QObject * parent() const
Returns a pointer to the parent object.
void setParent(QObject *parent)
Makes the object a child of parent.
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QSet< QString >::iterator it
Combined button and popup list for selecting options.
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
static QLowEnergyControllerPrivate * privateController(QLowEnergyController::Role role, const QBluetoothAddress &localDevice=QBluetoothAddress{})
void registerQLowEnergyControllerMetaType()
Q_CORE_EXPORT bool qEnvironmentVariableIsSet(const char *varName) noexcept
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent