Revert 03b22e5 sub/unsub changes, app should specify response.

This commit is contained in:
h2zero 2022-10-23 19:16:33 -06:00 committed by h2zero
parent 7d2d73d8fc
commit d83cd94d5b
4 changed files with 96 additions and 92 deletions

View file

@ -1,5 +1,5 @@
/** NimBLE_Server Demo: /** NimBLE_Client Demo:
* *
* Demonstrates many of the available features of the NimBLE client library. * Demonstrates many of the available features of the NimBLE client library.
* *
@ -203,9 +203,9 @@ bool connectToServer() {
} }
} }
/** registerForNotify() has been deprecated and replaced with subscribe() / unsubscribe(). /** registerForNotify() has been removed and replaced with subscribe() / unsubscribe().
* Subscribe parameter defaults are: notifications=true, notifyCallback=nullptr, response=false. * Subscribe parameter defaults are: notifications=true, notifyCallback=nullptr, response=true.
* Unsubscribe parameter defaults are: response=false. * Unsubscribe parameter defaults are: response=true.
*/ */
if(pChr->canNotify()) { if(pChr->canNotify()) {
//if(!pChr->registerForNotify(notifyCB)) { //if(!pChr->registerForNotify(notifyCB)) {
@ -267,8 +267,8 @@ bool connectToServer() {
} }
/** registerForNotify() has been deprecated and replaced with subscribe() / unsubscribe(). /** registerForNotify() has been deprecated and replaced with subscribe() / unsubscribe().
* Subscribe parameter defaults are: notifications=true, notifyCallback=nullptr, response=false. * Subscribe parameter defaults are: notifications=true, notifyCallback=nullptr, response=true.
* Unsubscribe parameter defaults are: response=false. * Unsubscribe parameter defaults are: response=true.
*/ */
if(pChr->canNotify()) { if(pChr->canNotify()) {
//if(!pChr->registerForNotify(notifyCB)) { //if(!pChr->registerForNotify(notifyCB)) {

View file

@ -102,9 +102,10 @@ bool connectToServer() {
std::string value = pRemoteCharacteristic->readValue(); std::string value = pRemoteCharacteristic->readValue();
printf("The characteristic value was: %s\n", value.c_str()); printf("The characteristic value was: %s\n", value.c_str());
} }
/** registerForNotify() has been deprecated and replaced with subscribe() / unsubscribe().
* Subscribe parameter defaults are: notifications=true, notifyCallback=nullptr, response=false. /** registerForNotify() has been removed and replaced with subscribe() / unsubscribe().
* Unsubscribe parameter defaults are: response=false. * Subscribe parameter defaults are: notifications=true, notifyCallback=nullptr, response=true.
* Unsubscribe parameter defaults are: response=true.
*/ */
if(pRemoteCharacteristic->canNotify()) { if(pRemoteCharacteristic->canNotify()) {
//pRemoteCharacteristic->registerForNotify(notifyCallback); //pRemoteCharacteristic->registerForNotify(notifyCallback);

View file

@ -564,7 +564,7 @@ int NimBLERemoteCharacteristic::onReadCB(uint16_t conn_handle,
* If NULL is provided then no callback is performed. * If NULL is provided then no callback is performed.
* @return false if writing to the descriptor failed. * @return false if writing to the descriptor failed.
*/ */
bool NimBLERemoteCharacteristic::setNotify(uint16_t val, notify_callback notifyCallback) { bool NimBLERemoteCharacteristic::setNotify(uint16_t val, notify_callback notifyCallback, bool response) {
NIMBLE_LOGD(LOG_TAG, ">> setNotify(): %s, %02x", toString().c_str(), val); NIMBLE_LOGD(LOG_TAG, ">> setNotify(): %s, %02x", toString().c_str(), val);
m_notifyCallback = notifyCallback; m_notifyCallback = notifyCallback;
@ -576,7 +576,8 @@ bool NimBLERemoteCharacteristic::setNotify(uint16_t val, notify_callback notifyC
} }
NIMBLE_LOGD(LOG_TAG, "<< setNotify()"); NIMBLE_LOGD(LOG_TAG, "<< setNotify()");
return desc->writeValue((uint8_t *)&val, 2, true);
return desc->writeValue((uint8_t *)&val, 2, response);
} // setNotify } // setNotify
@ -584,14 +585,15 @@ bool NimBLERemoteCharacteristic::setNotify(uint16_t val, notify_callback notifyC
* @brief Subscribe for notifications or indications. * @brief Subscribe for notifications or indications.
* @param [in] notifications If true, subscribe for notifications, false subscribe for indications. * @param [in] notifications If true, subscribe for notifications, false subscribe for indications.
* @param [in] notifyCallback A callback to be invoked for a notification. * @param [in] notifyCallback A callback to be invoked for a notification.
* @param [in] response If true, require a write response from the descriptor write operation.
* If NULL is provided then no callback is performed. * If NULL is provided then no callback is performed.
* @return false if writing to the descriptor failed. * @return false if writing to the descriptor failed.
*/ */
bool NimBLERemoteCharacteristic::subscribe(bool notifications, notify_callback notifyCallback) { bool NimBLERemoteCharacteristic::subscribe(bool notifications, notify_callback notifyCallback, bool response) {
if(notifications) { if(notifications) {
return setNotify(0x01, notifyCallback); return setNotify(0x01, notifyCallback, response);
} else { } else {
return setNotify(0x02, notifyCallback); return setNotify(0x02, notifyCallback, response);
} }
} // subscribe } // subscribe
@ -601,8 +603,8 @@ bool NimBLERemoteCharacteristic::subscribe(bool notifications, notify_callback n
* @param [in] response bool if true, require a write response from the descriptor write operation. * @param [in] response bool if true, require a write response from the descriptor write operation.
* @return false if writing to the descriptor failed. * @return false if writing to the descriptor failed.
*/ */
bool NimBLERemoteCharacteristic::unsubscribe() { bool NimBLERemoteCharacteristic::unsubscribe(bool response) {
return setNotify(0x00, nullptr); return setNotify(0x00, nullptr, response);
} // unsubscribe } // unsubscribe

View file

@ -66,8 +66,9 @@ public:
NimBLERemoteService* getRemoteService(); NimBLERemoteService* getRemoteService();
NimBLEAttValue getValue(time_t *timestamp = nullptr); NimBLEAttValue getValue(time_t *timestamp = nullptr);
bool subscribe(bool notifications = true, bool subscribe(bool notifications = true,
notify_callback notifyCallback = nullptr); notify_callback notifyCallback = nullptr,
bool unsubscribe(); bool response = true);
bool unsubscribe(bool response = true);
bool writeValue(const uint8_t* data, bool writeValue(const uint8_t* data,
size_t length, size_t length,
bool response = false); bool response = false);
@ -149,7 +150,7 @@ private:
friend class NimBLERemoteDescriptor; friend class NimBLERemoteDescriptor;
// Private member functions // Private member functions
bool setNotify(uint16_t val, notify_callback notifyCallback = nullptr); bool setNotify(uint16_t val, notify_callback notifyCallback = nullptr, bool response = true);
bool retrieveDescriptors(const NimBLEUUID *uuid_filter = nullptr); bool retrieveDescriptors(const NimBLEUUID *uuid_filter = nullptr);
static int onReadCB(uint16_t conn_handle, const struct ble_gatt_error *error, static int onReadCB(uint16_t conn_handle, const struct ble_gatt_error *error,
struct ble_gatt_attr *attr, void *arg); struct ble_gatt_attr *attr, void *arg);