Discuz! Board
标题:
如何在公有服务里添加自定义的特征?
[打印本页]
作者:
luobotia
时间:
2018-5-30 10:54
标题:
如何在公有服务里添加自定义的特征?
官方例程:nRF5_SDK_12.2.0_f012efa\examples\ble_peripheral\ble_app_proximity
下面是我修改的地方:
1. 添加特征
static uint32_t alert_duration_char_add(ble_lls_t * p_lls, const ble_lls_init_t * p_lls_init)
{
ble_gatts_char_md_t char_md;
ble_gatts_attr_t attr_char_value;
ble_uuid_t ble_uuid;
ble_gatts_attr_md_t attr_md;
uint8_t initial_alert_duration;
memset(&char_md, 0, sizeof(char_md));
char_md.char_props.read = 1;
char_md.char_props.write = 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 = NULL;
char_md.p_sccd_md = NULL;
BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_ALERT_DURATION_CHAR);
memset(&attr_md, 0, sizeof(attr_md));
attr_md.read_perm = p_lls_init->lls_attr_md.read_perm;
attr_md.write_perm = p_lls_init->lls_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;
memset(&attr_char_value, 0, sizeof(attr_char_value));
initial_alert_duration = p_lls_init->initial_alert_duration;
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);
attr_char_value.p_value = &initial_alert_duration;
return sd_ble_gatts_characteristic_add(p_lls->service_handle,
&char_md,
&attr_char_value,
&p_lls->alert_duration_handles
);
}
2. 初始化服务
uint32_t ble_lls_init(ble_lls_t * p_lls, const ble_lls_init_t * p_lls_init)
{
uint32_t err_code;
ble_uuid_t ble_uuid;
// Initialize service structure
if (p_lls_init->evt_handler == NULL)
{
return NRF_ERROR_INVALID_PARAM;
}
p_lls->evt_handler = p_lls_init->evt_handler;
p_lls->error_handler = p_lls_init->error_handler;
// Add service
BLE_UUID_BLE_ASSIGN(ble_uuid, BLE_UUID_LINK_LOSS_SERVICE);
err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
&ble_uuid,
&p_lls->service_handle);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
// Add alert level characteristic
err_code = alert_level_char_add(p_lls, p_lls_init);
VERIFY_SUCCESS(err_code);
// Add alert duration characteristic
err_code = alert_duration_char_add(p_lls, p_lls_init);
VERIFY_SUCCESS(err_code);
return NRF_SUCCESS;
}
3. 定义UUID:
#define BLE_UUID_ALERT_DURATION_CHAR 0x5A11
以上是我的修改配置。打开手机APP却看不到增加的特征,这是为什么 呢??求指教
欢迎光临 Discuz! Board (http://qfv8.com/)
Powered by Discuz! X3