10QT_IMPL_METATYPE_EXTERN(QLowEnergyCharacteristic)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
66struct QLowEnergyCharacteristicPrivate
68 QLowEnergyHandle handle;
72
73
74
75
76
77QLowEnergyCharacteristic::QLowEnergyCharacteristic():
84
85
86
87
88
89QLowEnergyCharacteristic::QLowEnergyCharacteristic(
const QLowEnergyCharacteristic &other):
93 data =
new QLowEnergyCharacteristicPrivate();
94 data->handle = other.data->handle;
99
100
101QLowEnergyCharacteristic::QLowEnergyCharacteristic(
102 QSharedPointer<QLowEnergyServicePrivate> p, QLowEnergyHandle handle):
105 data =
new QLowEnergyCharacteristicPrivate();
106 data->handle = handle;
110
111
112QLowEnergyCharacteristic::~QLowEnergyCharacteristic()
118
119
120
121
122
123
124
125
126
127
128QString QLowEnergyCharacteristic::name()
const
130 return QBluetoothUuid::characteristicToString(
131 static_cast<QBluetoothUuid::CharacteristicType>(uuid().toUInt16()));
135
136
137
138QBluetoothUuid QLowEnergyCharacteristic::uuid()
const
140 if (d_ptr.isNull() || !data
141 || !d_ptr->characteristicList.contains(data->handle))
142 return QBluetoothUuid();
144 return d_ptr->characteristicList[data->handle].uuid;
148
149
150
151
152QLowEnergyCharacteristic::PropertyTypes QLowEnergyCharacteristic::properties()
const
154 if (d_ptr.isNull() || !data
155 || !d_ptr->characteristicList.contains(data->handle))
156 return QLowEnergyCharacteristic::Unknown;
158 return d_ptr->characteristicList[data->handle].properties;
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178QByteArray QLowEnergyCharacteristic::value()
const
180 if (d_ptr.isNull() || !data
181 || !d_ptr->characteristicList.contains(data->handle))
184 return d_ptr->characteristicList[data->handle].value;
188
189
190
191
192
193
194
195
196
197QLowEnergyHandle QLowEnergyCharacteristic::handle()
const
199 if (d_ptr.isNull() || !data
200 || !d_ptr->characteristicList.contains(data->handle))
203 return d_ptr->characteristicList[data->handle].valueHandle;
207
208
209
210QLowEnergyCharacteristic &QLowEnergyCharacteristic::operator=(
const QLowEnergyCharacteristic &other)
221 data =
new QLowEnergyCharacteristicPrivate();
223 data->handle = other.data->handle;
229
230
231
232
233
234
235
236
239
240
241
242
243
244
245
246
247
250
251
252
253
254
255
256
257bool QLowEnergyCharacteristic::equals(
const QLowEnergyCharacteristic &a,
258 const QLowEnergyCharacteristic &b)
260 if (a.d_ptr != b.d_ptr)
263 if ((a.data && !b.data) || (!a.data && b.data))
269 if (a.data->handle != b.data->handle)
276
277
278
279
280
281
282
283
284
285
286
287
288bool QLowEnergyCharacteristic::isValid()
const
290 if (d_ptr.isNull() || !data)
293 if (d_ptr->state == QLowEnergyService::InvalidService)
300
301
302
303
304
305
306
307
308
309
310
311QLowEnergyHandle QLowEnergyCharacteristic::attributeHandle()
const
313 if (d_ptr.isNull() || !data)
320
321
322
323
324QLowEnergyDescriptor QLowEnergyCharacteristic::descriptor(
const QBluetoothUuid &uuid)
const
326 if (d_ptr.isNull() || !data)
327 return QLowEnergyDescriptor();
329 CharacteristicDataMap::const_iterator charIt = d_ptr->characteristicList.constFind(data->handle);
330 if (charIt != d_ptr->characteristicList.constEnd()) {
331 const QLowEnergyServicePrivate::CharData &charDetails = charIt.value();
333 DescriptorDataMap::const_iterator descIt = charDetails.descriptorList.constBegin();
334 for ( ; descIt != charDetails.descriptorList.constEnd(); ++descIt) {
335 const QLowEnergyHandle descHandle = descIt.key();
336 const QLowEnergyServicePrivate::DescData &descDetails = descIt.value();
338 if (descDetails.uuid == uuid)
339 return QLowEnergyDescriptor(d_ptr, data->handle, descHandle);
343 return QLowEnergyDescriptor();
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395QLowEnergyDescriptor QLowEnergyCharacteristic::clientCharacteristicConfiguration()
const
397 return descriptor(QBluetoothUuid::DescriptorType::ClientCharacteristicConfiguration);
401
402
403
404
405
406QList<QLowEnergyDescriptor> QLowEnergyCharacteristic::descriptors()
const
408 QList<QLowEnergyDescriptor> result;
410 if (d_ptr.isNull() || !data
411 || !d_ptr->characteristicList.contains(data->handle))
414 QList<QLowEnergyHandle> descriptorKeys = d_ptr->characteristicList[data->handle].
415 descriptorList.keys();
417 std::sort(descriptorKeys.begin(), descriptorKeys.end());
419 for (
const QLowEnergyHandle descHandle : std::as_const(descriptorKeys)) {
420 QLowEnergyDescriptor descriptor(d_ptr, data->handle, descHandle);
421 result.append(descriptor);
428
429
430
431
432
433
434
435
437
438
439
440
441
442
443
444
446
447
448
449
450
451
452
453
454const QByteArray QLowEnergyCharacteristic::CCCDDisable = QByteArray::fromHex(
"0000");
455const QByteArray QLowEnergyCharacteristic::CCCDEnableNotification = QByteArray::fromHex(
"0100");
456const QByteArray QLowEnergyCharacteristic::CCCDEnableIndication = QByteArray::fromHex(
"0200");