Skip to content

Commit e6cb20a

Browse files
author
Marc Laliberte
authored
Update BLERemoteCharacteristic.cpp
1 parent ef4427a commit e6cb20a

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/BLERemoteCharacteristic.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ BLERemoteCharacteristic::BLERemoteCharacteristic(
5757
*@brief Destructor.
5858
*/
5959
BLERemoteCharacteristic::~BLERemoteCharacteristic() {
60-
if(m_rawData != nullptr) free(m_rawData);
6160
removeDescriptors(); // Release resources for any descriptor information we may have allocated.
61+
if(m_rawData != nullptr) free(m_rawData);
6262
} // ~BLERemoteCharacteristic
6363

6464

@@ -523,10 +523,10 @@ std::string BLERemoteCharacteristic::toString() {
523523
* @brief Write the new value for the characteristic.
524524
* @param [in] newValue The new value to write.
525525
* @param [in] response Do we expect a response?
526-
* @return N/A.
526+
* @return false if not connected or cant perform write for some reason.
527527
*/
528-
void BLERemoteCharacteristic::writeValue(std::string newValue, bool response) {
529-
writeValue((uint8_t*)newValue.c_str(), strlen(newValue.c_str()), response);
528+
bool BLERemoteCharacteristic::writeValue(std::string newValue, bool response) {
529+
return writeValue((uint8_t*)newValue.c_str(), strlen(newValue.c_str()), response);
530530
} // writeValue
531531

532532

@@ -536,10 +536,10 @@ void BLERemoteCharacteristic::writeValue(std::string newValue, bool response) {
536536
* This is a convenience function. Many BLE characteristics are a single byte of data.
537537
* @param [in] newValue The new byte value to write.
538538
* @param [in] response Whether we require a response from the write.
539-
* @return N/A.
539+
* @return false if not connected or cant perform write for some reason.
540540
*/
541-
void BLERemoteCharacteristic::writeValue(uint8_t newValue, bool response) {
542-
writeValue(&newValue, 1, response);
541+
bool BLERemoteCharacteristic::writeValue(uint8_t newValue, bool response) {
542+
return writeValue(&newValue, 1, response);
543543
} // writeValue
544544

545545

@@ -548,15 +548,16 @@ void BLERemoteCharacteristic::writeValue(uint8_t newValue, bool response) {
548548
* @param [in] data A pointer to a data buffer.
549549
* @param [in] length The length of the data in the data buffer.
550550
* @param [in] response Whether we require a response from the write.
551+
* @return false if not connected or cant perform write for some reason.
551552
*/
552-
void BLERemoteCharacteristic::writeValue(uint8_t* data, size_t length, bool response) {
553+
bool BLERemoteCharacteristic::writeValue(uint8_t* data, size_t length, bool response) {
553554
// writeValue(std::string((char*)data, length), response);
554555
ESP_LOGD(LOG_TAG, ">> writeValue(), length: %d", length);
555556

556557
// Check to see that we are connected.
557558
if (!getRemoteService()->getClient()->isConnected()) {
558559
ESP_LOGE(LOG_TAG, "Disconnected");
559-
throw BLEDisconnectedException();
560+
return false;
560561
}
561562

562563
m_semaphoreWriteCharEvt.take("writeValue");
@@ -573,12 +574,13 @@ void BLERemoteCharacteristic::writeValue(uint8_t* data, size_t length, bool resp
573574

574575
if (errRc != ESP_OK) {
575576
ESP_LOGE(LOG_TAG, "esp_ble_gattc_write_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
576-
return;
577+
return false;
577578
}
578579

579580
m_semaphoreWriteCharEvt.wait("writeValue");
580581

581582
ESP_LOGD(LOG_TAG, "<< writeValue");
583+
return true;
582584
} // writeValue
583585

584586
/**

0 commit comments

Comments
 (0)