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

How to add an event handler for service?

Hi,

I'm studying the example code of "ble_app_blinky_pca10040_s132 ". 

What confused me is I couldn't find how the "led_write_handler" is added to the service. There is a line 

// Initialize LBS.
init.led_write_handler = led_write_handler;

in main.c (line 302), and it's passed to ble_lbs_init() (in ble_lbs.c), then in ble_lbs_init(), the handler pointer is set to p_lbs:

// Initialize service structure.
p_lbs->led_write_handler = p_lbs_init->led_write_handler;

(line 198),  but then I couldn't find this pointer is passed to anywhere, how does it work?

More generally, if I want to add a custom service to GATT, to my understanding I need to call several SoftDevice APIs:

1. sd_ble_uuid_vs_add() to add the UUID to the stack's UUID table.

2. sd_ble_gatts_service_add() to add service

3. sd_ble_gatts_characteristic_add() to add characteristics for this service

There is no parameter of these functions that needs a event handler pointer, then if I need a function to handle the write event to the characteristic value, what should I do? Did I missed something?

Thanks.

Parents Reply Children
No Data
Related