mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-22 13:10:55 +01:00
Revert 03b22e5
sub/unsub changes, app should specify response.
This commit is contained in:
parent
7d2d73d8fc
commit
d83cd94d5b
4 changed files with 96 additions and 92 deletions
|
@ -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)) {
|
||||||
|
|
|
@ -101,10 +101,11 @@ bool connectToServer() {
|
||||||
if(pRemoteCharacteristic->canRead()) {
|
if(pRemoteCharacteristic->canRead()) {
|
||||||
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);
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue