-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserviceinfo.cpp
74 lines (57 loc) · 1.66 KB
/
serviceinfo.cpp
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
67
68
69
70
71
72
73
74
// 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 <QBluetoothUuid>
#include <QLowEnergyService>
using namespace Qt::StringLiterals;
ServiceInfo::ServiceInfo(QLowEnergyService *service):
m_service(service)
{
m_service->setParent(this);
if (m_service) {
m_is_rx_tx = (m_service->serviceUuid().toString()
== "{6e400001-b5a3-f393-e0a9-e50e24dcca9e}");
}
}
QLowEnergyService *ServiceInfo::service() const
{
return m_service;
}
QString ServiceInfo::getName() const
{
if (m_is_rx_tx) {
return {"RX_TX"};
}
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);
}