ble_app_att_mtu_throughput in details

Hi, 

I'm using ble_app_att_mtu_throughput to communicate some data from a nRF52832 to another one. I reached my goal (1.4Mbps) but now I would know what the two board communicate. 

I menaged the code in particular: 

in amt.h:

#define AMT_BYTE_TRANSFER_CNT               (244 * 5)

instead of: 

#define AMT_BYTE_TRANSFER_CNT               (1024 * 1024)

just to manage well my 244 byte packets;

in the last part of amts.c I changed 244 with 1024, so:

static void char_notification_send(nrf_ble_amts_t * p_ctx)
{
    uint8_t            data[256];
    uint16_t           payload_len = p_ctx->max_payload_len;
    nrf_ble_amts_evt_t evt;

    if (p_ctx->bytes_sent >= AMT_BYTE_TRANSFER_CNT)
    {
        evt.bytes_transfered_cnt = p_ctx->bytes_sent;
        evt.evt_type             = NRF_BLE_AMTS_EVT_TRANSFER_FINISHED;

        p_ctx->evt_handler(evt);

        p_ctx->busy        = false;
        p_ctx->bytes_sent  = 0;
        p_ctx->kbytes_sent = 0;

        return;
    }

    ble_gatts_hvx_params_t const hvx_param =
    {
        .type   = BLE_GATT_HVX_NOTIFICATION,
        .handle = p_ctx->amts_char_handles.value_handle,
        .p_data = data,
        .p_len  = &payload_len,
    };

    uint32_t err_code = NRF_SUCCESS;
    while (err_code == NRF_SUCCESS)
    {
        (void)uint32_encode(p_ctx->bytes_sent, data);

        err_code = sd_ble_gatts_hvx(p_ctx->conn_handle, &hvx_param);

        if (err_code == NRF_ERROR_RESOURCES)
        {
            // Wait for BLE_GATTS_EVT_HVN_TX_COMPLETE.
            p_ctx->busy = true;
            break;
        }
        else if (err_code != NRF_SUCCESS)
        {
            NRF_LOG_ERROR("sd_ble_gatts_hvx() failed: 0x%x", err_code);
        }

        p_ctx->bytes_sent += payload_len;

        if (p_ctx->kbytes_sent != (p_ctx->bytes_sent / 244))
        {
            p_ctx->kbytes_sent = (p_ctx->bytes_sent / 244);

            evt.evt_type             = NRF_BLE_AMTS_EVT_PACKET_244B;
            evt.bytes_transfered_cnt = p_ctx->bytes_sent;
            p_ctx->evt_handler(evt);
        }
    }
}

instead of: 

static void char_notification_send(nrf_ble_amts_t * p_ctx)
{
    uint8_t            data[256];
    uint16_t           payload_len = p_ctx->max_payload_len;
    nrf_ble_amts_evt_t evt;

    if (p_ctx->bytes_sent >= AMT_BYTE_TRANSFER_CNT)
    {
        evt.bytes_transfered_cnt = p_ctx->bytes_sent;
        evt.evt_type             = NRF_BLE_AMTS_EVT_TRANSFER_FINISHED;

        p_ctx->evt_handler(evt);

        p_ctx->busy        = false;
        p_ctx->bytes_sent  = 0;
        p_ctx->kbytes_sent = 0;

        return;
    }

    ble_gatts_hvx_params_t const hvx_param =
    {
        .type   = BLE_GATT_HVX_NOTIFICATION,
        .handle = p_ctx->amts_char_handles.value_handle,
        .p_data = data,
        .p_len  = &payload_len,
    };

    uint32_t err_code = NRF_SUCCESS;
    while (err_code == NRF_SUCCESS)
    {
        (void)uint32_encode(p_ctx->bytes_sent, data);

        err_code = sd_ble_gatts_hvx(p_ctx->conn_handle, &hvx_param);

        if (err_code == NRF_ERROR_RESOURCES)
        {
            // Wait for BLE_GATTS_EVT_HVN_TX_COMPLETE.
            p_ctx->busy = true;
            break;
        }
        else if (err_code != NRF_SUCCESS)
        {
            NRF_LOG_ERROR("sd_ble_gatts_hvx() failed: 0x%x", err_code);
        }

        p_ctx->bytes_sent += payload_len;

        if (p_ctx->kbytes_sent != (p_ctx->bytes_sent / 1024))
        {
            p_ctx->kbytes_sent = (p_ctx->bytes_sent / 1024);

            evt.evt_type             = NRF_BLE_AMTS_EVT_PACKET_244B;
            evt.bytes_transfered_cnt = p_ctx->bytes_sent;
            p_ctx->evt_handler(evt);
        }
    }
}

then in amt.h I added NRF_BLE_AMTS_EVT_PACKET_244B:

typedef enum
{
    NRF_BLE_AMTS_EVT_NOTIF_ENABLED,
    NRF_BLE_AMTS_EVT_NOTIF_DISABLED,
    NRF_BLE_AMTS_EVT_TRANSFER_1KB,
    NRF_BLE_AMTS_EVT_PACKET_244B,
    NRF_BLE_AMTS_EVT_TRANSFER_FINISHED,
} nrf_ble_amts_evt_type_t;

so in the main I used NRF_BLE_AMTS_EVT_PACKET_244B instead of NRF_BLE_AMTS_EVT_PACKET_1KB:

case NRF_BLE_AMTS_EVT_PACKET_244B:   
        {
            NRF_LOG_INFO("Packet sent");
            bsp_board_led_on(PROGRESS_LED);
            nrf_delay_ms(0.5);
            bsp_board_led_off(PROGRESS_LED);
        } break;

So I did this modifications to trigger the case NRF_BLE_AMTS_EVT_PACKET_244B each 244B instead of 1KB, blinking one of the led on the board. 

What I noticed is that if I send at least 4 packets (so AMT_BYTE_TRANSFER_CNT >= 244*4) it's ok, but if I send less than 4 packets from the terminal I see that I receive however 4 packets. For example, if I set AMT_BYTE_TRANSFER_CNT = 244*2, that's what I see on PuTTY terminal: 

Central:

as you see "Sent 976 bytes of ATT payload" which are 244*4, meanwhile on the peripheral happen the same:

May you can say me, since I did some modifications, if I should manage something else?

Thanks.

Parents Reply Children
Related