BLE_GATTC_EVT_HVX
Hi,
I've implemented a BLE client that is able to:
- connect to another BLE device
- discover its services and characteristics
- enable notifications for a specific characteristic
- write to a specific characteristic
My aim is to enable notifications on multiple characteristics, and to be able to know from which characteristic the BLE_GATTC_EVT_HVX is generated, so that I can process the upcoming data in different ways.
This is what I'm doing upon discovery event, where I'm looking for a specific characteristic UUID within my own service to enable its notifications:
my_service_client_evt_t my_evt;
void my_service_on_db_disc_evt(my_service_client_t * p_my_service_client, ble_db_discovery_evt_t const * p_evt)
{
// Check if My Service was discovered.
if (p_evt->evt_type == BLE_DB_DISCOVERY_COMPLETE &&
p_evt->params.discovered_db.srv_uuid.uuid == MY_SERVICE_UUID &&
p_evt->params.discovered_db.srv_uuid.type == p_my_service_client->uuid_type)
{
my_evt.evt_type = MY_SERVICE_CLIENT_EVT_DISCOVERY_COMPLETE;
my_evt.conn_handle = p_evt->conn_handle;
for (uint32_t i = 0; i < p_evt->params.discovered_db.char_count; i++)
{
const ble_gatt_db_char_t * p_char = &(p_evt->params.discovered_db.charateristics[i]);
switch (p_char->characteristic.uuid.uuid)
{
case CUSTOM_VALUE_CHAR_UUID: // The discovered UUID matches the UUID I'm looking for
// Select this CVC
my_evt.peer_db.my_handle = p_char->characteristic.handle_value;
// Enable notifications for this CVC
cccd_configure(my_evt.conn_handle,p_char->cccd_handle, true);
break;
default:
break;
}
}
//If the instance has been assigned prior to db_discovery, assign the db_handles
if (p_my_service_client->conn_handle != BLE_CONN_HANDLE_INVALID)
{
if (p_my_service_client->peer_my_service_db.my_handle == BLE_GATT_HANDLE_INVALID)
{
p_my_service_client->peer_my_service_db = my_evt.peer_db;
}
}
p_my_service_client->evt_handler(p_my_service_client, &my_evt);
}
}
And this is what I'm doing to process the notifications from such characteristic:
// This handler is called upon BLE_GATTC_EVT_HVX event
static void on_hvx(ble_evt_t const * p_ble_evt)
{
uint8_t cvc_length = p_ble_evt->evt.gattc_evt.params.hvx.len;
uint8_t * cvc_content = (uint8_t *)p_ble_evt->evt.gattc_evt.params.hvx.data;
// Doing something with cvc_content
}
Now, I was thinking I could:
- enable notifications for different characteristics upon different calls to ble_db_discovery_start()
- retrieve the UUID of the characteristic I'm getting the notification from by looking into p_ble_evt parameters (but I could not find such information)
Therefore I'm asking you, can I achieve this? How can I know to which characteristic the p_ble_evt is related?
Thank you very much and best regards