summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2019-06-22 22:10:15 -0400
committerDan Halbert <halbert@halwitz.org>2019-06-22 22:10:15 -0400
commit140904ec84ad1900f280c1febaa89a499c42b8c5 (patch)
treed6d686b2056dc99975f66399ad82428f75ee8dcb /shared-bindings
parent4881e1ff55768c027404cc6a1375c43d4c3acf2a (diff)
getting Scanner to work
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/bleio/Address.c53
-rw-r--r--shared-bindings/bleio/Address.h2
-rw-r--r--shared-bindings/bleio/ScanEntry.c19
-rw-r--r--shared-bindings/bleio/ScanEntry.h2
-rw-r--r--shared-bindings/bleio/Scanner.c4
-rw-r--r--shared-bindings/bleio/Scanner.h2
-rw-r--r--shared-bindings/bleio/UUID.c6
7 files changed, 71 insertions, 17 deletions
diff --git a/shared-bindings/bleio/Address.c b/shared-bindings/bleio/Address.c
index 5875cf9bd..0e094c2e3 100644
--- a/shared-bindings/bleio/Address.c
+++ b/shared-bindings/bleio/Address.c
@@ -80,7 +80,7 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args,
mp_raise_ValueError(translate("Address type out of range"));
}
- common_hal_bleio_address_construct(self, buf_info.buf, buf_info.len, address_type);
+ common_hal_bleio_address_construct(self, buf_info.buf, address_type);
return MP_OBJ_FROM_PTR(self);
}
@@ -101,6 +101,13 @@ STATIC mp_obj_t bleio_address_get_address_bytes(mp_obj_t self_in) {
}
MP_DEFINE_CONST_FUN_OBJ_1(bleio_address_get_address_bytes_obj, bleio_address_get_address_bytes);
+const mp_obj_property_t bleio_address_address_bytes_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&bleio_address_get_address_bytes_obj,
+ (mp_obj_t)&mp_const_none_obj,
+ (mp_obj_t)&mp_const_none_obj},
+};
+
//| .. attribute:: type
//|
//| The address type (read-only). One of these integers:
@@ -124,9 +131,47 @@ const mp_obj_property_t bleio_address_type_obj = {
(mp_obj_t)&mp_const_none_obj},
};
+//| .. method:: __eq__(other)
+//|
+//| Two Address objects are equal if their addresses and address types are equal.
+//|
+STATIC mp_obj_t bleio_address_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
+ switch (op) {
+ // Two Addresses are equal if their address bytes and address_type are equal
+ case MP_BINARY_OP_EQUAL:
+ if (MP_OBJ_IS_TYPE(rhs_in, &bleio_address_type)) {
+ bleio_address_obj_t *lhs = MP_OBJ_TO_PTR(lhs_in);
+ bleio_address_obj_t *rhs = MP_OBJ_TO_PTR(rhs_in);
+ return mp_obj_new_bool(
+ mp_obj_equal(common_hal_bleio_address_get_address_bytes(lhs),
+ common_hal_bleio_address_get_address_bytes(rhs)) &&
+ common_hal_bleio_address_get_type(lhs) ==
+ common_hal_bleio_address_get_type(rhs));
+
+ } else {
+ return mp_const_false;
+ }
+
+ default:
+ return MP_OBJ_NULL; // op not supported
+ }
+}
+
+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]);
+}
+
STATIC const mp_rom_map_elem_t bleio_address_locals_dict_table[] = {
- { MP_ROM_QSTR(MP_QSTR_address_bytes), MP_ROM_PTR(&bleio_address_get_address_bytes_obj) },
- { MP_ROM_QSTR(MP_QSTR_type), MP_ROM_PTR(&bleio_address_get_type_obj) },
+ { 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) },
// These match the BLE_GAP_ADDR_TYPES values used by the nRF library.
{ MP_ROM_QSTR(MP_QSTR_PUBLIC), MP_OBJ_NEW_SMALL_INT(0) },
{ MP_ROM_QSTR(MP_QSTR_RANDOM_STATIC), MP_OBJ_NEW_SMALL_INT(1) },
@@ -141,5 +186,7 @@ const mp_obj_type_t bleio_address_type = {
{ &mp_type_type },
.name = MP_QSTR_Address,
.make_new = bleio_address_make_new,
+ .print = bleio_address_print,
+ .binary_op = bleio_address_binary_op,
.locals_dict = (mp_obj_dict_t*)&bleio_address_locals_dict
};
diff --git a/shared-bindings/bleio/Address.h b/shared-bindings/bleio/Address.h
index bff1542cf..5e02ee210 100644
--- a/shared-bindings/bleio/Address.h
+++ b/shared-bindings/bleio/Address.h
@@ -41,7 +41,7 @@
extern const mp_obj_type_t bleio_address_type;
-extern void common_hal_bleio_address_construct(bleio_address_obj_t *self, uint8_t *bytes, size_t bytes_length, uint8_t address_type);
+extern void common_hal_bleio_address_construct(bleio_address_obj_t *self, uint8_t *bytes, uint8_t address_type);
extern mp_obj_t common_hal_bleio_address_get_address_bytes(bleio_address_obj_t *self);
extern uint8_t common_hal_bleio_address_get_type(bleio_address_obj_t *self);
diff --git a/shared-bindings/bleio/ScanEntry.c b/shared-bindings/bleio/ScanEntry.c
index 145d2b023..b7798175c 100644
--- a/shared-bindings/bleio/ScanEntry.c
+++ b/shared-bindings/bleio/ScanEntry.c
@@ -62,19 +62,19 @@ const mp_obj_property_t bleio_scanentry_address_obj = {
(mp_obj_t)&mp_const_none_obj },
};
-//| .. attribute:: raw_data
+//| .. attribute:: advertisement_bytes
//|
//| All the advertisement data present in the packet, returned as a ``bytes`` object. (read-only)
//|
-STATIC mp_obj_t scanentry_get_raw_data(mp_obj_t self_in) {
+STATIC mp_obj_t scanentry_get_advertisement_bytes(mp_obj_t self_in) {
bleio_scanentry_obj_t *self = MP_OBJ_TO_PTR(self_in);
- return common_hal_bleio_scanentry_get_raw_data(self);
+ return common_hal_bleio_scanentry_get_advertisement_bytes(self);
}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanentry_get_raw_data_obj, scanentry_get_raw_data);
+STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_scanentry_get_advertisement_bytes_obj, scanentry_get_advertisement_bytes);
-const mp_obj_property_t bleio_scanentry_raw_data_obj = {
+const mp_obj_property_t bleio_scanentry_advertisement_bytes_obj = {
.base.type = &mp_type_property,
- .proxy = { (mp_obj_t)&bleio_scanentry_get_raw_data_obj,
+ .proxy = { (mp_obj_t)&bleio_scanentry_get_advertisement_bytes_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&mp_const_none_obj },
};
@@ -96,10 +96,11 @@ const mp_obj_property_t bleio_scanentry_rssi_obj = {
(mp_obj_t)&mp_const_none_obj },
};
+
STATIC const mp_rom_map_elem_t bleio_scanentry_locals_dict_table[] = {
- { MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&bleio_scanentry_address_obj) },
- { MP_ROM_QSTR(MP_QSTR_raw_data), MP_ROM_PTR(&bleio_scanentry_raw_data_obj) },
- { MP_ROM_QSTR(MP_QSTR_rssi), MP_ROM_PTR(&bleio_scanentry_rssi_obj) },
+ { MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&bleio_scanentry_address_obj) },
+ { MP_ROM_QSTR(MP_QSTR_advertisement_bytes), MP_ROM_PTR(&bleio_scanentry_advertisement_bytes_obj) },
+ { MP_ROM_QSTR(MP_QSTR_rssi), MP_ROM_PTR(&bleio_scanentry_rssi_obj) },
};
STATIC MP_DEFINE_CONST_DICT(bleio_scanentry_locals_dict, bleio_scanentry_locals_dict_table);
diff --git a/shared-bindings/bleio/ScanEntry.h b/shared-bindings/bleio/ScanEntry.h
index 3a02f2fac..77e93175f 100644
--- a/shared-bindings/bleio/ScanEntry.h
+++ b/shared-bindings/bleio/ScanEntry.h
@@ -35,7 +35,7 @@
extern const mp_obj_type_t bleio_scanentry_type;
mp_obj_t common_hal_bleio_scanentry_get_address(bleio_scanentry_obj_t *self);
-mp_obj_t common_hal_bleio_scanentry_get_raw_data(bleio_scanentry_obj_t *self);
+mp_obj_t common_hal_bleio_scanentry_get_advertisement_bytes(bleio_scanentry_obj_t *self);
mp_int_t common_hal_bleio_scanentry_get_rssi(bleio_scanentry_obj_t *self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_SCANENTRY_H
diff --git a/shared-bindings/bleio/Scanner.c b/shared-bindings/bleio/Scanner.c
index 92f6a2a18..d50f69fc5 100644
--- a/shared-bindings/bleio/Scanner.c
+++ b/shared-bindings/bleio/Scanner.c
@@ -42,7 +42,7 @@
//| :class:`Scanner` -- scan for nearby BLE devices
//| =========================================================
//|
-//| Allows scanning for nearby BLE devices.
+//| Scan for nearby BLE devices.
//|
//| Usage::
//|
@@ -112,7 +112,7 @@ STATIC mp_obj_t bleio_scanner_scan(size_t n_args, const mp_obj_t *pos_args, mp_m
common_hal_bleio_scanner_scan(self, timeout, interval, window);
- return common_hal_bleio_scanner_get_adv_reports(self);
+ return common_hal_bleio_scanner_get_scan_entries(self);
}
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 b9e3ecdee..1bbab78f4 100644
--- a/shared-bindings/bleio/Scanner.h
+++ b/shared-bindings/bleio/Scanner.h
@@ -36,6 +36,6 @@ 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 void common_hal_bleio_scanner_stop(bleio_scanner_obj_t *self);
-extern mp_obj_t common_hal_bleio_scanner_get_adv_reports(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/UUID.c b/shared-bindings/bleio/UUID.c
index 972505058..0db7435f4 100644
--- a/shared-bindings/bleio/UUID.c
+++ b/shared-bindings/bleio/UUID.c
@@ -220,6 +220,12 @@ STATIC mp_obj_t bleio_uuid_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
}
}
+//|
+
+//| .. method:: __eq__(other)
+//|
+//| Two UUID objects are equal if their values match and they are both 128-bit or both 16-bit.
+//|
STATIC mp_obj_t bleio_uuid_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
switch (op) {
// Two UUID's are equal if their uuid16 values and uuid128 references match.