Skip to content

Commit 99af2e0

Browse files
committed
Jira 541 Peripheral Start fails on X Number of Attributes
Change the interface and add return value
1 parent 286f98c commit 99af2e0

14 files changed

+137
-83
lines changed

libraries/CurieBLE/src/BLECentral.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ void BLECentral::setScanParam(const struct bt_le_scan_param &scan_param)
6161
BLECentralRole::instance()->setScanParam(scan_param);
6262
}
6363

64-
void BLECentral::addAttribute(BLEAttribute& attribute)
64+
BleStatus BLECentral::addAttribute(BLEAttribute& attribute)
6565
{
66-
BLECentralRole::instance()->addAttribute(attribute);
66+
return BLECentralRole::instance()->addAttribute(attribute);
6767
}
6868

6969
bool BLECentral::begin(void)

libraries/CurieBLE/src/BLECentral.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,12 @@ class BLECentral{
100100
*
101101
* @param attribute Attribute to add to Central
102102
*
103-
* @return none
103+
* @return BleStatus indicating success or error
104104
*
105105
* @note The attribute will used for discover the peripheral handler
106+
* Only need check return value at first call. Memory only alloc at first call
106107
*/
107-
void addAttribute(BLEAttribute& attribute);
108+
BleStatus addAttribute(BLEAttribute& attribute);
108109

109110
/**
110111
* Provide a function to be called when events related to this Device are raised

libraries/CurieBLE/src/BLECentralRole.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,18 @@ void BLECentralRole::setAdvertiseHandler(ble_advertise_handle_cb_t advcb)
265265
_adv_event_handle = advcb;
266266
}
267267

268-
void BLECentralRole::addAttribute(BLEAttribute& attribute)
268+
BleStatus BLECentralRole::addAttribute(BLEAttribute& attribute)
269269
{
270+
BleStatus err = BLE_STATUS_SUCCESS;
270271
for (int i = 0; i < BLE_MAX_CONN_CFG; i++)
271272
{
272-
_peripherial[i]->addAttribute(attribute);
273+
err = _peripherial[i]->addAttribute(attribute);
274+
if (err != BLE_STATUS_SUCCESS)
275+
{
276+
break;
277+
}
273278
}
279+
return err;
274280
}
275281

276282
bool BLECentralRole::begin()

libraries/CurieBLE/src/BLECentralRole.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ class BLECentralRole: public BLERoleBase {
110110
*
111111
* @param attribute Attribute to add to Central
112112
*
113-
* @return none
113+
* @return BleStatus indicating success or error
114114
*
115115
* @note The attribute will used for discover the peripheral handler
116116
*/
117-
void addAttribute(BLEAttribute& attribute);
117+
BleStatus addAttribute(BLEAttribute& attribute);
118118

119119
/**
120120
* Provide a function to be called when events related to this Device are raised
@@ -237,8 +237,8 @@ class BLECentralRole: public BLERoleBase {
237237
*/
238238
void handleParamUpdated(struct bt_conn *conn,
239239
uint16_t interval,
240-
uint16_t latency,
241-
uint16_t timeout);
240+
uint16_t latency,
241+
uint16_t timeout);
242242
/**
243243
* @brief Handle the advertisement
244244
*

libraries/CurieBLE/src/BLECommon.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ enum BLE_STATUS {
6565
BLE_STATUS_ALREADY_REGISTERED, /**< BLE service already registered */
6666
BLE_STATUS_WRONG_STATE, /**< Wrong state for request */
6767
BLE_STATUS_ERROR_PARAMETER, /**< Parameter in request is wrong */
68+
BLE_STATUS_NO_MEMORY, /**< System doesn't have memory */
6869
BLE_STATUS_GAP_BASE = 0x100, /**< GAP specific error base */
6970
BLE_STATUS_GATT_BASE = 0x200, /**< GATT specific Error base */
7071
};

libraries/CurieBLE/src/BLEPeripheral.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ BLEPeripheral::connected()
143143
return BLEPeripheralRole::instance()->connected();
144144
}
145145

