From 7e52da7ccb6214f8b53cc5c5c2f3faeb42441ff6 Mon Sep 17 00:00:00 2001 From: Glenn Ruben Bakke Date: Sun, 2 Apr 2017 16:41:08 +0200 Subject: [PATCH] nrf5/bluetooth: Update ble_drv_address_get to new api which pass in a address struct to fill by reference. Updating implementation to copy the address data. Also ensuring that the bluetooth stack has been enabled before fetching the address from the bluetooth stack. --- nrf5/bluetooth/ble_drv.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/nrf5/bluetooth/ble_drv.c b/nrf5/bluetooth/ble_drv.c index 3ea065710f..490c2b600c 100644 --- a/nrf5/bluetooth/ble_drv.c +++ b/nrf5/bluetooth/ble_drv.c @@ -227,13 +227,21 @@ uint8_t ble_drv_stack_enabled(void) { return is_enabled; } -void ble_drv_address_get(void) { +void ble_drv_address_get(ble_drv_addr_t * p_addr) { + SD_TEST_OR_ENABLE(); + ble_gap_addr_t local_ble_addr; #if (BLUETOOTH_SD != 132) uint32_t err_code = sd_ble_gap_address_get(&local_ble_addr); #else uint32_t err_code = sd_ble_gap_addr_get(&local_ble_addr); #endif + + if (err_code != 0) { + nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_OSError, + "Can not query for the device address.")); + } + BLE_DRIVER_LOG("ble address, type: " HEX2_FMT ", " \ "address: " HEX2_FMT ":" HEX2_FMT ":" HEX2_FMT ":" \ HEX2_FMT ":" HEX2_FMT ":" HEX2_FMT "\n", \ @@ -241,7 +249,8 @@ void ble_drv_address_get(void) { local_ble_addr.addr[5], local_ble_addr.addr[4], local_ble_addr.addr[3], \ local_ble_addr.addr[2], local_ble_addr.addr[1], local_ble_addr.addr[0]); - (void)err_code; + p_addr->addr_type = local_ble_addr.addr_type; + memcpy(p_addr->addr, local_ble_addr.addr, 6); } void ble_drv_advertise(void) {