fix newly-introduced bugs; UART client/server working again

This commit is contained in:
Dan Halbert 2019-08-07 11:10:21 -04:00
parent d74c8b9425
commit d047b73a9c
4 changed files with 16 additions and 15 deletions

View File

@ -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 = {

View File

@ -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;

View File

@ -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"));
}

View File

@ -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) },