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
  • Hi,

    The changes that you did to amts.c, those are calculations for converting from bytes to kilobytes, and therefore the divisor should still be 1024 (since there are 1024 bytes in a kilobyte, regardless of packet size.)

    Please also double check that your code compiles and builds without error. In your code, the line "nrf_delay_ms(0.5);" uses a decimal value (float or double value) as the argument to nrf_delay_ms, but that function takes an integer (of type uint32_t).

    What I noticed is that if I send at least 4 packets (so AMT_BYTE_TRANSFER_CNT >= 244*4) it's ok

    Does this mean for AMT_BYTE_TRANSFER_CNT of (244 * 5), you observe a total of 1220 bytes sent? If I were you, I would study the code and look for any places where an assumption is made that 1024 (or more) bytes would always be transferred. While 244 * 4 only adds up to 976, 1024 / 244 still rounds down to 4. this may of course be a total miss, but what I try to communicate here is that something might be off with calculations involving the numbers 1024 and/or 244, and also typically involving division.

    Regards,
    Terje

  • Hi, 

    About this

    The changes that you did to amts.c, those are calculations for converting from bytes to kilobytes, and therefore the divisor should still be 1024 (since there are 1024 bytes in a kilobyte, regardless of packet size.)

    I can't understand what are you referring to. I know the changes I did are just calculations, but I need to do it because of some parameters I should get.

    About this:

    Please also double check that your code compiles and builds without error. In your code, the line "nrf_delay_ms(0.5);" uses a decimal value (float or double value) as the argument to nrf_delay_ms, but that function takes an integer (of type uint32_t).

    I know it's strange but I control I obtain any error.

    Does this mean for AMT_BYTE_TRANSFER_CNT of (244 * 5), you observe a total of 1220 bytes sent?

    Yes, 1220 bytes sent. 

    I don't understand the division which you are talking about:

    but what I try to communicate here is that something might be off with calculations involving the numbers 1024 and/or 244, and also typically involving division

    Thanks,

    Regards.

Reply
  • Hi, 

    About this

    The changes that you did to amts.c, those are calculations for converting from bytes to kilobytes, and therefore the divisor should still be 1024 (since there are 1024 bytes in a kilobyte, regardless of packet size.)

    I can't understand what are you referring to. I know the changes I did are just calculations, but I need to do it because of some parameters I should get.

    About this:

    Please also double check that your code compiles and builds without error. In your code, the line "nrf_delay_ms(0.5);" uses a decimal value (float or double value) as the argument to nrf_delay_ms, but that function takes an integer (of type uint32_t).

    I know it's strange but I control I obtain any error.

    Does this mean for AMT_BYTE_TRANSFER_CNT of (244 * 5), you observe a total of 1220 bytes sent?

    Yes, 1220 bytes sent. 

    I don't understand the division which you are talking about:

    but what I try to communicate here is that something might be off with calculations involving the numbers 1024 and/or 244, and also typically involving division

    Thanks,

    Regards.

Children
No Data
Related