Skip to content

Commit 6ea995d

Browse files
committed
Jira 795 Make read / write calls to be blocking, git issue arduino#383
1. Add the parameter of read to support block/unblock call. 2. Changed file list libraries/CurieBLE/src/BLECharacteristic.cpp libraries/CurieBLE/src/BLECharacteristic.h libraries/CurieBLE/src/internal/BLECallbacks.cpp libraries/CurieBLE/src/internal/BLECharacteristicImp.cpp libraries/CurieBLE/src/internal/BLECharacteristicImp.h
1 parent ffcfffb commit 6ea995d

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

libraries/CurieBLE/src/BLECharacteristic.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,14 @@ bool BLECharacteristic::canUnsubscribe()
367367
return retVar;
368368
}
369369

370-
bool BLECharacteristic::read()
370+
bool BLECharacteristic::read(bool blocked)
371371
{
372372
bool retVar = false;
373373
BLECharacteristicImp *characteristicImp = getImplementation();
374374

375375
if (NULL != characteristicImp)
376376
{
377-
retVar = characteristicImp->read();
377+
retVar = characteristicImp->read(blocked);
378378
}
379379
return retVar;
380380
}

libraries/CurieBLE/src/BLECharacteristic.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ class BLECharacteristic: public BLEAttributeWithValue
321321
*
322322
* @note Only for GATT client. Schedule read request to the GATT server
323323
*/
324-
virtual bool read();
324+
virtual bool read(bool blocked = false);
325325

326326
/**
327327
* @brief Write the charcteristic value

libraries/CurieBLE/src/internal/BLECallbacks.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ uint8_t profile_read_rsp_process(bt_conn_t *conn,
145145
const void *data,
146146
uint16_t length)
147147
{
148-
if (NULL == data)
148+
if (NULL == data && 0 != length)
149149
{
150150
return BT_GATT_ITER_STOP;
151151
}

libraries/CurieBLE/src/internal/BLECharacteristicImp.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -593,9 +593,10 @@ bt_uuid_t* BLECharacteristicImp::getClientCharacteristicConfigUuid(void)
593593
return (bt_uuid_t*) &_gatt_ccc_uuid;
594594
}
595595

596-
bool BLECharacteristicImp::read()
596+
bool BLECharacteristicImp::read(bool blocked)
597597
{
598598
int retval = 0;
599+
bool ret_bool;
599600
bt_conn_t* conn = NULL;
600601

601602
if (true == BLEUtils::isLocalBLE(_ble_device))
@@ -633,8 +634,18 @@ bool BLECharacteristicImp::read()
633634
if (0 == retval)
634635
{
635636
_reading = true;
637+
ret_bool = true;
638+
639+
// Block the call
640+
if (blocked == true)
641+
{
642+
while (_reading == true )
643+
{
644+
delay(5);
645+
}
646+
}
636647
}
637-
return _reading;
648+
return ret_bool;
638649
}
639650

640651
bool BLECharacteristicImp::write(const unsigned char value[],

libraries/CurieBLE/src/internal/BLECharacteristicImp.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,18 @@ class BLECharacteristicImp: public BLEAttribute{
146146
/**
147147
* @brief Schedule the read request to read the characteristic in peripheral
148148
*
149-
* @param[in] none
149+
* @param[in] blocked Flag the call is blocked or un-blocked
150150
*
151151
* @return bool Indicate the success or error
152152
*
153-
* @note Only for central device
153+
* @note Only for GATT client
154+
* Default it is un-block call
154155
*/
155-
bool read();
156+
bool read(bool blocked = false);
156157

157158
/**
158159
* @brief Schedule the write request to update the characteristic in peripheral
159160
*
160-
* @param[in] peripheral The peripheral device that want to be updated
161161
* @param[in] value New value to set, as a byte array. Data is stored in internal copy.
162162
* @param[in] length Length, in bytes, of valid data in the array to write.
163163
* Must not exceed maxLength set for this characteristic.
@@ -324,7 +324,7 @@ class BLECharacteristicImp: public BLEAttribute{
324324
bt_gatt_subscribe_params_t _sub_params;
325325
bool _subscribed;
326326

327-
bool _reading;
327+
volatile bool _reading;
328328
bt_gatt_read_params_t _read_params; // GATT read parameter
329329

330330
typedef LinkNode<BLEDescriptorImp *> BLEDescriptorLinkNodeHeader;

0 commit comments

Comments
 (0)