diff options
| author | Dan Halbert <halbert@halwitz.org> | 2019-07-16 19:53:36 -0400 |
|---|---|---|
| committer | Dan Halbert <halbert@halwitz.org> | 2019-07-16 19:53:36 -0400 |
| commit | 364ee62d108bbdc1d4da8bb646a9332a68964b76 (patch) | |
| tree | a35823d7f86e9c422f280823df71b960976ab242 /shared-bindings/bleio | |
| parent | cb99546ea569bd91421e7ee0884c2756387a12d3 (diff) | |
Address review comments.
Diffstat (limited to 'shared-bindings/bleio')
| -rw-r--r-- | shared-bindings/bleio/Address.c | 54 | ||||
| -rw-r--r-- | shared-bindings/bleio/Central.c | 19 | ||||
| -rw-r--r-- | shared-bindings/bleio/Characteristic.c | 6 | ||||
| -rw-r--r-- | shared-bindings/bleio/Descriptor.c | 6 | ||||
| -rw-r--r-- | shared-bindings/bleio/Peripheral.c | 1 | ||||
| -rw-r--r-- | shared-bindings/bleio/ScanEntry.c | 1 | ||||
| -rw-r--r-- | shared-bindings/bleio/Scanner.c | 8 | ||||
| -rw-r--r-- | shared-bindings/bleio/Scanner.h | 3 | ||||
| -rw-r--r-- | shared-bindings/bleio/Service.c | 6 |
9 files changed, 59 insertions, 45 deletions
diff --git a/shared-bindings/bleio/Address.c b/shared-bindings/bleio/Address.c index cfad8fc11..37f01042c 100644 --- a/shared-bindings/bleio/Address.c +++ b/shared-bindings/bleio/Address.c @@ -48,13 +48,9 @@ //| The value itself can be one of: //| //| :param buf address: The address value to encapsulate. A buffer object (bytearray, bytes) of 6 bytes. -//| :param int address_type: one of these integers: -//| - ``bleio.Address.PUBLIC`` = 0 -//| - ``bleio.Address.RANDOM_STATIC`` = 1 -//| - ``bleio.Address.RANDOM_PRIVATE_RESOLVABLE`` = 2 -//| - ``bleio.Address.RANDOM_PRIVATE_NON_RESOLVABLE`` = 3 +//| :param int address_type: one of the integer values: `PUBLIC`, `RANDOM_STATIC`, +//| `RANDOM_PRIVATE_RESOLVABLE`, or `RANDOM_PRIVATE_NON_RESOLVABLE`. //| - STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_address, ARG_address_type }; static const mp_arg_t allowed_args[] = { @@ -105,12 +101,9 @@ const mp_obj_property_t bleio_address_address_bytes_obj = { //| .. attribute:: type //| -//| The address type (read-only). One of these integers: -//| -//| - ``bleio.Address.PUBLIC`` = 0 -//| - ``bleio.Address.RANDOM_STATIC`` = 1 -//| - ``bleio.Address.RANDOM_PRIVATE_RESOLVABLE`` = 2 -//| - ``bleio.Address.RANDOM_PRIVATE_NON_RESOLVABLE`` = 3 +//| The address type (read-only). +//| One of the integer values: `PUBLIC`, `RANDOM_STATIC`, +//| `RANDOM_PRIVATE_RESOLVABLE`, or `RANDOM_PRIVATE_NON_RESOLVABLE`. //| STATIC mp_obj_t bleio_address_get_type(mp_obj_t self_in) { bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -154,16 +147,37 @@ STATIC mp_obj_t bleio_address_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_o STATIC void bleio_address_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { bleio_address_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_obj_t address_bytes = common_hal_bleio_address_get_address_bytes(self); - - mp_buffer_info_t buf_info; - mp_get_buffer_raise(address_bytes, &buf_info, MP_BUFFER_READ); - const uint8_t *buf = (uint8_t *) buf_info.buf; - mp_printf(print, - "%02x:%02x:%02x:%02x:%02x:%02x", - buf[5], buf[4], buf[3], buf[2], buf[1], buf[0]); + if (kind == PRINT_STR) { + mp_buffer_info_t buf_info; + mp_obj_t address_bytes = common_hal_bleio_address_get_address_bytes(self); + mp_get_buffer_raise(address_bytes, &buf_info, MP_BUFFER_READ); + + const uint8_t *buf = (uint8_t *) buf_info.buf; + mp_printf(print, + "%02x:%02x:%02x:%02x:%02x:%02x", + buf[5], buf[4], buf[3], buf[2], buf[1], buf[0]); + } else { + mp_printf(print, "<Address>"); + } } +//| .. data:: PUBLIC +//| +//| A publicly known address, with a company ID (high 24 bits)and company-assigned part (low 24 bits). +//| +//| .. data:: RANDOM_STATIC +//| +//| A randomly generated address that does not change often. It may never change or may change after +//| a power cycle. +//| +//| .. data:: RANDOM_PRIVATE_RESOLVABLE +//| +//| An address that is usable when the peer knows the other device's secret Identity Resolving Key (IRK). +//| +//| .. data:: RANDOM_PRIVATE_NON_RESOLVABLE +//| +//| A randomly generated address that changes on every connection. +//| STATIC const mp_rom_map_elem_t bleio_address_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_address_bytes), MP_ROM_PTR(&bleio_address_address_bytes_obj) }, { MP_ROM_QSTR(MP_QSTR_type), MP_ROM_PTR(&bleio_address_type_obj) }, diff --git a/shared-bindings/bleio/Central.c b/shared-bindings/bleio/Central.c index a21f711af..fc00bce5c 100644 --- a/shared-bindings/bleio/Central.c +++ b/shared-bindings/bleio/Central.c @@ -56,7 +56,7 @@ //| //| my_entry = None //| for entry in entries: -//| if entry.name is not None and entry.name == 'MyCentral': +//| if entry.name is not None and entry.name == 'MyPeripheral': //| my_entry = entry //| break //| @@ -86,13 +86,13 @@ STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, //| //| :param bleio.Address address: The address of the peripheral to connect to //| :param float/int timeout: Try to connect for timeout seconds. -//| :param iterable service_uuids: a collection of :py:class:~`UUID` objects for the services +//| :param iterable service_uuids_whitelist: an iterable of :py:class:~`UUID` objects for the services //| provided by the peripheral that you want to use. //| The peripheral may provide more services, but services not listed are ignored. //| If a service in service_uuids is not found during discovery, it will not //| appear in `remote_services`. //| -//| If service_uuids is None, then all services will undergo discovery, which can be slow. +//| If service_uuids_whitelist is None, then all services will undergo discovery, which can be slow. //| //| If the service UUID is 128-bit, or its characteristic UUID's are 128-bit, you //| you must have already created a :py:class:~`UUID` object for that UUID in order for the @@ -101,11 +101,11 @@ STATIC mp_obj_t bleio_central_make_new(const mp_obj_type_t *type, size_t n_args, STATIC mp_obj_t bleio_central_connect(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { bleio_central_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - enum { ARG_address, ARG_timeout, ARG_service_uuids }; + enum { ARG_address, ARG_timeout, ARG_service_uuids_whitelist }; static const mp_arg_t allowed_args[] = { { MP_QSTR_address, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_timeout, MP_ARG_REQUIRED | MP_ARG_OBJ }, - { MP_QSTR_service_uuids, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, + { MP_QSTR_service_uuids_whitelist, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; @@ -119,7 +119,7 @@ STATIC mp_obj_t bleio_central_connect(mp_uint_t n_args, const mp_obj_t *pos_args mp_float_t timeout = mp_obj_get_float(args[ARG_timeout].u_obj); // common_hal_bleio_central_connect() will validate that services is an iterable or None. - common_hal_bleio_central_connect(self, address, timeout, args[ARG_service_uuids].u_obj); + common_hal_bleio_central_connect(self, address, timeout, args[ARG_service_uuids_whitelist].u_obj); return mp_const_none; } @@ -160,12 +160,15 @@ const mp_obj_property_t bleio_central_connected_obj = { //| .. attribute:: remote_services (read-only) //| -//| Empty until connected, then a list of services provided by the remote peripheral. +//| A tuple of services provided by the remote peripheral. +//| If the Central is not connected, an empty tuple will be returned. //| STATIC mp_obj_t bleio_central_get_remote_services(mp_obj_t self_in) { bleio_central_obj_t *self = MP_OBJ_TO_PTR(self_in); - return MP_OBJ_FROM_PTR(common_hal_bleio_central_get_remote_services(self)); + // Return list as a tuple so user won't be able to change it. + mp_obj_list_t *service_list = common_hal_bleio_central_get_remote_services(self); + return mp_obj_new_tuple(service_list->len, service_list->items); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_central_get_remote_services_obj, bleio_central_get_remote_services); diff --git a/shared-bindings/bleio/Characteristic.c b/shared-bindings/bleio/Characteristic.c index 0d5f8f79a..3bf0476ab 100644 --- a/shared-bindings/bleio/Characteristic.c +++ b/shared-bindings/bleio/Characteristic.c @@ -316,13 +316,13 @@ STATIC MP_DEFINE_CONST_DICT(bleio_characteristic_locals_dict, bleio_characterist STATIC void bleio_characteristic_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_printf(print, "Characteristic("); if (self->uuid) { + mp_printf(print, "Characteristic("); bleio_uuid_print(print, MP_OBJ_FROM_PTR(self->uuid), kind); + mp_printf(print, ")"); } else { - mp_printf(print, "Unregistered uUID"); + mp_printf(print, "<Characteristic with Unregistered UUID>"); } - mp_printf(print, ")"); } const mp_obj_type_t bleio_characteristic_type = { diff --git a/shared-bindings/bleio/Descriptor.c b/shared-bindings/bleio/Descriptor.c index f39283892..f2e5aa01d 100644 --- a/shared-bindings/bleio/Descriptor.c +++ b/shared-bindings/bleio/Descriptor.c @@ -162,13 +162,13 @@ STATIC MP_DEFINE_CONST_DICT(bleio_descriptor_locals_dict, bleio_descriptor_local STATIC void bleio_descriptor_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { bleio_descriptor_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_printf(print, "Descriptor("); if (self->uuid) { + mp_printf(print, "Descriptor("); bleio_uuid_print(print, MP_OBJ_FROM_PTR(self->uuid), kind); + mp_printf(print, ")"); } else { - mp_printf(print, "Unregistered uUID"); + mp_printf(print, "<Descriptor with Unregistered UUID>"); } - mp_printf(print, ")"); } const mp_obj_type_t bleio_descriptor_type = { diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c index b8d4c3975..1302c9652 100644 --- a/shared-bindings/bleio/Peripheral.c +++ b/shared-bindings/bleio/Peripheral.c @@ -63,6 +63,7 @@ static const char default_name[] = "CIRCUITPY"; //| Usage:: //| //| import bleio +//| from adafruit_ble.advertising import ServerAdvertisement //| //| # Create a Characteristic. //| chara = bleio.Characteristic(bleio.UUID(0x2919), read=True, notify=True) diff --git a/shared-bindings/bleio/ScanEntry.c b/shared-bindings/bleio/ScanEntry.c index b7798175c..6eb02c716 100644 --- a/shared-bindings/bleio/ScanEntry.c +++ b/shared-bindings/bleio/ScanEntry.c @@ -32,7 +32,6 @@ #include "shared-bindings/bleio/Address.h" #include "shared-bindings/bleio/ScanEntry.h" #include "shared-bindings/bleio/UUID.h" -#include "shared-module/bleio/AdvertisementData.h" #include "shared-module/bleio/ScanEntry.h" //| .. currentmodule:: bleio diff --git a/shared-bindings/bleio/Scanner.c b/shared-bindings/bleio/Scanner.c index 79ab34931..712425c25 100644 --- a/shared-bindings/bleio/Scanner.c +++ b/shared-bindings/bleio/Scanner.c @@ -75,8 +75,8 @@ STATIC mp_obj_t bleio_scanner_make_new(const mp_obj_type_t *type, size_t n_args, //| Must be in the range 0.0025 - 40.959375 seconds. //| :param float window: the duration (in seconds) to scan a single BLE channel. //| window must be <= interval. -//| :returns: advertising packets found -//| :rtype: list of :py:class:`bleio.ScanEntry` +//| :returns: an iterable of `bleio.ScanEntry` objects +//| :rtype: iterable //| STATIC mp_obj_t bleio_scanner_scan(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_timeout, ARG_interval, ARG_window }; @@ -110,9 +110,7 @@ STATIC mp_obj_t bleio_scanner_scan(size_t n_args, const mp_obj_t *pos_args, mp_m mp_raise_ValueError(translate("window must be <= interval")); } - common_hal_bleio_scanner_scan(self, timeout, interval, window); - - return common_hal_bleio_scanner_get_scan_entries(self); + return common_hal_bleio_scanner_scan(self, timeout, interval, window); } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(bleio_scanner_scan_obj, 2, bleio_scanner_scan); diff --git a/shared-bindings/bleio/Scanner.h b/shared-bindings/bleio/Scanner.h index 1bbab78f4..3a0ce7eae 100644 --- a/shared-bindings/bleio/Scanner.h +++ b/shared-bindings/bleio/Scanner.h @@ -34,8 +34,7 @@ extern const mp_obj_type_t bleio_scanner_type; extern void common_hal_bleio_scanner_construct(bleio_scanner_obj_t *self); -extern void common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window); +extern mp_obj_t common_hal_bleio_scanner_scan(bleio_scanner_obj_t *self, mp_float_t timeout, mp_float_t interval, mp_float_t window); extern void common_hal_bleio_scanner_stop(bleio_scanner_obj_t *self); -extern mp_obj_t common_hal_bleio_scanner_get_scan_entries(bleio_scanner_obj_t *self); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANNER_H diff --git a/shared-bindings/bleio/Service.c b/shared-bindings/bleio/Service.c index af215c6a5..db0606991 100644 --- a/shared-bindings/bleio/Service.c +++ b/shared-bindings/bleio/Service.c @@ -166,13 +166,13 @@ STATIC MP_DEFINE_CONST_DICT(bleio_service_locals_dict, bleio_service_locals_dict STATIC void bleio_service_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { bleio_service_obj_t *self = MP_OBJ_TO_PTR(self_in); - mp_printf(print, "Service("); if (self->uuid) { + mp_printf(print, "Service("); bleio_uuid_print(print, MP_OBJ_FROM_PTR(self->uuid), kind); + mp_printf(print, ")"); } else { - mp_printf(print, "unregistered UUID"); + mp_printf(print, "<Service with unregistered UUID>"); } - mp_printf(print, ")"); } const mp_obj_type_t bleio_service_type = { |