146-
void BLEPeripheral::addAttribute(BLEAttribute& attribute)
146+
BleStatus
147+
BLEPeripheral::addAttribute(BLEAttribute& attribute)
147148
{
148-
BLEPeripheralRole::instance()->addAttribute(attribute);
149+
return BLEPeripheralRole::instance()->addAttribute(attribute);
149150
}
150151

151152

libraries/CurieBLE/src/BLEPeripheral.h

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,9 @@ class BLEPeripheral{
146146
* @return BleStatus indicating success or error
147147
*
148148
* @note This method must be called before the begin method
149+
* Only need check return value at first call. Memory only alloc at first call
149150
*/
150-
void addAttribute(BLEAttribute& attribute);
151+
BleStatus addAttribute(BLEAttribute& attribute);
151152

152153
/**
153154
* Provide a function to be called when events related to this Device are raised
@@ -195,35 +196,35 @@ class BLEPeripheral{
195196
*/
196197
bool connected(void);
197198

198-
/**
199-
* @brief Init the ADV data and start send advertisement
200-
*
201-
* @param none
202-
*
203-
* @return BleStatus 0 - Success. Others - error code
204-
*
205-
* @note none
206-
*/
199+
/**
200+
* @brief Init the ADV data and start send advertisement
201+
*
202+
* @param none
203+
*
204+
* @return BleStatus 0 - Success. Others - error code
205+
*
206+
* @note none
207+
*/
207208
BleStatus startAdvertising(void);
208-
209-
/**
210-
* @brief Stop send advertisement
211-
*
212-
* @param none
213-
*
214-
* @return BleStatus 0 - Success. Others - error code
215-
*
216-
* @note none
217-
*/
218-
BleStatus stopAdvertising(void);
219-
209+
210+
/**
211+
* @brief Stop send advertisement
212+
*
213+
* @param none
214+
*
215+
* @return BleStatus 0 - Success. Others - error code
216+
*
217+
* @note none
218+
*/
219+
BleStatus stopAdvertising(void);
220+
220221
protected:
221222
void handleConnectEvent(struct bt_conn *conn, uint8_t err);
222223
void handleDisconnectEvent(struct bt_conn *conn, uint8_t reason);
223224
void handleParamUpdated(struct bt_conn *conn,
224225
uint16_t interval,
225-
uint16_t latency,
226-
uint16_t timeout);
226+
uint16_t latency,
227+
uint16_t timeout);
227228

228229
private:
229230

libraries/CurieBLE/src/BLEPeripheralHelper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ void BLEPeripheralHelper::linkLost(void)
9494
}
9595
}
9696

97-
void BLEPeripheralHelper::addAttribute(BLEAttribute& attribute)
97+
BleStatus BLEPeripheralHelper::addAttribute(BLEAttribute& attribute)
9898
{
99-
_profile.addAttribute(attribute);
99+
return _profile.addAttribute(attribute);
100100
}
101101

102102
int BLEPeripheralHelper::registerProfile()

libraries/CurieBLE/src/BLEPeripheralHelper.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,12 @@ class BLEPeripheralHelper : public BLEHelper {
4848
* Add an attribute to the BLE Peripheral helper
4949
*
5050
* @param attribute Attribute to add to Peripheral
51+
*
52+
* @return BleStatus indicating success or error
5153
*
5254
* @note This method must be called before the begin method
5355
*/
54-
void addAttribute(BLEAttribute& attribute);
56+
BleStatus addAttribute(BLEAttribute& attribute);
5557

5658
BLEAttribute *attribute(struct bt_gatt_subscribe_params *params);
5759
BLEAttribute *attribute(uint16_t handle);

libraries/CurieBLE/src/BLEPeripheralRole.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,10 @@ BLEPeripheralRole::connected()
158158
return _central;
159159
}
160160

161-
void BLEPeripheralRole::addAttribute(BLEAttribute& attribute)
161+
BleStatus
162+
BLEPeripheralRole::addAttribute(BLEAttribute& attribute)
162163
{
163-
_peripheral.addAttribute(attribute);
164+
return _peripheral.addAttribute(attribute);
164165
}
165166

166167
BleStatus

0 commit comments

Comments
 (0)