Advertisement

【Bluetooth蓝牙开发】九、BLE协议之GATT

阅读量:
img

个人主页:董哥聊技术 我是董哥,在嵌入式领域新兴着一个新的创作者群体 创作理念:专注于分享优质的嵌入式文章内容,并希望能让读者有所收获

img

所有文章汇总

文章目录

    • 1、简介

      • 角色的定义
    • 2、GATT协议框架

      • 2.1 Profile
      • 2.2 Service
        • 2.2.1 Service 定义
    • 2.2.2 Service 声明

      • 2.3 include
        • 2.3.1 include 定义
    • 2.3.2 include 声明

  • The fundamental characteristics are defined as follows.

    • The characteristics are formally declared in this section.

    • The characteristic values are explicitly stated here.

    • A detailed descriptor of the characteristics is provided below.

    • 3、参考资料

img

由于其抽象性较高,在技术实现上较为基础。尽管如此,在这一框架下所制定的一系列机制能够实现客户与服务器之间基于属性的形式化信息共享。值得注意的是,在这种机制下具体共享哪些信息完全由该框架自主决定,并不在当前体系中进行规范——这正是 GATT (Generic Attribute Profile)所关注的重点领域所在。
相比之下,相比传统的 ATT 而言,GATT 增加了一个字母 'G' 的标识符,在这一额外的维度中所承载的内容与前者有着本质区别——具体而言,“GATT”实际上相当于一个 profile framework(更为精确地说,则是一个 profile framework 的延伸)。这使得 GATT 在功能定位上与 ATT 形成鲜明对比。

1、简介

GATTGeneric Attributes通用属性,低功耗蓝牙的设备之间的通信协议

The Generic Attribute Profile (GATT) formalizes a formal service architecture based on the Attribute Protocol.

GATT基于ATT协议构建了一个服务架构,在信息处理与管理方面具有明确的功能划分

角色的定义

为了更好的实现GATTprofile概要文件,GATT定义了如下角色:

  • Client 负责向服务器提交命令与请求,并获取服务器的回应。
    • Server 负责回应来自客户端的命令与请求,并传递相应的结果。
image-20220816110411500

2、GATT协议框架

该GATT Profile规范了用于通信的数据结构, 其中涉及的服务和特性。

image-20220816111254549

通过查看上图可以看出,在GATT profile中,默认值采用的方式依次为Profile→Service→characteristic

最顶层的是profile,一个profile由一个或者多个service组成。

一个service又由characteristics组成。

每个characteristicpropertyvaluedescriptor组成。

2.1 Profile

The GATT Profile is a standard communication protocol encapsulated within the host device. It establishes the corresponding operational procedures for broadcasting, disseminating, and managing relevant attribute information via the ATT protocol.

完整的Attribute Type的类型如下图

image

2.2 Service

2.2.1 Service 定义

Service服务是完成特定功能或特性的数据和相关行为的集合

在BLE主控单元中,在采用多组服务的基础上(如电量信息、系统信息等),每组服务又包含了若干特征量;而每个具体特征量才是BLE通信的核心内容。

比如当前电量状态为80%,因此会利用电量的characteristic特征值存于从机的profile中。从而主机能够利用该特征值获取准确的数据信息。

包含一个Service的定义涉及:其声明为Service说明项;(可选)其include说明项;以及(可选)其characteristic说明项。

2.2.2 Service 声明

Service Declaration如下

image-20220817113245091

Attribute Type:服务类型分为两类,即primary servicesecondary service(首要服务与次要服务),它们的具体Attribute Type分别为0x28000x2801(具体为Service 1和Service 2)。

Attribute Value :是一个16位UUID或者128位的UUID。用来表示这是什么服务。

Attribute permission设置 表明该声明中包含一个属性权限设置项,并且该ATT属性被指定为只读状态且不需要进行验证或授权。

2.3 include

2.3.1 include 定义

include用于去引用已定义存在的服务,相当于C语言中的include包含。

include定义仅仅包含一个include Declaration。

2.3.2 include 声明

include Declaration如下:

image-20220817113623137
  • 属性类型字段值设置为Include。
    • 指定属性值字段需设置以下三个参数:
      • 包含所需的引用服务的Handle字段
      • 包含所需的引用Group的结束Handle字段
      • 提供唯一标识符
    • 此字段仅用于标识相关声明是否可读或可操作。

2.4 Characteristic

2.4.1 Characteristic 定义

characteristic包含了特征和值的定义。

BLE主从机的通信主要基于characteristic这一特性作为手段使用,在协议设计中将其视为一个标识符来完成数据传输操作。

定义中包含三个关键术语:特征声明式、特征值声明式以及特征描述式声明。其中前两项为必填项(必填项),最后一项为可选项(可选项)。

char = char·宣告 + char值·宣告 + 附带可选描述.

2.4.2 Characteristic 声明

Characteristic declaration如下:

image-20220823112540864
  • Service Category:服务类型为Characteristic type ,对应的Associated Attribute Type0x2803
    • Attribute Values:设置为CharacteristicsCharacteristics Value Attribute Handle Variable NameCharacteristics UUID
    • Attribute Permissions:表示该声明即该ATT属性是仅读的且无需验证及授权。

Attribute Value字段如下

image-20220830144354273

每个服务都可能使用多个characteristic definitions共享同一个Characteristic UUID

  • Characteristic Properties字段如下:
image-20220823112852622

Characteristic Value Attribute Handle 包含用于表示特征值相关属性的句柄

Characteristic UUID :是一个16位UUID或者128位的UUID

2.4.3 Characteristic Value 声明

Characteristic Value Declaration 如下

image-20220830145329585

Characteristic Valuecharacteristic声明后的第一个属性。

  • Attribute Type :该字段的值对应于在Characteristic声明时所使用的UUID
  • Attribute Value :其值对应于所述同一或相同的UUID所关联的属性实例。
  • Attribute permission :其权限由上层权限决定了。

其与Characteristic Declaration关系如下

image
2.4.4 Characteristic Descriptor 声明

These descriptors are primarily designed to encompass a range of information tied to their corresponding characteristic values. GATT has formalized a set of optional descriptors.

image-20220830150336139

每一种descriptor都有其特有的格式。

Characteristic User Description为例:

image
  • Attribute Type:该字段被设置为Characteristic user description,对应的值是0x2901
    • Attribute Value:定义的信息
    • Attribute permission:由上级权限指定

3、参考资料

[1]:

img
img

全部评论 (0)

还没有任何评论哟~