blob: 9032c7f2efefafeb532a7a60135523636aebc9fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// Copyright (C) 2013 BlackBerry Limited. All rights reserved.
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include "serviceinfo.h"
#include <QtBluetooth/qbluetoothuuid.h>
#include <QtBluetooth/qlowenergyservice.h>
using namespace Qt::StringLiterals;
ServiceInfo::ServiceInfo(QLowEnergyService *service):
m_service(service)
{
m_service->setParent(this);
}
QLowEnergyService *ServiceInfo::service() const
{
return m_service;
}
QString ServiceInfo::getName() const
{
if (!m_service)
return QString();
return m_service->serviceName();
}
QString ServiceInfo::getType() const
{
if (!m_service)
return QString();
QString result;
if (m_service->type() & QLowEnergyService::PrimaryService)
result += u"primary"_s;
else
result += u"secondary"_s;
if (m_service->type() & QLowEnergyService::IncludedService)
result += u" included"_s;
result.prepend('<'_L1).append('>'_L1);
return result;
}
QString ServiceInfo::getUuid() const
{
if (!m_service)
return QString();
const QBluetoothUuid uuid = m_service->serviceUuid();
bool success = false;
quint16 result16 = uuid.toUInt16(&success);
if (success)
return u"0x"_s + QString::number(result16, 16);
quint32 result32 = uuid.toUInt32(&success);
if (success)
return u"0x"_s + QString::number(result32, 16);
return uuid.toString().remove('{'_L1).remove('}'_L1);
}
|