able to change ble mac address

This commit is contained in:
Yihui Xiong 2020-08-07 23:01:49 +08:00
parent 7ffa2a103c
commit e7da652711
3 changed files with 18 additions and 2 deletions

View File

@ -386,6 +386,15 @@ bleio_address_obj_t *common_hal_bleio_adapter_get_address(bleio_adapter_obj_t *s
return address;
}
uint32_t common_hal_bleio_adapter_set_address(bleio_adapter_obj_t *self, bleio_address_obj_t *address)
{
ble_gap_addr_t local_address;
local_address.addr_type = address->type;
const char *data = mp_obj_str_get_str(address->bytes);
memcpy(local_address.addr, data, NUM_BLEIO_ADDRESS_BYTES);
return sd_ble_gap_addr_set(&local_address);
}
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);

View File

@ -96,7 +96,7 @@ 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));
@ -104,10 +104,16 @@ STATIC mp_obj_t bleio_adapter_get_address(mp_obj_t 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) {
common_hal_bleio_adapter_set_address(self, new_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 },
};

View File

@ -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 uint32_t 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);