Skip to content

WIP: Get bluetooth services handles #7754

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

Closed
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
11 changes: 11 additions & 0 deletions extmod/modbluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,16 @@ STATIC mp_obj_t bluetooth_ble_gatts_register_services(mp_obj_t self_in, mp_obj_t
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gatts_register_services_obj, bluetooth_ble_gatts_register_services);

STATIC mp_obj_t bluetooth_ble_gatts_get_service_handle(mp_obj_t self_in, mp_obj_t service_uuid_in){
(void)self_in;

const mp_obj_bluetooth_uuid_t *service_uuid = MP_OBJ_TO_PTR(service_uuid_in);
uint16_t service_handle = mp_bluetooth_ble_gatts_get_service_handle(service_uuid);

return mp_obj_new_int(service_handle);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(bluetooth_ble_gatts_get_service_handle_obj, bluetooth_ble_gatts_get_service_handle);

#if MICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE
STATIC mp_obj_t bluetooth_ble_gap_connect(size_t n_args, const mp_obj_t *args) {
uint8_t addr_type = mp_obj_get_int(args[1]);
Expand Down Expand Up @@ -935,6 +945,7 @@ STATIC const mp_rom_map_elem_t bluetooth_ble_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_gatts_notify), MP_ROM_PTR(&bluetooth_ble_gatts_notify_obj) },
{ MP_ROM_QSTR(MP_QSTR_gatts_indicate), MP_ROM_PTR(&bluetooth_ble_gatts_indicate_obj) },
{ MP_ROM_QSTR(MP_QSTR_gatts_set_buffer), MP_ROM_PTR(&bluetooth_ble_gatts_set_buffer_obj) },
{ MP_ROM_QSTR(MP_QSTR_gatts_get_service_handle), MP_ROM_PTR(&bluetooth_ble_gatts_get_service_handle_obj) },
#if MICROPY_PY_BLUETOOTH_ENABLE_GATT_CLIENT
// GATT Client
{ MP_ROM_QSTR(MP_QSTR_gattc_discover_services), MP_ROM_PTR(&bluetooth_ble_gattc_discover_services_obj) },
Expand Down
3 changes: 3 additions & 0 deletions extmod/modbluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,9 @@ int mp_bluetooth_gatts_indicate(uint16_t conn_handle, uint16_t value_handle);
// Append-mode means that remote writes will append and local reads will clear after reading.
int mp_bluetooth_gatts_set_buffer(uint16_t value_handle, size_t len, bool append);

// Return the value handle of a service identified from its uuid.
uint16_t mp_bluetooth_ble_gatts_get_service_handle(const mp_obj_bluetooth_uuid_t *service_uuid_in);

// Disconnect from a central or peripheral.
int mp_bluetooth_gap_disconnect(uint16_t conn_handle);

Expand Down
9 changes: 9 additions & 0 deletions extmod/nimble/modbluetooth_nimble.c
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,15 @@ int mp_bluetooth_set_preferred_mtu(uint16_t mtu) {
return 0;
}

uint16_t mp_bluetooth_ble_gatts_get_service_handle(const mp_obj_bluetooth_uuid_t *service_uuid_in){
const ble_uuid_t *service_nimble_uuid = create_nimble_uuid(service_uuid_in, NULL);
uint16_t service_handle = 0;

ble_gatts_find_svc(service_nimble_uuid, &service_handle);

return service_handle;
}

#if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
int mp_bluetooth_gap_pair(uint16_t conn_handle) {
DEBUG_printf("mp_bluetooth_gap_pair: conn_handle=%d\n", conn_handle);
Expand Down