From d047b73a9cd0f17f9e11d60f3004ada473b2c803 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 7 Aug 2019 11:10:21 -0400 Subject: [PATCH] fix newly-introduced bugs; UART client/server working again --- ports/nrf/common-hal/bleio/Service.c | 12 ++++++------ ports/nrf/common-hal/bleio/__init__.c | 5 ++--- shared-bindings/bleio/Characteristic.c | 12 ++++++------ shared-bindings/bleio/__init__.c | 2 ++ 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/ports/nrf/common-hal/bleio/Service.c b/ports/nrf/common-hal/bleio/Service.c index 6d2d9d74f8..0ac0107f55 100644 --- a/ports/nrf/common-hal/bleio/Service.c +++ b/ports/nrf/common-hal/bleio/Service.c @@ -73,12 +73,12 @@ void common_hal_bleio_service_add_all_characteristics(bleio_service_obj_t *self) MP_OBJ_TO_PTR(self->characteristic_list->items[characteristic_idx]); ble_gatts_char_md_t char_md = { - .char_props.broadcast = (bool) characteristic->props & CHAR_PROP_BROADCAST, - .char_props.read = (bool) characteristic->props & CHAR_PROP_READ, - .char_props.write_wo_resp = (bool) characteristic->props & CHAR_PROP_WRITE_NO_RESPONSE, - .char_props.write = (bool) characteristic->props & CHAR_PROP_WRITE, - .char_props.notify = (bool) characteristic->props & CHAR_PROP_NOTIFY, - .char_props.indicate = (bool) characteristic->props & CHAR_PROP_INDICATE, + .char_props.broadcast = (characteristic->props & CHAR_PROP_BROADCAST) ? 1 : 0, + .char_props.read = (characteristic->props & CHAR_PROP_READ) ? 1 : 0, + .char_props.write_wo_resp = (characteristic->props & CHAR_PROP_WRITE_NO_RESPONSE) ? 1 : 0, + .char_props.write = (characteristic->props & CHAR_PROP_WRITE) ? 1 : 0, + .char_props.notify = (characteristic->props & CHAR_PROP_NOTIFY) ? 1 : 0, + .char_props.indicate = (characteristic->props & CHAR_PROP_INDICATE) ? 1 : 0, }; ble_gatts_attr_md_t cccd_md = { diff --git a/ports/nrf/common-hal/bleio/__init__.c b/ports/nrf/common-hal/bleio/__init__.c index 9879a9ff43..d09b6f5aff 100644 --- a/ports/nrf/common-hal/bleio/__init__.c +++ b/ports/nrf/common-hal/bleio/__init__.c @@ -195,8 +195,6 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, mp_ob bleio_characteristic_obj_t *characteristic = m_new_obj(bleio_characteristic_obj_t); characteristic->base.type = &bleio_characteristic_type; - characteristic->descriptor_list = mp_obj_new_list(0, NULL); - bleio_uuid_obj_t *uuid = NULL; if (gattc_char->uuid.type != BLE_UUID_TYPE_UNKNOWN) { @@ -219,7 +217,8 @@ STATIC void on_char_discovery_rsp(ble_gattc_evt_char_disc_rsp_t *response, mp_ob (gattc_char->char_props.write_wo_resp ? CHAR_PROP_WRITE_NO_RESPONSE : 0); // Call common_hal_bleio_characteristic_construct() to initalize some fields and set up evt handler. - common_hal_bleio_characteristic_construct(characteristic, uuid, props, SEC_MODE_OPEN, SEC_MODE_OPEN, mp_const_empty_tuple); + common_hal_bleio_characteristic_construct( + characteristic, uuid, props, SEC_MODE_OPEN, SEC_MODE_OPEN, mp_obj_new_list(0, NULL)); characteristic->handle = gattc_char->handle_value; characteristic->service = m_char_discovery_service; diff --git a/shared-bindings/bleio/Characteristic.c b/shared-bindings/bleio/Characteristic.c index 45bec6c28d..4adc897ebe 100644 --- a/shared-bindings/bleio/Characteristic.c +++ b/shared-bindings/bleio/Characteristic.c @@ -96,16 +96,16 @@ STATIC mp_obj_t bleio_characteristic_make_new(const mp_obj_type_t *type, size_t bleio_characteristic_obj_t *self = m_new_obj(bleio_characteristic_obj_t); self->base.type = &bleio_characteristic_type; - // If descriptors is not an iterable, an exception will be thrown. - mp_obj_iter_buf_t iter_buf; - mp_obj_t iterable = mp_getiter(args[ARG_descriptors].u_obj, &iter_buf); - -// Copy the descriptors list and validate its items. + // Copy the descriptors list and validate its items. mp_obj_t desc_list_obj = mp_obj_new_list(0, NULL); mp_obj_list_t *desc_list = MP_OBJ_TO_PTR(desc_list_obj); + // If descriptors is not an iterable, an exception will be thrown. + mp_obj_iter_buf_t iter_buf; + mp_obj_t descriptors_iter = mp_getiter(descriptors, &iter_buf); + mp_obj_t descriptor_obj; - while ((descriptor_obj = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { + while ((descriptor_obj = mp_iternext(descriptors_iter)) != MP_OBJ_STOP_ITERATION) { if (!MP_OBJ_IS_TYPE(descriptor_obj, &bleio_descriptor_type)) { mp_raise_ValueError(translate("descriptors includes an object that is not a Descriptors")); } diff --git a/shared-bindings/bleio/__init__.c b/shared-bindings/bleio/__init__.c index 0009cf1135..05be48ddc7 100644 --- a/shared-bindings/bleio/__init__.c +++ b/shared-bindings/bleio/__init__.c @@ -28,6 +28,7 @@ #include "shared-bindings/bleio/__init__.h" #include "shared-bindings/bleio/Address.h" +#include "shared-bindings/bleio/Attribute.h" #include "shared-bindings/bleio/Central.h" #include "shared-bindings/bleio/Characteristic.h" #include "shared-bindings/bleio/CharacteristicBuffer.h" @@ -80,6 +81,7 @@ STATIC const mp_rom_map_elem_t bleio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_bleio) }, { MP_ROM_QSTR(MP_QSTR_Address), MP_ROM_PTR(&bleio_address_type) }, + { MP_ROM_QSTR(MP_QSTR_Attribute), MP_ROM_PTR(&bleio_attribute_type) }, { MP_ROM_QSTR(MP_QSTR_Central), MP_ROM_PTR(&bleio_central_type) }, { MP_ROM_QSTR(MP_QSTR_Characteristic), MP_ROM_PTR(&bleio_characteristic_type) }, { MP_ROM_QSTR(MP_QSTR_CharacteristicBuffer), MP_ROM_PTR(&bleio_characteristic_buffer_type) },