Esempio n. 1
0
/**@brief     Function for fetching the event handler provided by a registered application module.
 *
 * @param[in] srv_uuid UUID of the service.
 *
 * @retval    evt_handler Event handler of the module, registered for the given service UUID.
 * @retval    NULL If no event handler is found.
 */
static ble_db_discovery_evt_handler_t registered_handler_get(const ble_uuid_t * const p_srv_uuid)
{
    uint32_t i;

    for (i = 0; i < m_num_of_handlers_reg; i++)
    {
        if (BLE_UUID_EQ(&(m_registered_handlers[i]), p_srv_uuid))
        {
            return (m_evt_handler);
        }
    }

    return NULL;
}
Esempio n. 2
0
/**@brief Function for handling the Characteristic Discovery Response event.
 *
 * @param[in]   p_ias_c     Immediate Alert Service client structure.
 * @param[in]   p_ble_evt   Event received from the BLE stack.
 */
static void on_char_disc_resp(ble_ias_c_t * p_ias_c, const ble_evt_t * p_ble_evt)
{
    ble_ias_c_evt_t evt;

    if (p_ble_evt->evt.gattc_evt.gatt_status == BLE_GATT_STATUS_SUCCESS)
    {
        int                                   i;
        const ble_gattc_evt_char_disc_rsp_t * p_char_disc_rsp;

        p_char_disc_rsp = &(p_ble_evt->evt.gattc_evt.params.char_disc_rsp);

        // Iterate through the characteristics and find the correct one.
        for (i = 0; i < p_char_disc_rsp->count; i++)
        {
            if (BLE_UUID_EQ(&m_alert_level_uuid, &(p_char_disc_rsp->chars[i].uuid)))
            {
                // The Alert Level characteristic in the Immediate Alert Service instance is found
                // on peer. Check if it has the correct property 'Write without response' as per
                // Section 3.3.1.1 in Bluetooth Specification Vol 3.
                if (p_char_disc_rsp->chars[i].char_props.write_wo_resp)
                {
                    // The Alert Level characteristic has the correct property.
                    p_ias_c->alert_level_handle = p_char_disc_rsp->chars[i].handle_value;

                    evt.evt_type = BLE_IAS_C_EVT_SRV_DISCOVERED;

                    p_ias_c->evt_handler(p_ias_c, &evt);
                    return;
                }
                else
                {
                    // The property of Alert Level characteristic is invalid. Hence break out of the
                    // loop.
                    break;
                }
            }
        }
    }

    // The Alert Level characteristic in Immediate Alert Service was not found at the peer. Notify
    // the application using evt_handler.
    evt.evt_type = BLE_IAS_C_EVT_SRV_NOT_FOUND; 

    p_ias_c->evt_handler(p_ias_c, &evt);
}