Skip to content

Commit 6c9e42a

Browse files
authored
Merge pull request #413 from ogatatsu/fix_discovery
Fix discover characteristic.
2 parents 3c3659e + 6f1acc4 commit 6c9e42a

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

libraries/Bluefruit52Lib/src/BLEClientCharacteristic.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ bool BLEClientCharacteristic::_discoverDescriptor(uint16_t conn_handle, ble_gatt
155155
{
156156
LOG_LV2("DISC", "Found CCDD: handle = %d", disc_rsp.descs[i].handle);
157157
_cccd_handle = disc_rsp.descs[i].handle;
158+
159+
break;
158160
}
159161
}
160162

libraries/Bluefruit52Lib/src/BLEDiscovery.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLEClientChar
134134
{
135135
for (uint8_t i=0; i<count; i++)
136136
{
137+
if ( chr[i]->discovered() )
138+
continue;
139+
137140
if ( chr[i]->uuid == disc_chr->chars[d].uuid )
138141
{
139142
LOG_LV2("DISC", "[CHR] Found 0x%04X, handle = %d\n-----------------", disc_chr->chars[d].uuid.uuid, disc_chr->chars[d].handle_value);

libraries/Bluefruit52Lib/src/BLEGatt.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,20 +184,20 @@ void BLEGatt::_eventHandler(ble_evt_t* evt)
184184
if ( evt_id == BLE_GAP_EVT_DISCONNECTED )
185185
{
186186
// Client
187-
for(uint8_t i=0; i<_client.svc_count; i++)
187+
for(uint8_t i=0; i<_client.chr_count; i++)
188188
{
189-
if ( evt_conn_hdl == _client.svc_list[i]->_conn_hdl)
189+
if ( evt_conn_hdl == _client.chr_list[i]->connHandle() )
190190
{
191-
_client.svc_list[i]->disconnect();
191+
_client.chr_list[i]->disconnect();
192192
}
193193
}
194194

195195
// TODO merge to above loop
196-
for(uint8_t i=0; i<_client.chr_count; i++)
196+
for(uint8_t i=0; i<_client.svc_count; i++)
197197
{
198-
if ( evt_conn_hdl == _client.chr_list[i]->connHandle() )
198+
if ( evt_conn_hdl == _client.svc_list[i]->_conn_hdl)
199199
{
200-
_client.chr_list[i]->disconnect();
200+
_client.svc_list[i]->disconnect();
201201
}
202202
}
203203
}

0 commit comments

Comments
 (0)