Skip to content

Commit 547ecd7

Browse files
sgbihueriknyquist
authored andcommitted
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 fe14b8b commit 547ecd7

File tree

4 files changed

+20
-51
lines changed

4 files changed

+20
-51
lines changed

Diff for: 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

@@ -654,16 +664,6 @@ class BLEDevice
654664
void setAddress(const bt_addr_le_t& addr);
655665

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

Diff for: 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);

Diff for: libraries/CurieBLE/src/internal/BLEDeviceManager.cpp

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

9999
bool BLEDeviceManager::begin(BLEDevice *device)
100100
{
101-
if (NULL == _local_ble && false == *device)
101+
if (NULL == _local_ble)
102102
{
103103
_local_ble = device;
104-
_local_ble->setAddress(_local_bda);
105104
bt_le_set_mac_address(_local_bda);
105+
106106
// Set device name
107107
setDeviceName();
108108
_state = BLE_PERIPH_STATE_READY;
@@ -134,7 +134,8 @@ void BLEDeviceManager::poll()
134134
}
135135

136136
void BLEDeviceManager::end()
137-
{}
137+
{
138+
}
138139

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

Diff for: 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)