@@ -88,9 +88,9 @@ bool BLEDiscovery::_discoverService(uint16_t conn_handle, BLEClientService& svc,
8888 if ( (disc_svc.count ) && (svc.uuid == disc_svc.services [0 ].uuid ) )
8989 {
9090 _hdl_range = disc_svc.services [0 ].handle_range ;
91- svc.setHandleRange (_hdl_range. start_handle , _hdl_range. end_handle );
91+ svc.setHandleRange (_hdl_range);
9292
93- LOG_LV2 (Discover, " [SVC] Found 0x%04X, Handle start = %d, end = %d" , disc_svc.services [0 ].uuid .uuid , _hdl_range.start_handle , _hdl_range.end_handle );
93+ LOG_LV2 (Discover, " [SVC] Found 0x%04X, Handle start = %d, end = %d\n ----------------- " , disc_svc.services [0 ].uuid .uuid , _hdl_range.start_handle , _hdl_range.end_handle );
9494
9595 // increase for next discovery
9696 _hdl_range.start_handle ++;
@@ -102,11 +102,14 @@ bool BLEDiscovery::_discoverService(uint16_t conn_handle, BLEClientService& svc,
102102
103103uint8_t BLEDiscovery::discoverCharacteristic (uint16_t conn_handle, BLEClientCharacteristic* chr[], uint8_t count)
104104{
105- uint8_t found = 0 ;
105+ // We could found more characteristic than we looking for. Buffer must be large enough
106+ enum { MAX_DISC_CHARS = 4 };
106107
107- uint16_t bufsize = sizeof (ble_gattc_evt_char_disc_rsp_t ) + (count -1 )*sizeof (ble_gattc_char_t );
108+ uint16_t bufsize = sizeof (ble_gattc_evt_char_disc_rsp_t ) + (MAX_DISC_CHARS -1 )*sizeof (ble_gattc_char_t );
108109 ble_gattc_evt_char_disc_rsp_t * disc_chr = (ble_gattc_evt_char_disc_rsp_t *) rtos_malloc ( bufsize );
109110
111+ uint8_t found = 0 ;
112+
110113 while ( found < count )
111114 {
112115 LOG_LV2 (Discover, " [CHR] Handle start = %d, end = %d" , _hdl_range.start_handle , _hdl_range.end_handle );
@@ -129,7 +132,7 @@ uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLEClientChar
129132 {
130133 if ( chr[i]->uuid == disc_chr->chars [d].uuid )
131134 {
132- LOG_LV2 (Discover, " [CHR] Found 0x%04X, handle = %d" , disc_chr->chars [d].uuid .uuid , disc_chr->chars [d].handle_value );
135+ LOG_LV2 (Discover, " [CHR] Found 0x%04X, handle = %d\n ----------------- " , disc_chr->chars [d].uuid .uuid , disc_chr->chars [d].handle_value );
133136
134137 // characteristic assign overload
135138 chr[i]->assign (&disc_chr->chars [d]);
0 commit comments