1
1
2
- // #include "internal/ble_client.h"
3
2
#include " ArduinoBLE.h"
4
3
5
4
#include " BLEUtils.h"
@@ -67,7 +66,7 @@ const char* BLECharacteristic::uuid() const
67
66
return _uuid_cstr;
68
67
}
69
68
70
- unsigned char BLECharacteristic::properties ()
69
+ unsigned char BLECharacteristic::properties () const
71
70
{
72
71
unsigned char property = 0 ;
73
72
BLECharacteristicImp *characteristicImp = getImplementation ();
@@ -78,7 +77,7 @@ unsigned char BLECharacteristic::properties()
78
77
return property;
79
78
}
80
79
81
- int BLECharacteristic::valueSize () // const
80
+ int BLECharacteristic::valueSize () const
82
81
{
83
82
int valuesize = 0 ;
84
83
BLECharacteristicImp *characteristicImp = getImplementation ();
@@ -100,7 +99,7 @@ const byte* BLECharacteristic::value() const
100
99
return value_temp;
101
100
}
102
101
103
- int BLECharacteristic::valueLength () // const
102
+ int BLECharacteristic::valueLength () const
104
103
{
105
104
int valueLength = 0 ;
106
105
BLECharacteristicImp *characteristicImp = getImplementation ();
@@ -117,7 +116,7 @@ BLECharacteristic::operator bool() const
117
116
}
118
117
119
118
120
- byte BLECharacteristic::operator [] (int offset) // const
119
+ byte BLECharacteristic::operator [] (int offset) const
121
120
{
122
121
byte data = 0 ;
123
122
BLECharacteristicImp *characteristicImp = getImplementation ();
@@ -144,14 +143,20 @@ bool BLECharacteristic::writeValue(const byte value[], int length)
144
143
characteristicImp->writeValue (value, length);
145
144
retVar = true ;
146
145
}
147
- return retVar ;
146
+ return writeValue (value, length, 0 ) ;
148
147
}
149
148
150
149
bool BLECharacteristic::writeValue (const byte value[], int length, int offset)
151
150
{
152
- // TODO: Not support it now.
153
- // Will add this feature.
154
- return false ;
151
+ bool retVar = false ;
152
+ BLECharacteristicImp *characteristicImp = getImplementation ();
153
+
154
+ if (NULL != characteristicImp)
155
+ {
156
+ characteristicImp->writeValue (value, length, offset);
157
+ retVar = true ;
158
+ }
159
+ return retVar;
155
160
}
156
161
157
162
bool BLECharacteristic::writeValue (const char * value)
@@ -306,7 +311,7 @@ int BLECharacteristic::addDescriptor(BLEDescriptor& descriptor)
306
311
return retVar;
307
312
}
308
313
309
- int BLECharacteristic::descriptorCount () // const
314
+ int BLECharacteristic::descriptorCount () const
310
315
{
311
316
int count = 0 ;
312
317
BLECharacteristicImp *characteristicImp = getImplementation ();
@@ -320,28 +325,97 @@ int BLECharacteristic::descriptorCount() //const
320
325
321
326
bool BLECharacteristic::hasDescriptor (const char * uuid) const
322
327
{
323
- // TODO: Not support now
324
- return false ;
328
+ BLEDescriptorImp* descriptorImp = NULL ;
329
+ BLECharacteristicImp *characteristicImp = getImplementation ();
330
+
331
+ if (NULL != characteristicImp)
332
+ {
333
+ descriptorImp = characteristicImp->descrptor (uuid);
334
+ }
335
+
336
+ return (descriptorImp != NULL );
325
337
}
338
+
326
339
bool BLECharacteristic::hasDescriptor (const char * uuid, int index) const
327
340
{
328
- // TODO: Not support now
329
- return false ;
341
+ bool retVal = false ;
342
+ BLEDescriptorImp* descriptorImp = NULL ;
343
+ BLECharacteristicImp *characteristicImp = getImplementation ();
344
+
345
+ if (NULL != characteristicImp)
346
+ {
347
+ descriptorImp = characteristicImp->descrptor (index);
348
+ if (NULL != descriptorImp)
349
+ {
350
+ retVal = descriptorImp->compareUuid (uuid);
351
+ }
352
+ }
353
+
354
+ return retVal;
330
355
}
356
+
331
357
BLEDescriptor BLECharacteristic::descriptor (int index) const
332
358
{
333
- // TODO: Not support now
334
- return BLEDescriptor ();
359
+ BLEDescriptorImp* descriptorImp = NULL ;
360
+ BLECharacteristicImp *characteristicImp = getImplementation ();
361
+
362
+ if (NULL != characteristicImp)
363
+ {
364
+ descriptorImp = characteristicImp->descrptor (index);
365
+ }
366
+
367
+ if (descriptorImp != NULL )
368
+ {
369
+ return BLEDescriptor (descriptorImp, &_bledev);
370
+ }
371
+ else
372
+ {
373
+ return BLEDescriptor ();
374
+ }
335
375
}
336
376
BLEDescriptor BLECharacteristic::descriptor (const char * uuid) const
337
377
{
338
- // TODO: Not support now
339
- return BLEDescriptor ();
378
+ BLEDescriptorImp* descriptorImp = NULL ;
379
+ BLECharacteristicImp *characteristicImp = getImplementation ();
380
+
381
+ if (NULL != characteristicImp)
382
+ {
383
+ descriptorImp = characteristicImp->descrptor (uuid);
384
+ }
385
+
386
+ if (descriptorImp != NULL )
387
+ {
388
+ return BLEDescriptor (descriptorImp, &_bledev);
389
+ }
390
+ else
391
+ {
392
+ return BLEDescriptor ();
393
+ }
340
394
}
395
+
341
396
BLEDescriptor BLECharacteristic::descriptor (const char * uuid, int index) const
342
397
{
343
- // TODO: Not support now
344
- return BLEDescriptor ();
398
+ bool retVal = false ;
399
+ BLEDescriptorImp* descriptorImp = NULL ;
400
+ BLECharacteristicImp *characteristicImp = getImplementation ();
401
+
402
+ if (NULL != characteristicImp)
403
+ {
404
+ descriptorImp = characteristicImp->descrptor (index);
405
+ if (NULL != descriptorImp)
406
+ {
407
+ retVal = descriptorImp->compareUuid (uuid);
408
+ }
409
+ }
410
+
411
+ if (descriptorImp != NULL && true == retVal)
412
+ {
413
+ return BLEDescriptor (descriptorImp, &_bledev);
414
+ }
415
+ else
416
+ {
417
+ return BLEDescriptor ();
418
+ }
345
419
}
346
420
347
421
void BLECharacteristic::setEventHandler (BLECharacteristicEvent event,
@@ -391,13 +465,15 @@ BLECharacteristic::_setValue(const uint8_t value[], uint16_t length)
391
465
memcpy (_value, value, length);
392
466
}
393
467
394
- BLECharacteristicImp* BLECharacteristic::getImplementation ()
468
+ BLECharacteristicImp* BLECharacteristic::getImplementation () const
395
469
{
396
- if (NULL == _internal)
470
+ BLECharacteristicImp* tmp = NULL ;
471
+ tmp = _internal;
472
+ if (NULL == tmp)
397
473
{
398
- _internal = BLEProfileManager::instance ()->characteristic (_bledev, (const char *)_uuid_cstr);
474
+ tmp = BLEProfileManager::instance ()->characteristic (_bledev, (const char *)_uuid_cstr);
399
475
}
400
- return _internal ;
476
+ return tmp ;
401
477
}
402
478
403
479
void BLECharacteristic::setBLECharacteristicImp (BLECharacteristicImp *characteristicImp)
0 commit comments