zl程序教程

您现在的位置是:首页 >  其他

当前栏目

一个CH579属性表分析

2023-03-14 22:56:06 时间

关于服务、特特征的声明,查看ble属性格式、权限与声明一文。

1、属性定义

CH579中一条属性的定义如下:

/**
 * GATT Attribute format.
 */
typedef struct attAttribute_t
{
  gattAttrType_t type; //!< Attribute type (2 or 16 octet UUIDs)
  uint8 permissions;   //!< Attribute permissions
  uint16 handle;       //!< Attribute handle - assigned internally by attribute server
  uint8* pValue;       //!< Attribute value - encoding of the octet array is defined in 
                       //!< the applicable profile. The maximum length of an attribute 
                       //!< value shall be 512 octets.
} gattAttribute_t;

2、一个属性表

/*********************************************************************
 * Profile Attributes - Table
 */

static gattAttribute_t simpleProfileAttrTbl[] = 
{
  // Simple Profile Service  服务声明
  { 
    { ATT_BT_UUID_SIZE, primaryServiceUUID }, /* type */
    GATT_PERMIT_READ,                         /* permissions */
    0,                                        /* handle */
    (uint8 *)&simpleProfileService            /* pValue */
  },
  // Characteristic 1 Declaration 特征1声明
  { 
    { ATT_BT_UUID_SIZE, characterUUID },//类型
    GATT_PERMIT_READ,               //权限是可读       
    0,                              //句柄,初始化为0,由协议栈分配
    &simpleProfileChar1Props //值,描述特征值的特性、UUID等
  },

  // Characteristic Value 1   特征1值声明 
  { 
    { ATT_BT_UUID_SIZE, simpleProfilechar1UUID },//类型
    GATT_PERMIT_READ | GATT_PERMIT_WRITE, //权限是可读,可写的    
    0,                           //句柄,初始化为0,由协议栈分配
    simpleProfileChar1           //值,实际用户传输的数据
  },

 // Characteristic 1 User Description  特征1用户描述声明
 { 
  { ATT_BT_UUID_SIZE, charUserDescUUID },
    GATT_PERMIT_READ, 
    0, 
    simpleProfileChar1UserDesp 
  },
        
 // Characteristic 2 Declaration 特征2声明
 { 
    { ATT_BT_UUID_SIZE, characterUUID },
    GATT_PERMIT_READ, 
    0,
    &simpleProfileChar2Props 
 },

 // Characteristic Value 2  特征2值声明
 { 
    { ATT_BT_UUID_SIZE, simpleProfilechar2UUID },
    GATT_PERMIT_READ, 
    0, 
    simpleProfileChar2 
 },

 // Characteristic 2 User Description 特征2用户描述声明
 { 
   { ATT_BT_UUID_SIZE, charUserDescUUID }, 
   GATT_PERMIT_READ,    
   0,                   
   simpleProfileChar2UserDesp //值
 }, 
                 
 // Characteristic 3 Declaration
 { 
   { ATT_BT_UUID_SIZE, characterUUID },
   GATT_PERMIT_READ,     //权限是可读
   0,
   &simpleProfileChar3Props 
 },
 // Characteristic Value 3    
 { 
    { ATT_BT_UUID_SIZE, simpleProfilechar3UUID },
    GATT_PERMIT_WRITE,   //权限是可写
    0, 
    simpleProfileChar3 
 },
 // Characteristic 3 User Description
 { 
   { ATT_BT_UUID_SIZE, charUserDescUUID },
   GATT_PERMIT_READ,   //权限是可读
   0, 
   simpleProfileChar3UserDesp 
 },
 // Characteristic 4 Declaration
 { 
   { ATT_BT_UUID_SIZE, characterUUID },
   GATT_PERMIT_READ,  //权限是可读
   0,
   &simpleProfileChar4Props 
 },
 // Characteristic Value 4
 { 
   { ATT_BT_UUID_SIZE, simpleProfilechar4UUID },
   0, 
   0, 
   simpleProfileChar4 
 },
 // Characteristic 4 configuration
 { 
   { ATT_BT_UUID_SIZE, clientCharCfgUUID },
   GATT_PERMIT_READ | GATT_PERMIT_WRITE, 
   0, 
   (uint8 *)simpleProfileChar4Config 
 },
 // Characteristic 4 User Description
 { 
   { ATT_BT_UUID_SIZE, charUserDescUUID },
   GATT_PERMIT_READ, 
   0, 
   simpleProfileChar4UserDesp 
 }, 
 // Characteristic 5 Declaration
 { 
   { ATT_BT_UUID_SIZE, characterUUID },
   GATT_PERMIT_READ, 
   0,
   &simpleProfileChar5Props 
 },
 // Characteristic Value 5
 { 
   { ATT_BT_UUID_SIZE, simpleProfilechar5UUID },
   GATT_PERMIT_AUTHEN_READ, 
   0, 
   simpleProfileChar5 
 },
 // Characteristic 5 User Description
 { 
   { ATT_BT_UUID_SIZE, charUserDescUUID },
   GATT_PERMIT_READ, 
   0, 
   simpleProfileChar5UserDesp 
 },
};

可以看出: (1)多个属性,构成了上面的属性表,代码中的属性表由17条属性构成; (2)每个属性,都由类型权限句柄,四部分构成; (3)属性表,由服务开始,服务本身的权限是只读,服务本身是一个属性; (4)特征声明后紧跟特征值声明; (5)一个特征由特征声明开始; (6)特征声明本身就是一个属性; (7)特征值声明本身也是一个属性,实际应用传输数据,也是通过特征值传输的; (8)根据属性类型的不同,属性值有可能是UUID、实际传输的值,特性等; (9)特征声明的值是特征值声明属性本身(这句话理解起来有些拗口,参见特征1声明和特征值1声明); (10)特征后面可以跟多个描述属性。

关于特征声明的值,CH579属性表的定义和蓝牙核心的描述略有差异,代码中特征声明的值只有特性,而文档描述在还有特征值句柄,UUID,这里我猜测CH579的协议栈会自动处理吧。