This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problems with function for handling ble events

Hi,

I'm using ble_app_template to implement my custom solution. I can read battery values, but I can't read custom values.

As a reference, I'm using ble_app_cscs, and the function below works fine.

ble_cscs.c

void ble_cscs_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
{
    ble_cscs_t * p_cscs = (ble_cscs_t *)p_context;

    if (p_cscs == NULL || p_ble_evt == NULL)
    {
        return;
    }

    ble_sc_ctrlpt_on_ble_evt(&(p_cscs->ctrl_pt), p_ble_evt);
    switch (p_ble_evt->header.evt_id)
    {
        case BLE_GAP_EVT_CONNECTED:
            on_connect(p_cscs, p_ble_evt);
            break;

        case BLE_GAP_EVT_DISCONNECTED:
            on_disconnect(p_cscs, p_ble_evt);
            break;

        case BLE_GATTS_EVT_WRITE:
            on_write(p_cscs, p_ble_evt);
            break;

        default:
            // No implementation needed.
            break;
    }
}

In my code, I made the same function, but the value of machine state is 0 and never enter in the first case to send data do my application.

void ble_cps_on_ble_evt(ble_cps_t * p_cps, ble_evt_t * p_ble_evt)
{
 
    switch (p_ble_evt->header.evt_id)
    {
    case BLE_GAP_EVT_CONNECTED:
        on_connect(p_cps, p_ble_evt);
        break;

    case BLE_GAP_EVT_DISCONNECTED:
        on_disconnect(p_cps, p_ble_evt);
        break;

    case BLE_GATTS_EVT_WRITE:
        on_write(p_cps, p_ble_evt);
        break;

    default:
        // No implementation needed.
        break;
    }
}

I using nrf52 pca10040 dev board and sdk 17.0.2.

Can you help me to solve this?

Regards

Parents
  • To complement my question, inside the battery service (ble_bas.c) has the same function and works fine too.

    void ble_bas_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
    {
        if ((p_context == NULL) || (p_ble_evt == NULL))
        {
            return;
        }

        ble_bas_t * p_bas = (ble_bas_t *)p_context;

        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GATTS_EVT_WRITE:
                on_write(p_bas, p_ble_evt);
                break;

            default:
                // No implementation needed.
                break;
        }
    }

Reply
  • To complement my question, inside the battery service (ble_bas.c) has the same function and works fine too.

    void ble_bas_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
    {
        if ((p_context == NULL) || (p_ble_evt == NULL))
        {
            return;
        }

        ble_bas_t * p_bas = (ble_bas_t *)p_context;

        switch (p_ble_evt->header.evt_id)
        {
            case BLE_GATTS_EVT_WRITE:
                on_write(p_bas, p_ble_evt);
                break;

            default:
                // No implementation needed.
                break;
        }
    }

Children
No Data
Related