Skip to content

Commit 5b69b5a

Browse files
committed
Fix the review issues and dismiss some TODOs
Notice: Not test on IDE
1 parent 5fc779b commit 5b69b5a

17 files changed

+554
-142
lines changed

libraries/BLE/examples/central/central.ino

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11

22
#include "ArduinoBLE.h"
3-
#include "BLEAttribute.h"
4-
#include "BLECharacteristicImp.h"
5-
#include "BLEProfileManager.h"
63

74
// LED pin
85
#define LED_PIN 13
96

107
void setup() {
11-
Serial.begin(115200);
8+
Serial.begin(9600);
129
Serial.println("test---");
1310

1411
// set LED pin to output mode
@@ -45,12 +42,9 @@ void controlLed(BLEDevice &peripheral)
4542

4643
if (!ledCharacteristic)
4744
{
48-
//peripheral.disconnect();
49-
while(1)
50-
{
45+
peripheral.disconnect();
5146
Serial.println("Peripheral does not have LED characteristic!");
5247
delay(5000);
53-
}
5448
return;
5549
}
5650

@@ -76,9 +70,7 @@ void controlLed(BLEDevice &peripheral)
7670
}
7771

7872
void loop() {
79-
//pr_debug(LOG_MODULE_BLE, "%s-%d",__FUNCTION__, __LINE__);
8073
BLEDevice peripheral = BLE.available();
81-
//pr_debug(LOG_MODULE_BLE, "%s-%d",__FUNCTION__, __LINE__);
8274
if (peripheral)
8375
{
8476
Serial.println(peripheral.address());

libraries/BLE/examples/notification/notification.ino

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11

22
#include "ArduinoBLE.h"
3-
#include "BLEAttribute.h"
4-
#include "BLECharacteristicImp.h"
5-
#include "BLEProfileManager.h"
63

74
// LED pin
85
#define LED_PIN 13
@@ -15,7 +12,7 @@ BLECharacteristic switchCharacteristic("19b10101e8f2537e4f6cd104768a1214", BLE
1512
BLEDescriptor switchDescriptor("2901", "switch");
1613

1714
void setup() {
18-
Serial.begin(115200);
15+
Serial.begin(9600);
1916
Serial.println("test---");
2017

2118
// set LED pin to output mode

libraries/BLE/examples/notifycentral/notifycentral.ino

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11

22
#include "ArduinoBLE.h"
3-
#include "BLEAttribute.h"
4-
#include "BLECharacteristicImp.h"
5-
#include "BLEProfileManager.h"
63

74
// LED pin
85
#define LED_PIN 13
96

107
void setup() {
11-
Serial.begin(115200);
8+
Serial.begin(9600);
129
Serial.println("test---");
1310

1411
// set LED pin to output mode
@@ -45,12 +42,9 @@ void controlLed(BLEDevice &peripheral)
4542

4643
if (!ledCharacteristic)
4744
{
48-
//peripheral.disconnect();
49-
while(1)
50-
{
45+
peripheral.disconnect();
5146
Serial.println("Peripheral does not have LED characteristic!");
5247
delay(5000);
53-
}
5448
return;
5549
}
5650
ledCharacteristic.subscribe();

libraries/BLE/examples/test/test.ino

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11

22
#include "ArduinoBLE.h"
3-
#include "BLEAttribute.h"
4-
#include "BLECharacteristicImp.h"
5-
#include "BLEProfileManager.h"
63

74
// LED pin
85
#define LED_PIN 13
@@ -15,7 +12,7 @@ BLECharacteristic switchCharacteristic("19b10101e8f2537e4f6cd104768a1214", BLE
1512
BLEDescriptor switchDescriptor("2901", "switch");
1613

1714
void setup() {
18-
Serial.begin(115200);
15+
Serial.begin(9600);
1916
Serial.println("test---");
2017

2118
// set LED pin to output mode

libraries/BLE/src/ArduinoBLE.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class BLECharacteristic;
2727
class BLEDescriptor;
2828
class BLEService;
2929
class BLECharacteristicImp;
30+
class BLEDescriptorImp;
3031

3132
#include "BLECommon.h"
3233

libraries/BLE/src/BLECharacteristic.cpp

Lines changed: 100 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
//#include "internal/ble_client.h"
32
#include "ArduinoBLE.h"
43

54
#include "BLEUtils.h"
@@ -67,7 +66,7 @@ const char* BLECharacteristic::uuid() const
6766
return _uuid_cstr;
6867
}
6968

70-
unsigned char BLECharacteristic::properties()
69+
unsigned char BLECharacteristic::properties() const
7170
{
7271
unsigned char property = 0;
7372
BLECharacteristicImp *characteristicImp = getImplementation();
@@ -78,7 +77,7 @@ unsigned char BLECharacteristic::properties()
7877
return property;
7978
}
8079

81-
int BLECharacteristic::valueSize() //const
80+
int BLECharacteristic::valueSize() const
8281
{
8382
int valuesize = 0;
8483
BLECharacteristicImp *characteristicImp = getImplementation();
@@ -100,7 +99,7 @@ const byte* BLECharacteristic::value() const
10099
return value_temp;
101100
}
102101

103-
int BLECharacteristic::valueLength() //const
102+
int BLECharacteristic::valueLength() const
104103
{
105104
int valueLength = 0;
106105
BLECharacteristicImp *characteristicImp = getImplementation();
@@ -117,7 +116,7 @@ BLECharacteristic::operator bool() const
117116
}
118117

119118

120-
byte BLECharacteristic::operator[] (int offset) //const
119+
byte BLECharacteristic::operator[] (int offset) const
121120
{
122121
byte data = 0;
123122
BLECharacteristicImp *characteristicImp = getImplementation();
@@ -144,14 +143,20 @@ bool BLECharacteristic::writeValue(const byte value[], int length)
144143
characteristicImp->writeValue(value, length);
145144
retVar = true;
146145
}
147-
return retVar;
146+
return writeValue(value, length, 0);
148147
}
149148

150149
bool BLECharacteristic::writeValue(const byte value[], int length, int offset)
151150
{
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;
155160
}
156161

157162
bool BLECharacteristic::writeValue(const char* value)
@@ -306,7 +311,7 @@ int BLECharacteristic::addDescriptor(BLEDescriptor& descriptor)
306311
return retVar;
307312
}
308313

309-
int BLECharacteristic::descriptorCount() //const
314+
int BLECharacteristic::descriptorCount() const
310315
{
311316
int count = 0;
312317
BLECharacteristicImp *characteristicImp = getImplementation();
@@ -320,28 +325,97 @@ int BLECharacteristic::descriptorCount() //const
320325

321326
bool BLECharacteristic::hasDescriptor(const char* uuid) const
322327
{
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);
325337
}
338+
326339
bool BLECharacteristic::hasDescriptor(const char* uuid, int index) const
327340
{
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;
330355
}
356+
331357
BLEDescriptor BLECharacteristic::descriptor(int index) const
332358
{
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+
}
335375
}
336376
BLEDescriptor BLECharacteristic::descriptor(const char * uuid) const
337377
{
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+
}
340394
}
395+
341396
BLEDescriptor BLECharacteristic::descriptor(const char * uuid, int index) const
342397
{
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+
}
345419
}
346420

347421
void BLECharacteristic::setEventHandler(BLECharacteristicEvent event,
@@ -391,13 +465,15 @@ BLECharacteristic::_setValue(const uint8_t value[], uint16_t length)
391465
memcpy(_value, value, length);
392466
}
393467

394-
BLECharacteristicImp* BLECharacteristic::getImplementation()
468+
BLECharacteristicImp* BLECharacteristic::getImplementation() const
395469
{
396-
if (NULL == _internal)
470+
BLECharacteristicImp* tmp = NULL;
471+
tmp = _internal;
472+
if (NULL == tmp)
397473
{
398-
_internal = BLEProfileManager::instance()->characteristic(_bledev, (const char*)_uuid_cstr);
474+
tmp = BLEProfileManager::instance()->characteristic(_bledev, (const char*)_uuid_cstr);
399475
}
400-
return _internal;
476+
return tmp;
401477
}
402478

403479
void BLECharacteristic::setBLECharacteristicImp(BLECharacteristicImp *characteristicImp)

0 commit comments

Comments
 (0)