How to Receive 100bytes of data with net_buf_simple_pull_mem( ) over ble-mesh

Hi,

I am transferring 100 bytes of data via BLE-Mesh from a vendor client model, which I need to receive in my vendor server model.

I referred to nCS provided chat sample, where I noticed below data extraction code:

static const uint8_t *extract_msg(struct net_buf_simple *buf)
{
	buf->data[buf->len - 1] = '\0';
	return net_buf_simple_pull_mem(buf, buf->len);
}

static int handle_message(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx,
			  struct net_buf_simple *buf)
{
	struct bt_mesh_chat_cli *chat = model->user_data;
	const uint8_t *msg;

	msg = extract_msg(buf);

	if (chat->handlers->message) {
		chat->handlers->message(chat, ctx, msg);
	}

	return 0;
}

My questions are:

  1. What's the max len of data buffer that can be received.?
  2. How do I modify the size of data buffer..? I couldn't find where the net_buf_simple struct field for size buf->len is being set.
  3. How would the usage of net_buf_simple_pull_mem( ) look like to pull 100bytes..?
  4. This 100bytes data, can I typecast into my user structure to populate struct fields..?

Thanks,

Ubaid

  • Hi. 

    I need to do some research on this. I will get back to you with more information by the end of the day tomorrow. 

    Sorry about the inconvenience. 

    Br, 
    Joakim

  • I will get back to you with more information by the end of the day tomorrow

    Thank you , Yes please, will wait for your help.

    Along with the above queries, I have a related query as in below:

    Suppose along with my opcode, my client model will send the following data:

    struct Log_Data
    {
        float LOG_ID;
        uint8_t timeout;
        uint8_t severity;
        uint64_t timestamp;
    }

    On my server model, if i need to receive this data against the opcode registered handler, will my handler look as in below:

    static int handle_message(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx,
    			  struct net_buf_simple *buf)
    {
    	float LOG_ID = net_buf_simple_pull_le64(buff);
    	uint8_t timeout = net_buf_simple_pull_u8(buff);
    	uint8_t severity = net_buf_simple_pull_u8(buff);
    	uint64_t timestamp = net_buf_simple_pull_le64(buff);
    
    	return 0;
    }

    Or should I use the API: 

    net_buf_simple_pull_mem(buf, sizeof(Log_Data))

    which would return me pointer to the data..?

    Kindly suggest a way for me to receive the above mentioned struct,

    Thanks,

    Ubaid

  • Hello .


    I will get back to you with more information by the end of the day tomorrow

    • What's the max len of data buffer that can be received.?
    • How do I modify the size of data buffer..? I couldn't find where the net_buf_simple struct field for size buf->len is being set.
    • How would the usage of net_buf_simple_pull_mem( ) look like to pull 100bytes..?
    • This 100bytes data, can I typecast into my user structure to populate struct fields..?

    Can you suggest..?

Related