From 78c08212163a845b40e39af1755c823019785e52 Mon Sep 17 00:00:00 2001 From: Glenn Ruben Bakke Date: Sun, 14 May 2017 18:04:27 +0200 Subject: [PATCH] nrf5/modules/ubluepy: Continue characteristic discovery until nothing more is found during connect proceedure. --- nrf5/modules/ubluepy/ubluepy_peripheral.c | 31 ++++++++++++++++------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/nrf5/modules/ubluepy/ubluepy_peripheral.c b/nrf5/modules/ubluepy/ubluepy_peripheral.c index a68e46f4a6..19c59a1a63 100644 --- a/nrf5/modules/ubluepy/ubluepy_peripheral.c +++ b/nrf5/modules/ubluepy/ubluepy_peripheral.c @@ -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; + } } }