gatt profile 理解

gatt profile 理解

2016年09月05日 16:35:19 nanjoh 阅读数 2967

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);

 

 

首先你要了解一个GATT profile的框架分类,

                                                                   UUID

 1.primary service                                 0x2800

 2.sencondary service                         0x2801

 3.include                                               0x2802

 4.characteristic                                    0x2803

 5.characteristic extended property    0x2900

6.characteristic user description       0x2901

7.client characteristic configuration   0x2902

8.server characteristic configuration  0x2903

9.characteristic format                          0x2904

10. characteristic aggregate format    0x2905

要理解,cilent想找到你定义的东西,就必须要通过primary service中的UUID来识别。

在你的代码中, primary service的属性是只读。characteristic  Declaration中就是我上面的characteristic(4)它的属性是只读,UUID应该是0x2803.

依次类推,有的characteristic不是一定要定义的,是可选的,所以有的service 只有一个characteristic 或者2个characteristic。。。。

说了这些,你还是多看看资料。 蓝牙4.0的那个协议spec~!

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值