summaryrefslogtreecommitdiffstats
path: root/examples/bluetooth/lowenergyscanner/characteristicinfo.cpp
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-07-03 16:18:03 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-07-15 20:39:40 +0200
commitc39189a922ce7057b410eba12e80abac589712cf (patch)
tree338815352496d1b1e2d0234f8fd81488e6dc84c5 /examples/bluetooth/lowenergyscanner/characteristicinfo.cpp
parent4a52ec355e2b2541d1867f785ef58c8c483b7316 (diff)
Port lowenergyscanner example to new API
Some minor improvements have been incorporated too but the focus is on the port. More code and UI cleanups are required. Change-Id: I56f226b8418b78190d498df04d67686220a3644e Reviewed-by: Fabian Bumberger <fbumberger@rim.com>
Diffstat (limited to 'examples/bluetooth/lowenergyscanner/characteristicinfo.cpp')
-rw-r--r--examples/bluetooth/lowenergyscanner/characteristicinfo.cpp68
1 files changed, 49 insertions, 19 deletions
diff --git a/examples/bluetooth/lowenergyscanner/characteristicinfo.cpp b/examples/bluetooth/lowenergyscanner/characteristicinfo.cpp
index 2a69529a..b0a60b34 100644
--- a/examples/bluetooth/lowenergyscanner/characteristicinfo.cpp
+++ b/examples/bluetooth/lowenergyscanner/characteristicinfo.cpp
@@ -1,6 +1,7 @@
/***************************************************************************
**
** Copyright (C) 2013 BlackBerry Limited. All rights reserved.
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtBluetooth module of the Qt Toolkit.
@@ -42,31 +43,54 @@
#include "qbluetoothuuid.h"
#include <QByteArray>
-CharacteristicInfo::CharacteristicInfo():
- m_characteristic(QLowEnergyCharacteristicInfo())
+CharacteristicInfo::CharacteristicInfo()
{
}
-CharacteristicInfo::CharacteristicInfo(const QLowEnergyCharacteristicInfo &characteristic):
+CharacteristicInfo::CharacteristicInfo(const QLowEnergyCharacteristic &characteristic):
m_characteristic(characteristic)
{
- emit characteristicChanged();
}
-void CharacteristicInfo::setCharacteristic(const QLowEnergyCharacteristicInfo &characteristic)
+void CharacteristicInfo::setCharacteristic(const QLowEnergyCharacteristic &characteristic)
{
- m_characteristic = QLowEnergyCharacteristicInfo(characteristic);
+ m_characteristic = characteristic;
emit characteristicChanged();
}
QString CharacteristicInfo::getName() const
{
- return m_characteristic.name();
+ QString name = m_characteristic.name();
+ if (!name.isEmpty())
+ return name;
+
+ // find descriptor with CharacteristicUserDescription
+ foreach (const QLowEnergyDescriptor &descriptor, m_characteristic.descriptors()) {
+ if (descriptor.type() == QBluetoothUuid::CharacteristicUserDescription) {
+ name = QByteArray::fromHex(descriptor.value());
+ break;
+ }
+ }
+
+ if (name.isEmpty())
+ name = "Unknown";
+
+ return name;
}
QString CharacteristicInfo::getUuid() const
{
- return m_characteristic.uuid().toString().remove(QLatin1Char('{')).remove(QLatin1Char('}'));
+ const QBluetoothUuid uuid = m_characteristic.uuid();
+ bool success = false;
+ quint16 result16 = uuid.toUInt16(&success);
+ if (success)
+ return QStringLiteral("0x") + QString::number(result16, 16);
+
+ quint32 result32 = uuid.toUInt32(&success);
+ if (success)
+ return QStringLiteral("0x") + QString::number(result32, 16);
+
+ return uuid.toString().remove(QLatin1Char('{')).remove(QLatin1Char('}'));
}
QString CharacteristicInfo::getValue() const
@@ -89,20 +113,26 @@ QString CharacteristicInfo::getPermission() const
{
QString properties = "Properties:";
int permission = m_characteristic.properties();
- if (permission & QLowEnergyCharacteristicInfo::Read)
- properties = properties + QStringLiteral(" Read");
- if (permission & QLowEnergyCharacteristicInfo::Write)
- properties = properties + QStringLiteral(" Write");
- if (permission & QLowEnergyCharacteristicInfo::Notify)
- properties = properties + QStringLiteral(" Notify");
- if (permission & QLowEnergyCharacteristicInfo::Indicate)
- properties = properties + QStringLiteral(" Indicate");
- if (permission & QLowEnergyCharacteristicInfo::ExtendedProperty)
- properties = properties + QStringLiteral(" ExtendedProperty");
+ if (permission & QLowEnergyCharacteristic::Read)
+ properties += QStringLiteral(" Read");
+ if (permission & QLowEnergyCharacteristic::Write)
+ properties += QStringLiteral(" Write");
+ if (permission & QLowEnergyCharacteristic::Notify)
+ properties += QStringLiteral(" Notify");
+ if (permission & QLowEnergyCharacteristic::Indicate)
+ properties += QStringLiteral(" Indicate");
+ if (permission & QLowEnergyCharacteristic::ExtendedProperty)
+ properties += QStringLiteral(" ExtendedProperty");
+ if (permission & QLowEnergyCharacteristic::Broadcasting)
+ properties += QStringLiteral(" Broadcast");
+ if (permission & QLowEnergyCharacteristic::WriteNoResponse)
+ properties += QStringLiteral(" WriteNoResp");
+ if (permission & QLowEnergyCharacteristic::WriteSigned)
+ properties += QStringLiteral(" WriteSigned");
return properties;
}
-QLowEnergyCharacteristicInfo CharacteristicInfo::getCharacteristic() const
+QLowEnergyCharacteristic CharacteristicInfo::getCharacteristic() const
{
return m_characteristic;
}