Skip to content

Commit 8e2c4e4

Browse files
committed
Bugfix/onRead callback not called for non-long read commands.
1 parent d02a89a commit 8e2c4e4

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/NimBLECharacteristic.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,13 @@ int NimBLECharacteristic::handleGapEvent(uint16_t conn_handle, uint16_t attr_han
273273
if(ble_uuid_cmp(uuid, &pCharacteristic->getUUID().getNative()->u) == 0){
274274
switch(ctxt->op) {
275275
case BLE_GATT_ACCESS_OP_READ_CHR: {
276-
// If the packet header is only 8 bytes this is a follow up of a long read
277-
// so we don't want to call the onRead() callback again.
278-
if(ctxt->om->om_pkthdr_len > 8) {
279-
rc = ble_gap_conn_find(conn_handle, &desc);
280-
assert(rc == 0);
276+
rc = ble_gap_conn_find(conn_handle, &desc);
277+
assert(rc == 0);
278+
279+
// If the packet header is only 8 bytes this is a follow up of a long read
280+
// so we don't want to call the onRead() callback again.
281+
if(ctxt->om->om_pkthdr_len > 8 ||
282+
pCharacteristic->m_value.size() <= (ble_att_mtu(desc.conn_handle) - 3)) {
281283
pCharacteristic->m_pCallbacks->onRead(pCharacteristic);
282284
pCharacteristic->m_pCallbacks->onRead(pCharacteristic, &desc);
283285
}

src/NimBLEDescriptor.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ int NimBLEDescriptor::handleGapEvent(uint16_t conn_handle, uint16_t attr_handle,
155155

156156
const ble_uuid_t *uuid;
157157
int rc;
158+
struct ble_gap_conn_desc desc;
158159
NimBLEDescriptor* pDescriptor = (NimBLEDescriptor*)arg;
159160

160161
NIMBLE_LOGD(LOG_TAG, "Descriptor %s %s event", pDescriptor->getUUID().toString().c_str(),
@@ -164,9 +165,13 @@ int NimBLEDescriptor::handleGapEvent(uint16_t conn_handle, uint16_t attr_handle,
164165
if(ble_uuid_cmp(uuid, &pDescriptor->getUUID().getNative()->u) == 0){
165166
switch(ctxt->op) {
166167
case BLE_GATT_ACCESS_OP_READ_DSC: {
167-
// If the packet header is only 8 bytes this is a follow up of a long read
168-
// so we don't want to call the onRead() callback again.
169-
if(ctxt->om->om_pkthdr_len > 8) {
168+
rc = ble_gap_conn_find(conn_handle, &desc);
169+
assert(rc == 0);
170+
171+
// If the packet header is only 8 bytes this is a follow up of a long read
172+
// so we don't want to call the onRead() callback again.
173+
if(ctxt->om->om_pkthdr_len > 8 ||
174+
pDescriptor->m_value.size() <= (ble_att_mtu(desc.conn_handle) - 3)) {
170175
pDescriptor->m_pCallbacks->onRead(pDescriptor);
171176
}
172177

0 commit comments

Comments
 (0)