Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e08f1a7

Browse files
committedJan 13, 2017
Jira791 Sketch crash using both Firmata and BLE library, gitHub issue #377
1. The BLEStream object adds profile when boot but the HW doesn't be initialized and makes APP crash. 2. Change the BLE initial process not depend on HW. Buffer the attributes if HW not initialized. 3. Changed files libraries/CurieBLE/src/BLEDevice.h - expose constructor libraries/CurieBLE/src/BLEPeripheral.cpp - not call HW init function libraries/CurieBLE/src/internal/BLEDeviceManager.cpp - change init order libraries/CurieBLE/src/internal/BLEProfileManager.cpp - change constructor
1 parent 787fc45 commit e08f1a7

File tree

4 files changed

+20
-51
lines changed

4 files changed

+20
-51
lines changed
 

‎libraries/CurieBLE/src/BLEDevice.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ class BLEDevice
5959
*/
6060
BLEDevice(const BLEDevice* bledevice);
6161
BLEDevice(const BLEDevice& bledevice);
62+
/**
63+
* @brief The BLE device constructure
64+
*
65+
* @param[in] bleaddress BLE device address
66+
*
67+
* @return none
68+
*
69+
* @note none
70+
*/
71+
BLEDevice(const bt_addr_le_t* bleaddress);
6272
virtual ~BLEDevice();
6373

6474

@@ -653,16 +663,6 @@ class BLEDevice
653663
void setAddress(const bt_addr_le_t& addr);
654664

655665
void setAdvertiseData(const uint8_t* adv_data, uint8_t len);
656-
/**
657-
* @brief The BLE device constructure
658-
*
659-
* @param[in] bleaddress BLE device address
660-
*
661-
* @return none
662-
*
663-
* @note none
664-
*/
665-
BLEDevice(const bt_addr_le_t* bleaddress);
666666
private:
667667
void preCheckProfile();
668668

‎libraries/CurieBLE/src/BLEPeripheral.cpp

+1-36
Original file line numberDiff line numberDiff line change
@@ -55,67 +55,37 @@ BLEPeripheral::~BLEPeripheral(void)
5555

5656
void BLEPeripheral::setAdvertisedServiceUuid(const char* advertisedServiceUuid)
5757
{
58-
if (!_initCalled) {
59-
init();
60-
}
61-
6258
BLE.setAdvertisedServiceUuid(advertisedServiceUuid);
6359
}
60+
6461
void BLEPeripheral::setLocalName(const char* localName)
6562
{
66-
if (!_initCalled) {
67-
init();
68-
}
69-
7063
BLE.setLocalName(localName);
7164
}
7265

73-
7466
void BLEPeripheral::setDeviceName(const char *deviceName)
7567
{
76-
if (!_initCalled) {
77-
init();
78-
}
79-
8068
BLE.setDeviceName(deviceName);
8169
}
8270

8371
void BLEPeripheral::setAppearance(const unsigned short appearance)
8472
{
85-
if (!_initCalled) {
86-
init();
87-
}
88-
8973
BLE.setAppearance(appearance);
9074
}
9175

9276
void BLEPeripheral::setConnectionInterval(const unsigned short minConnInterval, const unsigned short maxConnInterval)
9377
{
94-
if (!_initCalled) {
95-
init();
96-
}
97-
9878
BLE.setConnectionInterval(minConnInterval, maxConnInterval);
9979
}
10080

10181
void BLEPeripheral::addAttribute(BLEService& service)
10282
{
103-
if (!_initCalled)
104-
{
105-
init();
106-
}
107-
10883
BLE.addService(service);
10984
_lastService = &service;
11085
}
11186

11287
void BLEPeripheral::addAttribute(BLECharacteristic& characteristic)
11388
{
114-
if (!_initCalled)
115-
{
116-
init();
117-
}
118-
11989
if (_lastService)
12090
{
12191
_lastService->addCharacteristic(characteristic);
@@ -125,11 +95,6 @@ void BLEPeripheral::addAttribute(BLECharacteristic& characteristic)
12595

12696
void BLEPeripheral::addAttribute(BLEDescriptor& descriptor)
12797
{
128-
if (!_initCalled)
129-
{
130-
init();
131-
}
132-
13398
if (_lastCharacteristic)
13499
{
135100
_lastCharacteristic->addDescriptor(descriptor);

‎libraries/CurieBLE/src/internal/BLEDeviceManager.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ BLEDeviceManager::~BLEDeviceManager()
9797

9898
bool BLEDeviceManager::begin(BLEDevice *device)
9999
{
100-
if (NULL == _local_ble && false == *device)
100+
if (NULL == _local_ble)
101101
{
102102
_local_ble = device;
103-
_local_ble->setAddress(_local_bda);
104103
bt_le_set_mac_address(_local_bda);
104+
105105
// Set device name
106106
setDeviceName();
107107
_state = BLE_PERIPH_STATE_READY;
@@ -133,7 +133,8 @@ void BLEDeviceManager::poll()
133133
}
134134

135135
void BLEDeviceManager::end()
136-
{}
136+
{
137+
}
137138

138139
bool BLEDeviceManager::connected(const BLEDevice *device) const
139140
{
@@ -287,7 +288,10 @@ void BLEDeviceManager::setDeviceName(const char* deviceName)
287288
if (len > BLE_MAX_DEVICE_NAME)
288289
len = BLE_MAX_DEVICE_NAME;
289290
memcpy(_device_name, deviceName, len);
290-
setDeviceName();
291+
if (NULL != _local_ble)
292+
{
293+
setDeviceName();
294+
}
291295
}
292296
}
293297

‎libraries/CurieBLE/src/internal/BLEProfileManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "BLECallbacks.h"
2626
#include "BLEUtils.h"
2727

28-
BLEDevice BLE;
28+
BLEDevice BLE(BLEUtils::bleGetLoalAddress());
2929

3030
BLEProfileManager* BLEProfileManager::_instance = NULL;
3131

0 commit comments

Comments
 (0)
Please sign in to comment.