nrf5/modules/ubluepy: Continue characteristic discovery until nothing more is found during connect proceedure.

This commit is contained in:
Glenn Ruben Bakke 2017-05-14 18:04:27 +02:00 committed by glennrub
parent 653f4a86d5
commit 78c0821216
1 changed files with 22 additions and 9 deletions

View File

@ -402,7 +402,7 @@ STATIC mp_obj_t peripheral_connect(mp_uint_t n_args, const mp_obj_t *pos_args, m
service_disc_retval = ble_drv_discover_services(self,
self->conn_handle,
p_service->end_handle,
p_service->end_handle + 1,
disc_add_service);
}
@ -413,15 +413,28 @@ STATIC mp_obj_t peripheral_connect(mp_uint_t n_args, const mp_obj_t *pos_args, m
for (uint16_t s = 0; s < num_services; s++) {
ubluepy_service_obj_t * p_service = (ubluepy_service_obj_t *)services[s];
bool char_disc_retval = ble_drv_discover_characteristic(p_service,
self->conn_handle,
p_service->start_handle,
p_service->end_handle,
disc_add_char);
// continue discovery of characteristics ...
while (char_disc_retval) {
mp_obj_t * characteristics = NULL;
mp_uint_t num_chars;
mp_obj_get_array(p_service->char_list, &num_chars, &characteristics);
bool retval = ble_drv_discover_characteristic(p_service,
self->conn_handle,
p_service->start_handle,
p_service->end_handle,
disc_add_char);
if (retval != true) {
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError,
"Error during characteristic discovery"));
ubluepy_characteristic_obj_t * p_char = (ubluepy_characteristic_obj_t *)characteristics[num_chars - 1];
uint16_t next_handle = p_char->handle + 1;
if ((next_handle) < p_service->end_handle) {
char_disc_retval = ble_drv_discover_characteristic(p_service,
self->conn_handle,
next_handle,
p_service->end_handle,
disc_add_char);
} else {
break;
}
}
}