summaryrefslogtreecommitdiff
path: root/ports/nrf/common-hal/_bleio/Service.c
diff options
context:
space:
mode:
Diffstat (limited to 'ports/nrf/common-hal/_bleio/Service.c')
-rw-r--r--ports/nrf/common-hal/_bleio/Service.c19
1 files changed, 10 insertions, 9 deletions
diff --git a/ports/nrf/common-hal/_bleio/Service.c b/ports/nrf/common-hal/_bleio/Service.c
index 3362ed137..19288f747 100644
--- a/ports/nrf/common-hal/_bleio/Service.c
+++ b/ports/nrf/common-hal/_bleio/Service.c
@@ -56,10 +56,8 @@ uint32_t _common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uu
}
void common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_obj_t *uuid, bool is_secondary) {
- const uint32_t err_code = _common_hal_bleio_service_construct(self, uuid, is_secondary, mp_obj_new_list(0, NULL));
- if (err_code != NRF_SUCCESS) {
- mp_raise_OSError_msg_varg(translate("Failed to create service, NRF_ERROR_%q"), MP_OBJ_QSTR_VALUE(base_error_messages[err_code - NRF_ERROR_BASE_NUM]));
- }
+ check_nrf_error(_common_hal_bleio_service_construct(self, uuid, is_secondary,
+ mp_obj_new_list(0, NULL)));
}
void bleio_service_from_connection(bleio_service_obj_t *self, mp_obj_t connection) {
@@ -121,6 +119,10 @@ void common_hal_bleio_service_add_characteristic(bleio_service_obj_t *self,
bleio_attribute_gatts_set_security_mode(&char_attr_md.read_perm, characteristic->read_perm);
bleio_attribute_gatts_set_security_mode(&char_attr_md.write_perm, characteristic->write_perm);
+ #if CIRCUITPY_VERBOSE_BLE
+ // Turn on read authorization so that we receive an event to print on every read.
+ char_attr_md.rd_auth = true;
+ #endif
ble_gatts_attr_t char_attr = {
.p_uuid = &char_uuid,
@@ -133,16 +135,15 @@ void common_hal_bleio_service_add_characteristic(bleio_service_obj_t *self,
ble_gatts_char_handles_t char_handles;
- uint32_t err_code;
- err_code = sd_ble_gatts_characteristic_add(self->handle, &char_md, &char_attr, &char_handles);
- if (err_code != NRF_SUCCESS) {
- mp_raise_OSError_msg_varg(translate("Failed to add characteristic, NRF_ERROR_%q"), MP_OBJ_QSTR_VALUE(base_error_messages[err_code - NRF_ERROR_BASE_NUM]));
- }
+ check_nrf_error(sd_ble_gatts_characteristic_add(self->handle, &char_md, &char_attr, &char_handles));
characteristic->user_desc_handle = char_handles.user_desc_handle;
characteristic->cccd_handle = char_handles.cccd_handle;
characteristic->sccd_handle = char_handles.sccd_handle;
characteristic->handle = char_handles.value_handle;
+ #if CIRCUITPY_VERBOSE_BLE
+ mp_printf(&mp_plat_print, "Char handle %x user %x cccd %x sccd %x\n", characteristic->handle, characteristic->user_desc_handle, characteristic->cccd_handle, characteristic->sccd_handle);
+ #endif
mp_obj_list_append(self->characteristic_list, MP_OBJ_FROM_PTR(characteristic));
}