From 370c20ff6c3a6c362c140dacb6c31200e877e923 Mon Sep 17 00:00:00 2001 From: Glenn Ruben Bakke Date: Sat, 13 May 2017 18:10:33 +0200 Subject: [PATCH] nrf5/modules/ubluepy: Continue primary service discovery until nothing more is found in connect proceedure. --- nrf5/modules/ubluepy/ubluepy_peripheral.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/nrf5/modules/ubluepy/ubluepy_peripheral.c b/nrf5/modules/ubluepy/ubluepy_peripheral.c index ac1584d044..a68e46f4a6 100644 --- a/nrf5/modules/ubluepy/ubluepy_peripheral.c +++ b/nrf5/modules/ubluepy/ubluepy_peripheral.c @@ -389,10 +389,21 @@ STATIC mp_obj_t peripheral_connect(mp_uint_t n_args, const mp_obj_t *pos_args, m ble_drv_gattc_event_handler_set(MP_OBJ_FROM_PTR(self), gattc_event_handler); - bool retval = ble_drv_discover_services(self, self->conn_handle, disc_add_service); - if (retval != true) { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, - "Error during service discovery")); + bool service_disc_retval = ble_drv_discover_services(self, self->conn_handle, 0x0001, disc_add_service); + + // continue discovery of primary services ... + while (service_disc_retval) { + // locate the last added service + mp_obj_t * services = NULL; + mp_uint_t num_services; + mp_obj_get_array(self->service_list, &num_services, &services); + + ubluepy_service_obj_t * p_service = (ubluepy_service_obj_t *)services[num_services - 1]; + + service_disc_retval = ble_drv_discover_services(self, + self->conn_handle, + p_service->end_handle, + disc_add_service); } // For each service perform a characteristic discovery