ATT属性table
GATT profile 层次
服务初始化过程:
1.初始化UUID128/16bit UUID,
2.设置为主要服务 BLE_GATTS_SRVC_TYPE_PRIMARY 0x01 /**< Primary Service. */
3.添加服务sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_lbs->service_handle);
service_handle保存 获取来自协议栈的服务。
3.添加特性 led_char_add(p_lbs, p_lbs_init);
特性声明(characteristic Declaration)
Attribute handle Attribute Type attribute value Attribute perimission
特性声明包括:
1.属性值Characteristic Properties(characteristic Properites 1byte charactertic Value Handle 2byte characteristic UUID 2or 16 byte)
2.characteristic Externded Properites
3.characteristic User Description
4.Client Characteristic Configuration
5.Characteristic Presentation format
6. characteristic Aggregate Format
1.在特性声明中 设置
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;
2.设置读写(properties),如果只是读 需要设置设置CCCD
memset(&cccd_md, 0, sizeof(cccd_md));
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&cccd_md.write_perm);
cccd_md.vloc = BLE_GATTS_VLOC_STACK;
如果是写,则不需要,个人理解。
3.设置读写权限,UUID,数据的长度等。
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
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 = NULL;
4.最后增加特性:sd_ble_gatts_characteristic_add(p_lbs->service_handle,
&char_md,
&attr_char_value,
&p_lbs->led_char_handles);