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

Write Long - How to know which attribute

I'm using SDK 7.1, PCA10028 eval board, SD110 7.1, MCP 3.6.0.8331

I have 2 characteristics, and both are 32 bytes long. When I try a "Write Long" from the MCP a BLE_EVT_USER_MEM_REQUEST is generated.

Originally, I tested this with just one of characteristic "New_Name". The BLE_EVT_USER_MEM_REQUEST would call the function:

void on_write_long(ble_blinds_t * p_blinds,	ble_evt_t 	* p_ble_evt)
{
  ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
	int32_t							err_code;
	ble_user_mem_block_t 				*mem_block_struct;
	
     mem_block_struct->p_mem		= New_Name;
	 mem_block_struct->len			= sizeof(New_Name);
					
	sd_ble_user_mem_reply(p_blinds->conn_handle, mem_block_struct);
	APP_ERROR_CHECK(err_code);
    
}

This worked, and New_Name was updated to the value I wrote from the MCP.

After I added the second 32-byte attribute I looked at p_ble_evt to find a handle or UUID pointing to the attribute I was writing to. I cannot find any identifier to know, which of the two attributes, is being written to.

I thought it should be in: p_ble_evt.evt.gatts_evt.params.write.context.char_uuid. In both cases, the char_uuid has the value of 0x1651 (this is a valid attribute UUID, but does not correspond to either of the 32-byte attributes I'm trying to write to.

In the MCP both of the 32-byte attributes have unique UUIDs, and neither is 0x1651, so I'm not sure why the .char_uuid has a UUID for a completely different attribute.

How can I identify which attribute is being written to, so I can set up the mem_block_struct, to point to the correct value? Why is the .char_uuid pointing to an attribute I did not write to?

Thanks, Clint

Parents Reply
  • You need to look at the event BLE_GATTS_EVT_WRITE in the function ble_lmxs_on_ble_evt. It is where the buffer is being processed. First you need to check the characteristic handle to see if it is a long write or not. If a long write, the you will find the GATMEMHDR at the beginning of the p_mem block. The Handle member is the characteritic for which the data is destined to. Because the long write is subdivide into multiple blocks. The Offset is the cursor to where this current data should be in the full data block that was transmitted. I hope it's clearer. It's too long to describe everything here. Find GATT Queued Write in the documentation. It'll help you understand better the code.

Children
No Data
Related