summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2017-02-14 11:06:55 +0100
committerKari Hautamäki <kari.hautamaki@qt.io>2017-02-14 14:04:47 +0000
commitcc73478e1ff48a6e469d3856c552e7a5e3d5023d (patch)
tree29a4d2ebd8dc262d789d71754ccbbd306975dd88
parent25aa7288205ba8371466768392a3be02a5c8f5d7 (diff)
iot-sensortag: Rework service discovery
Instead of iterating over the list of the controller's services after discovery is finished, handle the found services one by one when the according serviceDiscovered signal is emitted. Change-Id: I84d879059222189fb106e085bd9f2e4d3cb44bb5 Reviewed-by: Kari Hautamäki <kari.hautamaki@qt.io>
-rw-r--r--tradeshow/iot-sensortag/bluetoothapiconstants.h7
-rw-r--r--tradeshow/iot-sensortag/bluetoothdevice.cpp119
2 files changed, 60 insertions, 66 deletions
diff --git a/tradeshow/iot-sensortag/bluetoothapiconstants.h b/tradeshow/iot-sensortag/bluetoothapiconstants.h
index b29d73b..57d0849 100644
--- a/tradeshow/iot-sensortag/bluetoothapiconstants.h
+++ b/tradeshow/iot-sensortag/bluetoothapiconstants.h
@@ -52,6 +52,13 @@
// NOTE! This file should only contain defines, no implementation
+// These service UUIDs come from the Texas Intruments SensorTag Bluetooth LE API specification
+#define IRTEMPERATURESENSOR_SERVICE_UUID "f00aa00-0451-4000-b000-000000000000"
+#define BAROMETER_SERVICE_UUID "f000aa40-0451-4000-b000-000000000000"
+#define HUMIDITYSENSOR_SERVICE_UUID "f000aa20-0451-4000-b000-000000000000"
+#define LIGHTSENSOR_SERVICE_UUID "f000aa70-0451-4000-b000-000000000000"
+#define MOTIONSENSOR_SERVICE_UUID "f000aa80-0451-4000-b000-000000000000"
+
/* Timeouts (values between 100ms and 2500ms allowed by API specification.
* API values are passed in hex as strings and multiplied by 10 in SensorTag.
* These values can be modifed as needed by performance.
diff --git a/tradeshow/iot-sensortag/bluetoothdevice.cpp b/tradeshow/iot-sensortag/bluetoothdevice.cpp
index 800a8ab..ba9aa55 100644
--- a/tradeshow/iot-sensortag/bluetoothdevice.cpp
+++ b/tradeshow/iot-sensortag/bluetoothdevice.cpp
@@ -162,93 +162,80 @@ void BluetoothDevice::scanServices()
void BluetoothDevice::addLowEnergyService(const QBluetoothUuid &serviceUuid)
{
-}
-
-void BluetoothDevice::serviceScanDone()
-{
- statusUpdated("(Service scan done!)");
- qCDebug(boot2QtDemos) << "ServiceScan done.";
- if (!irTemperatureService)
- {
- QBluetoothUuid uuid;
- for (int i = 0; i < controller->services().count(); i++) {
- QBluetoothUuid id = controller->services().at(i);
- if (id.toString().contains("f000aa00-0451-4000-b000-000000000000")) {
- uuid = id;
- break;
- }
+ if (serviceUuid == QBluetoothUuid(QLatin1String(IRTEMPERATURESENSOR_SERVICE_UUID))) {
+ qCDebug(boot2QtDemos) << "Found infrared temperature service.";
+ irTemperatureService = controller->createServiceObject(serviceUuid);
+ if (!irTemperatureService) {
+ qWarning() << "Could not create infrared temperature service object.";
+ return;
}
-
- irTemperatureService = controller->createServiceObject(uuid);
connect(irTemperatureService, &QLowEnergyService::stateChanged, this, &BluetoothDevice::temperatureDetailsDiscovered);
connect(irTemperatureService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::characteristicsRead);
irTemperatureService->discoverDetails();
- }
- if (!baroService)
- {
- QBluetoothUuid uuid;
- for (int i = 0; i < controller->services().count(); i++) {
- QBluetoothUuid id = controller->services().at(i);
- if (id.toString().contains("f000aa40-0451-4000-b000-000000000000")) {
- uuid = id;
- break;
- }
+ } else if (serviceUuid == QBluetoothUuid(QLatin1String(BAROMETER_SERVICE_UUID))) {
+ qCDebug(boot2QtDemos) << "Found barometer service.";
+ baroService = controller->createServiceObject(serviceUuid);
+ if (!baroService) {
+ qWarning() << "Could not create barometer service object.";
+ return;
}
-
- baroService = controller->createServiceObject(uuid);
connect(baroService, &QLowEnergyService::stateChanged, this, &BluetoothDevice::barometerDetailsDiscovered);
connect(baroService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::characteristicsRead);
baroService->discoverDetails();
- }
- if (!humidityService)
- {
- QBluetoothUuid uuid;
- for (int i = 0; i < controller->services().count(); i++) {
- QBluetoothUuid id = controller->services().at(i);
- if (id.toString().contains("f000aa20-0451-4000-b000-000000000000")) {
- uuid = id;
- break;
- }
-
+ } else if (serviceUuid == QBluetoothUuid(QLatin1String(HUMIDITYSENSOR_SERVICE_UUID))) {
+ qCDebug(boot2QtDemos) << "Found humidity service.";
+ humidityService = controller->createServiceObject(serviceUuid);
+ if (!humidityService) {
+ qWarning() << "Could not create humidity service object.";
+ return;
}
-
- humidityService = controller->createServiceObject(uuid);
connect(humidityService, &QLowEnergyService::stateChanged, this, &BluetoothDevice::humidityDetailsDiscovered);
connect(humidityService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::characteristicsRead);
humidityService->discoverDetails();
- }
- if (!lightService)
- {
- QBluetoothUuid uuid;
- for (int i = 0; i < controller->services().count(); i++) {
- QBluetoothUuid id = controller->services().at(i);
- if (id.toString().contains("f000aa70-0451-4000-b000-000000000000")) {
- uuid = id;
- break;
- }
-
+ } else if (serviceUuid == QBluetoothUuid(QLatin1String(LIGHTSENSOR_SERVICE_UUID))) {
+ qCDebug(boot2QtDemos) << "Found light service.";
+ lightService = controller->createServiceObject(serviceUuid);
+ if (!lightService) {
+ qWarning() << "Could not create light service object.";
+ return;
}
-
- lightService = controller->createServiceObject(uuid);
connect(lightService, &QLowEnergyService::stateChanged, this, &BluetoothDevice::lightIntensityDetailsDiscovered);
connect(lightService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::characteristicsRead);
lightService->discoverDetails();
- }
- if (!motionService)
- {
- QBluetoothUuid uuid;
- for (int i = 0; i < controller->services().count(); i++) {
- QBluetoothUuid id = controller->services().at(i);
- if (id.toString().contains("f000aa80-0451-4000-b000-000000000000")) {
- uuid = id;
- break;
- }
+ } else if (serviceUuid == QBluetoothUuid(QLatin1String(MOTIONSENSOR_SERVICE_UUID))) {
+ qCDebug(boot2QtDemos) << "Found motion service.";
+ motionService = controller->createServiceObject(serviceUuid);
+ if (!motionService) {
+ qWarning() << "Could not create motion service object.";
+ return;
}
- motionService = controller->createServiceObject(uuid);
connect(motionService, &QLowEnergyService::stateChanged, this, &BluetoothDevice::motionDetailsDiscovered);
connect(motionService, &QLowEnergyService::characteristicChanged, this, &BluetoothDevice::characteristicsRead);
motionService->discoverDetails();
+ } else {
+ qCDebug(boot2QtDemos) << "Found unhandled service with id" << serviceUuid << ".";
}
+}
+
+void BluetoothDevice::serviceScanDone()
+{
+ statusUpdated("(Service scan done!)");
+ qCDebug(boot2QtDemos) << "ServiceScan done.";
+ if (!irTemperatureService)
+ qCDebug(boot2QtDemos) << "Infrared temperature service not found.";
+
+ if (!baroService)
+ qCDebug(boot2QtDemos) << "Barometer service not found.";
+
+ if (!humidityService)
+ qCDebug(boot2QtDemos) << "Humidity service not found.";
+
+ if (!lightService)
+ qCDebug(boot2QtDemos) << "Light service not found.";
+
+ if (!motionService)
+ qCDebug(boot2QtDemos) << "Motion service not found.";
+
attitudeChangeInterval.restart();
}