Beispiel #1
0
static void discovery_complete_evt_trigger(ble_db_discovery_t * const p_db_discovery)
{
    ble_db_discovery_evt_t          evt;
    ble_db_discovery_evt_handler_t  p_evt_handler;

    // No (more) descriptors found. Send an event to the application.
    p_evt_handler = registered_handler_get(p_db_discovery->srv_being_discovered.srv_uuid.uuid);
    
    if (p_evt_handler != NULL)
    {
        evt.evt_type             = BLE_DB_DISCOVERY_COMPLETE;
        evt.conn_handle          = p_db_discovery->conn_handle;
        evt.params.discovered_db = p_db_discovery->srv_being_discovered;

        uint8_t                   i = 0;
        ble_db_discovery_char_t * p_chars_being_discovered =
                                          &(p_db_discovery->srv_being_discovered.charateristics[0]);

        for (i = 0; i < evt.params.discovered_db.char_count; i++)
        {
            evt.params.discovered_db.charateristics[i].cccd_handle    =
                            p_chars_being_discovered[i].cccd_handle;
            evt.params.discovered_db.charateristics[i].characteristic =
                            p_chars_being_discovered[i].characteristic;
        }

        // Send the event to the registered user module.
        p_evt_handler(&evt);
    }
}
/**@brief     Function for triggering a Discovery Complete or Service Not Found event to the
 *            application.
 *
 * @details   This function will fetch the event handler based on the UUID of the service being
 *            discovered. (The event handler is registered by the application beforehand).
 *            It then triggers an event indicating the completion of the service discovery.
 *            If no event handler was found, then this function will do nothing.
 *
 * @param[in] p_db_discovery Pointer to the DB discovery structure.
 * @param[in] is_srv_found   Variable to indicate if the service was found at the peer.
 */
static void discovery_complete_evt_trigger(ble_db_discovery_t * const p_db_discovery,
                                           bool                       is_srv_found)
{
    ble_db_discovery_evt_handler_t p_evt_handler;
    ble_db_discovery_srv_t       * p_srv_being_discovered;

    p_srv_being_discovered = &(p_db_discovery->services[p_db_discovery->curr_srv_ind]);

    p_evt_handler = registered_handler_get(&(p_srv_being_discovered->srv_uuid));

    if (p_evt_handler != NULL)
    {
        if (m_pending_usr_evt_index < DB_DISCOVERY_MAX_USERS)
        {
            // Insert an event into the pending event list.
            m_pending_user_evts[m_pending_usr_evt_index].evt.conn_handle =
                p_db_discovery->conn_handle;

            if (is_srv_found)
            {
                m_pending_user_evts[m_pending_usr_evt_index].evt.evt_type =
                    BLE_DB_DISCOVERY_COMPLETE;

                m_pending_user_evts[m_pending_usr_evt_index].evt.params.discovered_db =
                    *p_srv_being_discovered;
            }
            else
            {
                m_pending_user_evts[m_pending_usr_evt_index].evt.evt_type =
                    BLE_DB_DISCOVERY_SRV_NOT_FOUND;
            }
            m_pending_user_evts[m_pending_usr_evt_index].evt_handler = p_evt_handler;

            m_pending_usr_evt_index++;

            if (m_pending_usr_evt_index == m_num_of_handlers_reg)
            {
                // All registered modules have pending events. Send all pending events to the user
                // modules.
                pending_user_evts_send();
            }
            else
            {
                // Too many events pending. Do nothing. (Ideally this should not happen.)
            }
        }
    }
}
Beispiel #3
0
static void indicate_error_to_app(ble_db_discovery_t * const   p_db_discovery,
                                  const ble_gattc_evt_t* const p_ble_gattc_evt,
                                  uint32_t                     err_code)
{
    // Indicate the error to the user application registered for the service being
    // discovered.
    ble_db_discovery_evt_t         evt;
    ble_db_discovery_evt_handler_t p_evt_handler;

    p_evt_handler = registered_handler_get(p_db_discovery->srv_being_discovered.srv_uuid.uuid);

    evt.conn_handle     = p_ble_gattc_evt->conn_handle;
    evt.evt_type        = BLE_DB_DISCOVERY_ERROR;
    evt.params.err_code = err_code;

    p_evt_handler(&evt);
}
Beispiel #4
0
/**@brief     Function for storing the event handler provided by a registered application module.
 *
 * @param[in] p_srv_uuid    The UUID of the service.
 * @param[in] p_evt_handler The event handler provided by the application.
 *
 * @retval    NRF_SUCCESS If the handler was stored or already present in the list.
 * @retval    NRF_ERROR_NO_MEM If there is no space left to store the handler.
 */
