summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2019-08-07 11:10:21 -0400
committerDan Halbert <halbert@halwitz.org>2019-08-07 11:10:21 -0400
commitd047b73a9cd0f17f9e11d60f3004ada473b2c803 (patch)
treef4402588a40ea8e8ebfd78aa9b1fec0361caca3f
parentd74c8b9425d38fe2dce56e044b128ab5693f5f06 (diff)
fix newly-introduced bugs; UART client/server working again
-rw-r--r--ports/nrf/common-hal/bleio/Service.c12
-rw-r--r--ports/nrf/common-hal/bleio/__init__.c5
-rw-r--r--shared-bindings/bleio/Characteristic.c12
-rw-r--r--shared-bindings/bleio/__init__.c2
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 6d2d9d74f..0ac0107f5 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 9879a9ff4..d09b6f5af 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 45bec6c28..4adc897eb 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 0009cf113..05be48ddc 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) },