This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
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

How to get data from different characteristics

Hello,

i have a BLE device running with a service with three writable characteristics. At the moment I have one data handler function. If there is any characteristic written, the software will jump to this data handler. My question is, how can I differ, which charcteristic was written??

void memory_data_handler(ble_memory_t * p_com, uint8_t * p_data, uint16_t length){
	dbg_printf("*** Mem service data written:\r");
	for (uint32_t i = 0; i < length; i++)
{
			memContent[i] = p_data[i];
			dbg_printf("data[%d] = 0x%x\r", i, memContent[i]);
}}

Is there a opportunity to get a switch case into the datahandler? Or do I have to write a data_handler function for every characteristic? Then I would have to call the right data_handler function in the

static void on_write(ble_memory_t * p_com, ble_evt_t * p_ble_evt)

function...

Thanks for any help!

Regards, BTprogrammer

  • All the information is in the p_ble_evt, if you follow that down you'll find the characteristic being written (and a whole load of other information). So yes you need to do something in the on_write handler to either call one of three functions or pull the information out of the structure and pass it as another argument to one function or any combination of those.

    The current signature of your memory_data_handler() has already lost the information about which characteristic was written.

    If your three writable characteristics are basically very similar and handled in similar ways, then use one handler and just pass it the characteristic pulled from the event, if your three characteristics are quite different and would benefit from each having its own handler code, then switch inside the on_write() and call one of three pieces of code.

  • Hello RK,

    thanks for your reply. Now I added three different data handlers. And call each specific data_handler function in the on_write function. I think this is the right way for my application. And it is just the way I suspected...

    Thanks and regards, BTprogrammer

Related