static uint32_t registered_handler_set(const ble_uuid_t * const       p_srv_uuid,
                                       ble_db_discovery_evt_handler_t p_evt_handler)
{
    if (registered_handler_get(p_srv_uuid) != NULL)
    {
        return NRF_SUCCESS;
    }
    if (m_num_of_handlers_reg < DB_DISCOVERY_MAX_USERS)
    {
        m_registered_handlers[m_num_of_handlers_reg] = *p_srv_uuid;

        m_num_of_handlers_reg++;

        return NRF_SUCCESS;
    }
    else
    {
        return NRF_ERROR_NO_MEM;
    }
}
Beispiel #5
0
/**@brief     Function for indicating error to the application.
 *
 * @details   This function will fetch the event handler based on the UUID of the service being
 *            discovered. (The event handler is registered by the application beforehand).
 *            The error code is added to the pending events together with the event handler.
 *            If no event handler was found, then this function will do nothing.
 *
 * @param[in] p_db_discovery Pointer to the DB discovery structure.
 * @param[in] err_code       Error code that should be provided to the application.
 * @param[in] conn_handle    Connection Handle.
 *
 */
static void discovery_error_evt_trigger(ble_db_discovery_t * const p_db_discovery,
                                        uint32_t                   err_code,
                                        uint16_t const             conn_handle)
{
    ble_db_discovery_evt_handler_t p_evt_handler;
    ble_gatt_db_srv_t            * p_srv_being_discovered;

    p_srv_being_discovered = &(p_db_discovery->services[p_db_discovery->curr_srv_ind]);

    p_evt_handler = registered_handler_get(&(p_srv_being_discovered->srv_uuid));

    if (p_evt_handler != NULL)
    {
        ble_db_discovery_evt_t evt;

        evt.conn_handle     = conn_handle;
        evt.evt_type        = BLE_DB_DISCOVERY_ERROR;
        evt.params.err_code = err_code;

        p_evt_handler(&evt);
    }
}
/**@brief     Function for indicating error to the application.
 *
 * @details   This function will fetch the event handler based on the UUID of the service being
 *            discovered. (The event handler is registered by the application beforehand).
 *            The error code is added to the pending events together with the event handler.
 *            If no event handler was found, then this function will do nothing.
 *
 * @param[in] p_db_discovery Pointer to the DB discovery structure.
 * @param[in] err_code       Error code that should be provided to the application.
 *
 */
static void discovery_error_evt_trigger(ble_db_discovery_t * const p_db_discovery,
                                        uint32_t                   err_code)
{
    ble_db_discovery_evt_handler_t p_evt_handler;
    ble_db_discovery_srv_t       * p_srv_being_discovered;

    p_srv_being_discovered = &(p_db_discovery->services[p_db_discovery->curr_srv_ind]);

    p_evt_handler = registered_handler_get(&(p_srv_being_discovered->srv_uuid));

    if (p_evt_handler != NULL)
    {
        if (m_pending_usr_evt_index < DB_DISCOVERY_MAX_USERS)
        {
            // Insert an event into the pending event list.
            m_pending_user_evts[m_pending_usr_evt_index].evt.conn_handle     =
                p_db_discovery->conn_handle;
            m_pending_user_evts[m_pending_usr_evt_index].evt.evt_type        =
                BLE_DB_DISCOVERY_ERROR;
            m_pending_user_evts[m_pending_usr_evt_index].evt.params.err_code = err_code;
            m_pending_user_evts[m_pending_usr_evt_index].evt_handler         = p_evt_handler;

            m_pending_usr_evt_index++;

            if (m_pending_usr_evt_index == m_num_of_handlers_reg)
            {
                // All registered modules have pending events.
                // Send all pending events to the user modules.
                pending_user_evts_send();
            }
        }
        else
        {
            // Too many events pending. Do nothing. (Ideally this should not happen.)
        }
    }
}