Dear community,
I am trying to implement a custom service, however I am struggling because many example codes are for PCA10040, Softdevice S132 and/or for older SDK's. I've basically tried to implement it based on:
- the custom BLE service example (PCA10040, S132) from GitHub
- the predefined services like BAS and LLS from the proximity example (PCA10056, S140), on which my code is based on
- the ble_app_template example from SDK 17.0.2.
So I've tried to work out the differences between those three examples and now I am wondering what difference is between those three code snippets (from the (...)_char_add functions of those three example codes).
ble_add_char_params_t char_md; memset(&char_md, 0, sizeof(char_md)); char_md.char_props.read = 1; char_md.char_props.write = 1; char_md.char_props.notify = 1; char_md.p_char_user_desc = NULL; char_md.p_char_pf = NULL; char_md.p_user_desc_md = NULL; char_md.p_cccd_md = &cccd_md; char_md.p_sccd_md = NULL;
ble_gatts_attr_md_t attr_md; memset(&attr_md, 0, sizeof(attr_md)); attr_md.read_perm = p_sds_init->custom_value_char_attr_md.read_perm; attr_md.write_perm = p_sds_init->custom_value_char_attr_md.write_perm; attr_md.vloc = BLE_GATTS_VLOC_STACK; attr_md.rd_auth = 0; attr_md.wr_auth = 0; attr_md.vlen = 0;
ble_gatts_attr_t attr_char_value; memset(&attr_char_value, 0, sizeof(attr_char_value)); attr_char_value.p_uuid = &ble_uuid; attr_char_value.p_attr_md = &attr_md; attr_char_value.init_len = sizeof(uint8_t); attr_char_value.init_offs = 0; attr_char_value.max_len = sizeof(uint8_t);
Also, the characteristics and attributes are often added with different functions, such as:
err_code = sd_ble_gatts_characteristic_add(p_sds->service_handle, &char_md,
&attr_char_value,
&p_sds->custom_value_handles);
or in case of the predefined services BAS and LLS:
return characteristic_add(p_lls->service_handle,
&add_char_params,
&p_lls->alert_level_handles);
I basically want to add three services with multiple characteristics that are all read/write. What I already achieved is to read and write the LLS characteristic with a smartphone app, so it would be most convenient for me to use more or less the kind of characteristics that are added there.
Can someone explain to me what the difference is between those code snippets? And maybe a recommendation on which of that I should use? Or rather how I can implement these read/write characteristics?
Kind regards.