This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Events handling

I am looking at this example: github.com/.../main.c

In ble_evt_dispatch (line 315), this function forwards an BLE event to all of the modules. By looking at ble_evt_t, none of the fields does not signify which event is for which. So how does the individual modules knows that for example, BLE_GAP_EVT_CONNECTED is suppose to be for that module?

If there is an way to identify the events based on the UUID, then we can properly route the events to the correct BLE event handler.

Or am I just missing something here? Thank you.

Parents
  • In ble_evt_t there is a header which holds the event id. The different modules use the event id to check if it should handle the event or not. This is usually done using a switch statement. Example code:

    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            err_code = bsp_indication_set(BSP_INDICATE_CONNECTED);
            APP_ERROR_CHECK(err_code);
            m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
            break; // BLE_GAP_EVT_CONNECTED
    
        case BLE_GAP_EVT_DISCONNECTED:
            err_code = bsp_indication_set(BSP_INDICATE_IDLE);
            APP_ERROR_CHECK(err_code);
            m_conn_handle = BLE_CONN_HANDLE_INVALID;
            break; // BLE_GAP_EVT_DISCONNECTED
    
        default:
            // No implementation needed.
            break;
    }
    
  • The BLE_GAP_EVT_CONNECTED is sent from the SoftDevice to the application code. This is a type of BLE stack event, and usually only the on_ble_evt() function handles these events. But the event itself is not sent specifically to any event handler. It’s up to the application code on how these events should be handled.

Reply Children
No Data
Related