Skip to content

Commit c46f904

Browse files
committed
Update the code after merge to resolve the build issue
1 parent 8707049 commit c46f904

File tree

11 files changed

+94
-112
lines changed

11 files changed

+94
-112
lines changed

libraries/BLE/examples/central/led_control/led_control.ino

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
const int buttonPin = 2;
2525
int oldButtonState = LOW;
2626

27-
char uuid_buf[70];
2827

2928
void setup() {
3029
Serial.begin(9600);
@@ -47,16 +46,16 @@ void loop() {
4746

4847
if (peripheral) {
4948
// discovered a peripheral, print out address, local name, and advertised service
50-
peripheral.advertisedServiceUuid(uuid_buf);
5149
Serial.print("Found ");
5250
Serial.print(peripheral.address());
5351
Serial.print(" '");
5452
Serial.print(peripheral.localName());
5553
Serial.print("' ");
56-
Serial.println(uuid_buf);
54+
Serial.print(peripheral.advertisedServiceUuid());
55+
Serial.println();
5756

5857
// see if peripheral is advertising the LED service
59-
if (String(uuid_buf) == String("19b10000-e8f2-537e-4f6c-d104768a1214")) {
58+
if (peripheral.advertisedServiceUuid() == "19b10000-e8f2-537e-4f6c-d104768a1214") {
6059
// stop scanning
6160
BLE.stopScan();
6261

libraries/BLE/examples/central/peripheral_explorer/peripheral_explorer.ino

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
#include <ArduinoBLE.h>
2121

22-
char uuid_buf[70];
23-
2422
void setup() {
2523
Serial.begin(9600);
2624

@@ -39,13 +37,13 @@ void loop() {
3937

4038
if (peripheral) {
4139
// discovered a peripheral, print out address, local name, and advertised service
42-
peripheral.advertisedServiceUuid(uuid_buf);
4340
Serial.print("Found ");
4441
Serial.print(peripheral.address());
4542
Serial.print(" '");
4643
Serial.print(peripheral.localName());
4744
Serial.print("' ");
48-
Serial.println(uuid_buf);
45+
Serial.print(peripheral.advertisedServiceUuid());
46+
Serial.println();
4947

5048
// see if peripheral is a SensorTag
5149
if (peripheral.localName() == "SensorTag") {

libraries/BLE/examples/central/scan/scan.ino

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1818
*/
1919

20-
char uuid_buf[70];
21-
2220
#include <ArduinoBLE.h>
2321

2422
void setup() {
@@ -56,8 +54,8 @@ void loop() {
5654
if (peripheral.hasAdvertisedServiceUuid()) {
5755
Serial.print("Service UUID's: ");
5856
for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) {
59-
peripheral.advertisedServiceUuid(i, uuid_buf);
60-
Serial.print(String(uuid_buf) + " ");
57+
Serial.print(peripheral.advertisedServiceUuid(i));
58+
Serial.print(" ");
6159
}
6260
Serial.println();
6361
}

libraries/BLE/examples/central/scan_callback/scan_callback.ino

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
#include <ArduinoBLE.h>
2121

22-
char uuid_buf[70];
23-
2422
void setup() {
2523
Serial.begin(9600);
2624

@@ -60,8 +58,8 @@ void bleCentralDiscoverHandler(BLEDevice peripheral) {
6058
if (peripheral.hasAdvertisedServiceUuid()) {
6159
Serial.print("Service UUID's: ");
6260
for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) {
63-
peripheral.advertisedServiceUuid(i, uuid_buf);
64-
Serial.print(String(uuid_buf) + " ");
61+
Serial.print(peripheral.advertisedServiceUuid(i));
62+
Serial.print(" ");
6563
}
6664
Serial.println();
6765
}

libraries/BLE/examples/central/sensortag_button/sensortag_button.ino

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
#include <ArduinoBLE.h>
2121

22-
uuid_buf[70];
23-
2422
void setup() {
2523
Serial.begin(9600);
2624

@@ -39,14 +37,13 @@ void loop() {
3937

4038
if (peripheral) {
4139
// discovered a peripheral, print out address, local name, and advertised service
42-
peripheral.advertisedServiceUuid(uuid_buf);
43-
4440
Serial.print("Found ");
4541
Serial.print(peripheral.address());
4642
Serial.print(" '");
4743
Serial.print(peripheral.localName());
4844
Serial.print("' ");
49-
Serial.println(uuid_buf);
45+
Serial.print(peripheral.advertisedServiceUuid());
46+
Serial.println();
5047

5148
// see if peripheral is a SensorTag
5249
if (peripheral.localName() == "SensorTag") {

libraries/BLE/src/BLECharacteristic.cpp

Lines changed: 45 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
BLECharacteristic::BLECharacteristic():
1313
_bledev(), _internal(NULL), _chrc_local_imp(NULL), _broadcast(false),
14-
_properties(0), _value_size(0), _value(NULL),
15-
_event_handlers(NULL)
14+
_properties(0), _value_size(0), _value(NULL)//,
15+
//_event_handlers(NULL)
1616
{
1717
memset(_uuid_cstr, 0, sizeof(_uuid_cstr));
1818
memset(_event_handlers, 0, sizeof(_event_handlers));
@@ -23,8 +23,8 @@ BLECharacteristic::BLECharacteristic(const char* uuid,
2323
unsigned short valueSize):
2424
_bledev(), _internal(NULL), _chrc_local_imp(NULL), _broadcast(false),
2525
_properties(properties),
26-
_value(NULL),
27-
_event_handlers(NULL)
26+
_value(NULL)//,
27+
//_event_handlers(NULL)
2828
{
2929
bt_uuid_128 bt_uuid_tmp;
3030
_value_size = valueSize > BLE_MAX_ATTR_LONGDATA_LEN ? BLE_MAX_ATTR_LONGDATA_LEN : valueSize;
@@ -45,58 +45,17 @@ BLECharacteristic::BLECharacteristic(const char* uuid,
4545
BLECharacteristic::BLECharacteristic(BLECharacteristicImp *characteristicImp,
4646
const BLEDevice *bleDev):
4747
_bledev(bleDev), _internal(characteristicImp), _chrc_local_imp(NULL),
48-
_broadcast(false), _value(NULL),_event_handlers(NULL)
48+
_broadcast(false), _value(NULL)//,_event_handlers(NULL)
4949
{
5050
BLEUtils::uuidBT2String(characteristicImp->bt_uuid(), _uuid_cstr);
5151
_properties = characteristicImp->properties();
5252
_value_size = characteristicImp->valueSize();
5353
memset(_event_handlers, 0, sizeof(_event_handlers));
5454
}
5555

56-
BLECharacteristic::BLECharacteristic(const BLECharacteristic& rhs)
57-
{
58-
_value = (unsigned char*)malloc(rhs._value_size); // Sid. KW: _value should not make local here
59-
if (_value) {
60-
memcpy(_value, rhs._value, rhs._value_size);
61-
_value_size = rhs._value_size;
62-
} else {
63-
_value_size = 0;
64-
}
65-
memcpy(_uuid_cstr, rhs._uuid_cstr, sizeof(_uuid_cstr));
66-
_properties = rhs._properties;
67-
memcpy(_event_handlers, rhs._event_handlers, sizeof(_event_handlers));
68-
_internal = rhs._internal;
69-
_bledev = BLEDevice(&rhs._bledev);
70-
}
71-
72-
BLECharacteristic& BLECharacteristic::operator= (const BLECharacteristic& rhs)
73-
{
74-
if (this != &rhs)
75-
{
76-
if (_value)
77-
{
78-
free(_value);
79-
}
80-
_value = (unsigned char*)malloc(rhs._value_size);
81-
if (_value)
82-
{
83-
memcpy(_value, rhs._value, rhs._value_size);
84-
_value_size = rhs._value_size;
85-
} else {
86-
_value_size = 0;
87-
}
88-
memcpy(_uuid_cstr, rhs._uuid_cstr, sizeof(_uuid_cstr));
89-
_properties = rhs._properties;
90-
memcpy(_event_handlers, rhs._event_handlers, sizeof(_event_handlers));
91-
_internal = rhs._internal;
92-
_bledev = BLEDevice(&rhs._bledev);
93-
}
94-
return *this;
95-
}
96-
9756
BLECharacteristic::BLECharacteristic(const BLECharacteristic& rhs):
98-
_value(NULL),
99-
_event_handlers(NULL)
57+
_value(NULL)//,
58+
//_event_handlers(NULL)
10059
{
10160
_chrc_local_imp = NULL; // Not copy
10261
_value_size = rhs._value_size;
@@ -117,22 +76,28 @@ BLECharacteristic::BLECharacteristic(const BLECharacteristic& rhs):
11776

11877
}
11978

120-
if (rhs._event_handlers != NULL)
79+
//if (rhs._event_handlers != NULL)
12180
{
122-
_event_handlers = (BLECharacteristicEventHandler*)malloc(sizeof(BLECharacteristicEventHandler) * BLECharacteristicEventLast);
81+
//_event_handlers = (BLECharacteristicEventHandler*)malloc(sizeof(BLECharacteristicEventHandler) * BLECharacteristicEventLast);
12382

124-
if (NULL != _event_handlers)
83+
//if (NULL != _event_handlers)
12584
memcpy(_event_handlers, rhs._event_handlers, (sizeof(BLECharacteristicEventHandler) * BLECharacteristicEventLast));
12685
}
12786
}
128-
//return *this;
12987
}
13088

13189
BLECharacteristic::~BLECharacteristic()
13290
{
13391
if (_value)
13492
{
13593
free(_value);
94+
_value = NULL;
95+
}
96+
97+
if (_chrc_local_imp != NULL)
98+
{
99+
delete _chrc_local_imp;
100+
_chrc_local_imp = NULL;
136101
}
137102
}
138103

@@ -219,14 +184,17 @@ BLECharacteristic& BLECharacteristic::operator= (const BLECharacteristic& chrc)
219184

220185
if (NULL != _value)
221186
memcpy(_value, chrc._value, chrc._value_size);
187+
else {
188+
_value_size = 0;
189+
}
222190
}
223191

224-
if (chrc._event_handlers != NULL)
192+
//if (chrc._event_handlers != NULL)
225193
{
226-
if (NULL == _event_handlers)
227-
_event_handlers = (BLECharacteristicEventHandler*)malloc(sizeof(BLECharacteristicEventHandler) * BLECharacteristicEventLast);
194+
//if (NULL == _event_handlers)
195+
// _event_handlers = (BLECharacteristicEventHandler*)malloc(sizeof(BLECharacteristicEventHandler) * BLECharacteristicEventLast);
228196

229-
if (NULL != _event_handlers)
197+
//if (NULL != _event_handlers)
230198
memcpy(_event_handlers, chrc._event_handlers, (sizeof(BLECharacteristicEventHandler) * BLECharacteristicEventLast));
231199
}
232200

@@ -426,16 +394,36 @@ bool BLECharacteristic::valueUpdated()
426394

427395
int BLECharacteristic::addDescriptor(BLEDescriptor& descriptor)
428396
{
429-
bool retVar = false;
397+
int retVar = BLE_STATUS_ERROR;
430398
BLECharacteristicImp *characteristicImp = getImplementation();
431399

432400
if (NULL != characteristicImp)
433401
{
434402
retVar = characteristicImp->addDescriptor(descriptor);
435403
}
404+
else if (BLEUtils::isLocalBLE(_bledev) == true)
405+
{
406+
// Only support the GATT server that create the service in local device.
407+
_chrc_local_imp = new BLECharacteristicImp(*this, _bledev);
408+
if (NULL == _chrc_local_imp)
409+
{
410+
retVar = BLE_STATUS_NO_MEMORY;
411+
}
412+
else
413+
{
414+
retVar = _chrc_local_imp->addDescriptor(descriptor);
415+
}
416+
}
436417
return retVar;
437418
}
438419

420+
BLECharacteristicImp* BLECharacteristic::fetchCharacteristicImp()
421+
{
422+
BLECharacteristicImp* temp = _chrc_local_imp;
423+
_chrc_local_imp = NULL;
424+
return temp;
425+
}
426+
439427
int BLECharacteristic::descriptorCount() const
440428
{
441429
int count = 0;

libraries/BLE/src/BLEDevice.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,14 @@ String BLEDevice::localName() const
294294
return BLEDeviceManager::instance()->localName(this);
295295
}
296296

297-
void BLEDevice::advertisedServiceUuid(char *buf) const
297+
String BLEDevice::advertisedServiceUuid() const
298298
{
299-
BLEDeviceManager::instance()->advertisedServiceUuid(this, buf);
299+
return BLEDeviceManager::instance()->advertisedServiceUuid(this);
300300
}
301301

302-
void BLEDevice::advertisedServiceUuid(int index, char *buf) const
302+
String BLEDevice::advertisedServiceUuid(int index) const
303303
{
304-
BLEDeviceManager::instance()->advertisedServiceUuid(this, index, buf);
304+
return BLEDeviceManager::instance()->advertisedServiceUuid(this, index);
305305
}
306306

307307
int BLEDevice::rssi() const

libraries/BLE/src/BLEDevice.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ class BLEDevice
460460
int advertisedServiceUuidCount() const; // number of services the peripheral is advertising
461461

462462
String localName() const; // returns the advertised local name as a String
463-
void advertisedServiceUuid(char *buf) const; // returns the advertised service as a UUID String
464-
void advertisedServiceUuid(int index, char *buf) const; // returns the nth advertised service as a UUID String
463+
String advertisedServiceUuid() const; // returns the advertised service as a UUID String
464+
String advertisedServiceUuid(int index) const; // returns the nth advertised service as a UUID String
465465

466466
int rssi() const; // returns the RSSI of the peripheral at discovery
467467

libraries/BLE/src/internal/BLEDescriptorImp.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,29 +79,29 @@ BLEDescriptorImp& BLEDescriptorImp::operator=(const BLEDescriptorImp& that)
7979
{
8080
if (this != &that) {
8181

82-
BLEAttribute::operator=(that);
83-
if (_value)
84-
free(_value);
85-
86-
_value_length = that._value_length;
87-
_value = (unsigned char *)malloc(_value_length);
88-
if (_value)
89-
memcpy(_value, that._value, sizeof(_value_length));
90-
else
91-
_value_length = 0;
92-
93-
_value_handle = that._value_handle;
94-
_properties = that._properties;
95-
_descriptor_uuid = that._descriptor_uuid;
96-
_bledev = BLEDevice(&that._bledev);
82+
BLEAttribute::operator=(that);
83+
if (_value)
84+
free(_value);
85+
86+
_value_length = that._value_length;
87+
_value = (unsigned char *)malloc(_value_length);
88+
if (_value)
89+
memcpy(_value, that._value, sizeof(_value_length));
90+
else
91+
_value_length = 0;
92+
93+
_value_handle = that._value_handle;
94+
_properties = that._properties;
95+
_descriptor_uuid = that._descriptor_uuid;
96+
_bledev = BLEDevice(&that._bledev);
9797
}
9898
return *this;
9999
}
100100

101101
BLEDescriptorImp::~BLEDescriptorImp() {
102102
if (_value != (unsigned char *)NULL) {
103103
free(_value);
104-
_value = (unsigned char *)NULL;
104+
_value = (unsigned char *)NULL;
105105
}
106106
}
107107

0 commit comments

Comments
 (0)