@@ -88,9 +88,9 @@ bool BLEDiscovery::_discoverService(uint16_t conn_handle, BLEClientService& svc,
88
88
if ( (disc_svc.count ) && (svc.uuid == disc_svc.services [0 ].uuid ) )
89
89
{
90
90
_hdl_range = disc_svc.services [0 ].handle_range ;
91
- svc.setHandleRange (_hdl_range. start_handle , _hdl_range. end_handle );
91
+ svc.setHandleRange (_hdl_range);
92
92
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 );
94
94
95
95
// increase for next discovery
96
96
_hdl_range.start_handle ++;
@@ -102,11 +102,14 @@ bool BLEDiscovery::_discoverService(uint16_t conn_handle, BLEClientService& svc,
102
102
103
103
uint8_t BLEDiscovery::discoverCharacteristic (uint16_t conn_handle, BLEClientCharacteristic* chr[], uint8_t count)
104
104
{
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 };
106
107
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 );
108
109
ble_gattc_evt_char_disc_rsp_t * disc_chr = (ble_gattc_evt_char_disc_rsp_t *) rtos_malloc ( bufsize );
109
110
111
+ uint8_t found = 0 ;
112
+
110
113
while ( found < count )
111
114
{
112
115
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
129
132
{
130
133
if ( chr[i]->uuid == disc_chr->chars [d].uuid )
131
134
{
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 );
133
136
134
137
// characteristic assign overload
135
138
chr[i]->assign (&disc_chr->chars [d]);
0 commit comments