Skip to content

Jira 795 Make read / write calls to be blocking, git issue #383 #404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libraries/CurieBLE/src/BLECharacteristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,14 @@ bool BLECharacteristic::canUnsubscribe()
return retVar;
}

bool BLECharacteristic::read()
bool BLECharacteristic::read(bool blocked)
{
bool retVar = false;
BLECharacteristicImp *characteristicImp = getImplementation();

if (NULL != characteristicImp)
{
retVar = characteristicImp->read();
retVar = characteristicImp->read(blocked);
}
return retVar;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/CurieBLE/src/BLECharacteristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ class BLECharacteristic: public BLEAttributeWithValue
*
* @note Only for GATT client. Schedule read request to the GATT server
*/
virtual bool read();
virtual bool read(bool blocked = false);

/**
* @brief Write the charcteristic value
Expand Down
2 changes: 1 addition & 1 deletion libraries/CurieBLE/src/internal/BLECallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ uint8_t profile_read_rsp_process(bt_conn_t *conn,
const void *data,
uint16_t length)
{
if (NULL == data)
if (NULL == data && 0 != length)
{
return BT_GATT_ITER_STOP;
}
Expand Down
15 changes: 13 additions & 2 deletions libraries/CurieBLE/src/internal/BLECharacteristicImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,10 @@ bt_uuid_t* BLECharacteristicImp::getClientCharacteristicConfigUuid(void)
return (bt_uuid_t*) &_gatt_ccc_uuid;
}

bool BLECharacteristicImp::read()
bool BLECharacteristicImp::read(bool blocked)
{
int retval = 0;
bool ret_bool;
bt_conn_t* conn = NULL;

if (true == BLEUtils::isLocalBLE(_ble_device))
Expand Down Expand Up @@ -633,8 +634,18 @@ bool BLECharacteristicImp::read()
if (0 == retval)
{
_reading = true;
ret_bool = true;

// Block the call
if (blocked == true)
{
while (_reading == true )
{
delay(5);
}
}
}
return _reading;
return ret_bool;
}

bool BLECharacteristicImp::write(const unsigned char value[],
Expand Down
10 changes: 5 additions & 5 deletions libraries/CurieBLE/src/internal/BLECharacteristicImp.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,18 @@ class BLECharacteristicImp: public BLEAttribute{
/**
* @brief Schedule the read request to read the characteristic in peripheral
*
* @param[in] none
* @param[in] blocked Flag the call is blocked or un-blocked
*
* @return bool Indicate the success or error
*
* @note Only for central device
* @note Only for GATT client
* Default it is un-block call
*/
bool read();
bool read(bool blocked = false);

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

bool _reading;
volatile bool _reading;
bt_gatt_read_params_t _read_params; // GATT read parameter

typedef LinkNode<BLEDescriptorImp *> BLEDescriptorLinkNodeHeader;
Expand Down