Skip to content
Snippets Groups Projects
Commit bee7c425 authored by schneider's avatar schneider
Browse files

feat(mp-ble): Allow to register descriptors

parent b4f339c5
No related branches found
No related tags found
1 merge request!446Initial MicroPython BLE support (GATTS)
...@@ -391,10 +391,6 @@ int mp_bluetooth_gatts_register_service( ...@@ -391,10 +391,6 @@ int mp_bluetooth_gatts_register_service(
size_t num_descriptors_total = 0; size_t num_descriptors_total = 0;
size_t num_ccds = 0; size_t num_ccds = 0;
for (size_t i = 0; i < num_characteristics; i++) { for (size_t i = 0; i < num_characteristics; i++) {
if (num_descriptors[i]) {
// TODO: more specific error
raise();
}
num_descriptors_total += num_descriptors[i]; num_descriptors_total += num_descriptors[i];
if ((characteristic_flags[i] & if ((characteristic_flags[i] &
MP_BLUETOOTH_CHARACTERISTIC_FLAG_NOTIFY) || MP_BLUETOOTH_CHARACTERISTIC_FLAG_NOTIFY) ||
...@@ -409,7 +405,7 @@ int mp_bluetooth_gatts_register_service( ...@@ -409,7 +405,7 @@ int mp_bluetooth_gatts_register_service(
1 + num_characteristics * 2 + num_ccds + num_descriptors_total; 1 + num_characteristics * 2 + num_ccds + num_descriptors_total;
uint16_t startHandle; uint16_t startHandle;
uint16_t uuid_len = uint8_t uuid_len =
service_uuid->type == MP_BLUETOOTH_UUID_TYPE_16 ? 2 : 16; service_uuid->type == MP_BLUETOOTH_UUID_TYPE_16 ? 2 : 16;
// TODO: handle error // TODO: handle error
...@@ -423,12 +419,13 @@ int mp_bluetooth_gatts_register_service( ...@@ -423,12 +419,13 @@ int mp_bluetooth_gatts_register_service(
uint16_t currentHandle = startHandle; uint16_t currentHandle = startHandle;
size_t descriptor_index = 0;
size_t handle_index = 0; size_t handle_index = 0;
for (size_t i = 0; i < num_characteristics; ++i) {
for (size_t i = 0; i < num_characteristics; i++) {
uint8_t flags = characteristic_flags[i]; uint8_t flags = characteristic_flags[i];
mp_obj_bluetooth_uuid_t *uuid = characteristic_uuids[i]; mp_obj_bluetooth_uuid_t *uuid = characteristic_uuids[i];
uint8_t uuid_len = uuid_len = uuid->type == MP_BLUETOOTH_UUID_TYPE_16 ? 2 : 16;
uuid->type == MP_BLUETOOTH_UUID_TYPE_16 ? 2 : 16;
currentHandle++; currentHandle++;
epic_atts_dyn_add_characteristic( epic_atts_dyn_add_characteristic(
...@@ -484,6 +481,33 @@ int mp_bluetooth_gatts_register_service( ...@@ -484,6 +481,33 @@ int mp_bluetooth_gatts_register_service(
} }
handle_index++; handle_index++;
for (size_t j = 0; j < num_descriptors[i]; j++) {
flags = descriptor_flags[descriptor_index];
mp_obj_bluetooth_uuid_t *uuid =
descriptor_uuids[descriptor_index];
uuid_len = uuid->type == MP_BLUETOOTH_UUID_TYPE_16 ? 2 :
16;
epic_ble_atts_dyn_add_descriptor(
pSvcHandle,
uuid->data,
uuid_len,
flags,
NULL,
0,
MP_BLUETOOTH_DEFAULT_ATTR_LEN
);
mp_bluetooth_gatts_db_create_entry(
GATTS_DB,
handles[handle_index],
MP_BLUETOOTH_DEFAULT_ATTR_LEN
);
descriptor_index++;
handle_index++;
}
} }
return 0; return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment