summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2019-06-02 23:21:30 -0400
committerDan Halbert <halbert@halwitz.org>2019-06-02 23:21:30 -0400
commit63ac37946df041519ffa822fde292f3be6d1840c (patch)
treec995e94ad222fd05578a4d707d2d82a1c0db21c0 /shared-bindings
parent12f1d9d30cf6e8c73db2eac5512c332cfde3031f (diff)
1. Remove advertising data construction in C: it's all done in Python now
2. Add scan response capability to advertising.
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/bleio/Broadcaster.c2
-rw-r--r--shared-bindings/bleio/Peripheral.c26
-rw-r--r--shared-bindings/bleio/Peripheral.h2
3 files changed, 19 insertions, 11 deletions
diff --git a/shared-bindings/bleio/Broadcaster.c b/shared-bindings/bleio/Broadcaster.c
index 209e66490..294f1a83a 100644
--- a/shared-bindings/bleio/Broadcaster.c
+++ b/shared-bindings/bleio/Broadcaster.c
@@ -82,7 +82,7 @@ STATIC mp_obj_t bleio_broadcaster_make_new(const mp_obj_type_t *type, size_t n_a
//|
//| Start advertising using the given data packet.
//|
-//| :param buf data: advertising data packet, starting with advertising data flags (0x01)
+//| :param buf data: advertising data packet
//|
STATIC mp_obj_t bleio_broadcaster_start_advertising(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
bleio_broadcaster_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
diff --git a/shared-bindings/bleio/Peripheral.c b/shared-bindings/bleio/Peripheral.c
index 340485f35..960b3723c 100644
--- a/shared-bindings/bleio/Peripheral.c
+++ b/shared-bindings/bleio/Peripheral.c
@@ -68,7 +68,8 @@ static const char default_name[] = "CIRCUITPY";
//|
//| # Create a peripheral and start it up.
//| periph = bleio.Peripheral([service])
-//| periph.start_advertising()
+//| adv = ServerAdvertisement(periph)
+//| periph.start_advertising(adv.advertising_data_bytes, adv.scan_response_bytes)
//|
//| while not periph.connected:
//| # Wait for connection.
@@ -181,33 +182,40 @@ const mp_obj_property_t bleio_peripheral_name_obj = {
(mp_obj_t)&mp_const_none_obj },
};
-//| .. method:: start_advertising(*, connectable=True, data=None)
+//| .. method:: start_advertising(data, *, scan_response=None, connectable=True)
//|
//| Starts advertising the peripheral. The peripheral's name and
//| services are included in the advertisement packets.
//|
+//| :param buf data: advertising data packet bytes
+//| :param buf scan_response: scan response data packet bytes. ``None`` if no scan response is needed.
//| :param bool connectable: If `True` then other devices are allowed to connect to this peripheral.
-//| :param buf data: If `None`, advertise the services passed to this Peripheral when it was created.
-//| If not `None`, then send the bytes in ``data`` as the advertising packet.
+//|
//|
STATIC mp_obj_t bleio_peripheral_start_advertising(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
bleio_peripheral_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]);
- enum { ARG_connectable, ARG_data };
+ enum { ARG_data, ARG_scan_response, ARG_connectable };
static const mp_arg_t allowed_args[] = {
+ { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ },
+ { MP_QSTR_scan_response, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
{ MP_QSTR_connectable, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} },
- { MP_QSTR_data, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} },
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
- mp_buffer_info_t bufinfo = { 0 };
+ mp_buffer_info_t data_bufinfo;
+ mp_get_buffer_raise(args[ARG_data].u_obj, &data_bufinfo, MP_BUFFER_READ);
+
+ // Pass an empty buffer if scan_response not provided.
+ mp_buffer_info_t scan_response_bufinfo = { 0 };
if (args[ARG_data].u_obj != mp_const_none) {
- mp_get_buffer_raise(args[ARG_data].u_obj, &bufinfo, MP_BUFFER_READ);
+ mp_get_buffer_raise(args[ARG_scan_response].u_obj, &scan_response_bufinfo, MP_BUFFER_READ);
}
- common_hal_bleio_peripheral_start_advertising(self, args[ARG_connectable].u_bool, &bufinfo);
+ common_hal_bleio_peripheral_start_advertising(self, args[ARG_connectable].u_bool,
+ &data_bufinfo, &scan_response_bufinfo);
return mp_const_none;
}
diff --git a/shared-bindings/bleio/Peripheral.h b/shared-bindings/bleio/Peripheral.h
index 02a5c1ef8..c09c60088 100644
--- a/shared-bindings/bleio/Peripheral.h
+++ b/shared-bindings/bleio/Peripheral.h
@@ -34,7 +34,7 @@ extern const mp_obj_type_t bleio_peripheral_type;
extern void common_hal_bleio_peripheral_construct(bleio_peripheral_obj_t *self);
extern bool common_hal_bleio_peripheral_get_connected(bleio_peripheral_obj_t *self);
-extern void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *device, bool connectable, mp_buffer_info_t *raw_data);
+extern void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *device, bool connectable, mp_buffer_info_t *advertising_data_bufinfo, mp_buffer_info_t *scan_response_data_bufinfo);
extern void common_hal_bleio_peripheral_stop_advertising(bleio_peripheral_obj_t *device);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_PERIPHERAL_H