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 { typedef struct _ubluepy_scan_entry_obj_t {
mp_obj_base_t base; mp_obj_base_t base;
uint8_t addr[6]; mp_obj_t addr;
uint8_t addr_type; uint8_t addr_type;
bool connectable; bool connectable;
int8_t rssi; 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) { 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; ubluepy_scan_entry_obj_t * self = (ubluepy_scan_entry_obj_t *)o;
(void)self; (void)self;
mp_printf(print, "ScanEntry(addr: "HEX2_FMT":"HEX2_FMT":"HEX2_FMT":" \ mp_printf(print, "ScanEntry");
HEX2_FMT":"HEX2_FMT":"HEX2_FMT")",
self->addr[0], self->addr[1], self->addr[2],
self->addr[3], self->addr[4], self->addr[5]);
} }
STATIC void ubluepy_scan_entry_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { 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); ubluepy_scan_entry_obj_t *self = MP_OBJ_TO_PTR(self_in);
if (attr == MP_QSTR_addr) { 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) { } else if (attr == MP_QSTR_addr_type) {
dest[0] = mp_obj_new_int(self->addr_type); dest[0] = mp_obj_new_int(self->addr_type);
} else if (attr == MP_QSTR_rssi) { } 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); ubluepy_scan_entry_obj_t * item = m_new_obj(ubluepy_scan_entry_obj_t);
item->base.type = &ubluepy_scan_entry_type; item->base.type = &ubluepy_scan_entry_type;
item->addr[0] = data->p_peer_addr[5]; vstr_t vstr;
item->addr[1] = data->p_peer_addr[4]; vstr_init(&vstr, 17);
item->addr[2] = data->p_peer_addr[3];
item->addr[3] = data->p_peer_addr[2]; vstr_printf(&vstr, ""HEX2_FMT":"HEX2_FMT":"HEX2_FMT":" \
item->addr[4] = data->p_peer_addr[1]; HEX2_FMT":"HEX2_FMT":"HEX2_FMT"",
item->addr[5] = data->p_peer_addr[0]; 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->addr_type = data->addr_type;
item->rssi = data->rssi; item->rssi = data->rssi;