Skip to content

support to change ble mac address #3276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-08-11 15:37-0500\n"
"POT-Creation-Date: 2020-08-14 09:36-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -641,6 +641,10 @@ msgstr ""
msgid "Could not restart PWM"
msgstr ""

#: shared-bindings/_bleio/Adapter.c
msgid "Could not set address"
msgstr ""

#: ports/stm/common-hal/pulseio/PWMOut.c
msgid "Could not start PWM"
msgstr ""
Expand Down
11 changes: 11 additions & 0 deletions ports/nrf/common-hal/_bleio/Adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,17 @@ bleio_address_obj_t *common_hal_bleio_adapter_get_address(bleio_adapter_obj_t *s
return address;
}

bool common_hal_bleio_adapter_set_address(bleio_adapter_obj_t *self, bleio_address_obj_t *address) {
ble_gap_addr_t local_address;
mp_buffer_info_t bufinfo;
if (!mp_get_buffer(address->bytes, &bufinfo, MP_BUFFER_READ)) {
return false;
}
local_address.addr_type = address->type;
memcpy(local_address.addr, bufinfo.buf, NUM_BLEIO_ADDRESS_BYTES);
return sd_ble_gap_addr_set(&local_address) == NRF_SUCCESS;
}

mp_obj_str_t* common_hal_bleio_adapter_get_name(bleio_adapter_obj_t *self) {
uint16_t len = 0;
sd_ble_gap_device_name_get(NULL, &len);
Expand Down
12 changes: 10 additions & 2 deletions shared-bindings/_bleio/Adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,26 @@ const mp_obj_property_t bleio_adapter_enabled_obj = {
};

//| address: Address
//| """MAC address of the BLE adapter. (read-only)"""
//| """MAC address of the BLE adapter."""
//|
STATIC mp_obj_t bleio_adapter_get_address(mp_obj_t self) {
return MP_OBJ_FROM_PTR(common_hal_bleio_adapter_get_address(self));

}
MP_DEFINE_CONST_FUN_OBJ_1(bleio_adapter_get_address_obj, bleio_adapter_get_address);

STATIC mp_obj_t bleio_adapter_set_address(mp_obj_t self, mp_obj_t new_address) {
if (!common_hal_bleio_adapter_set_address(self, new_address)) {
mp_raise_bleio_BluetoothError(translate("Could not set address"));
}
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(bleio_adapter_set_address_obj, bleio_adapter_set_address);

const mp_obj_property_t bleio_adapter_address_obj = {
.base.type = &mp_type_property,
.proxy = { (mp_obj_t)&bleio_adapter_get_address_obj,
(mp_obj_t)&mp_const_none_obj,
(mp_obj_t)&bleio_adapter_set_address_obj,
(mp_obj_t)&mp_const_none_obj },
};

Expand Down
1 change: 1 addition & 0 deletions shared-bindings/_bleio/Adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ extern bool common_hal_bleio_adapter_get_enabled(bleio_adapter_obj_t *self);
extern void common_hal_bleio_adapter_set_enabled(bleio_adapter_obj_t *self, bool enabled);
extern bool common_hal_bleio_adapter_get_connected(bleio_adapter_obj_t *self);
extern bleio_address_obj_t *common_hal_bleio_adapter_get_address(bleio_adapter_obj_t *self);
extern bool common_hal_bleio_adapter_set_address(bleio_adapter_obj_t *self, bleio_address_obj_t *address);

extern mp_obj_str_t* common_hal_bleio_adapter_get_name(bleio_adapter_obj_t *self);
extern void common_hal_bleio_adapter_set_name(bleio_adapter_obj_t *self, const char* name);
Expand Down