nrf5/modules/ubluepy: Return BLE peer address as string instead of bytearray. Updated struct in modubluepy.h to use a mp_obj_t to hold a string instead of a fixed 6-byte array. Stripped down ScanEntry print out to only contain class name, peer address available through addr attribute.

This commit is contained in:
Glenn Ruben Bakke 2017-03-22 23:18:41 +01:00
parent 23163154b9
commit 8a884de7b9
3 changed files with 14 additions and 12 deletions

View File

@ -152,7 +152,7 @@ typedef struct _ubluepy_scanner_obj_t {
typedef struct _ubluepy_scan_entry_obj_t {
mp_obj_base_t base;
uint8_t addr[6];
mp_obj_t addr;
uint8_t addr_type;
bool connectable;
int8_t rssi;

View File

@ -37,10 +37,7 @@
STATIC void ubluepy_scan_entry_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) {
ubluepy_scan_entry_obj_t * self = (ubluepy_scan_entry_obj_t *)o;
(void)self;
mp_printf(print, "ScanEntry(addr: "HEX2_FMT":"HEX2_FMT":"HEX2_FMT":" \
HEX2_FMT":"HEX2_FMT":"HEX2_FMT")",
self->addr[0], self->addr[1], self->addr[2],
self->addr[3], self->addr[4], self->addr[5]);
mp_printf(print, "ScanEntry");
}
STATIC void ubluepy_scan_entry_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
@ -50,7 +47,7 @@ STATIC void ubluepy_scan_entry_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest)
}
ubluepy_scan_entry_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (attr == MP_QSTR_addr) {
dest[0] = mp_obj_new_bytearray_by_ref(6, self->addr);
dest[0] = self->addr;
} else if (attr == MP_QSTR_addr_type) {
dest[0] = mp_obj_new_int(self->addr_type);
} else if (attr == MP_QSTR_rssi) {

View File

@ -41,12 +41,17 @@ STATIC void adv_event_handler(mp_obj_t self_in, uint16_t event_id, ble_drv_adv_d
ubluepy_scan_entry_obj_t * item = m_new_obj(ubluepy_scan_entry_obj_t);
item->base.type = &ubluepy_scan_entry_type;
item->addr[0] = data->p_peer_addr[5];
item->addr[1] = data->p_peer_addr[4];
item->addr[2] = data->p_peer_addr[3];
item->addr[3] = data->p_peer_addr[2];
item->addr[4] = data->p_peer_addr[1];
item->addr[5] = data->p_peer_addr[0];
vstr_t vstr;
vstr_init(&vstr, 17);
vstr_printf(&vstr, ""HEX2_FMT":"HEX2_FMT":"HEX2_FMT":" \
HEX2_FMT":"HEX2_FMT":"HEX2_FMT"",
data->p_peer_addr[5], data->p_peer_addr[4], data->p_peer_addr[3],
data->p_peer_addr[2], data->p_peer_addr[1], data->p_peer_addr[0]);
item->addr = mp_obj_new_str(vstr.buf, vstr.len, false);
vstr_clear(&vstr);
item->addr_type = data->addr_type;
item->rssi = data->rssi;