BLE --- ATT/GATT

ATT

ATT 定义了数据交互的协议(PDU、各种命令),和存储在 server 的各种 attribute 格式,即定义了BLE协议栈上层的数据结构和组织方式

PDU 

在ATT层协议框架内,拥有一组属性的设备称为服务端(Server),读写该属性值的设备称为客户端(Client),Server和Client通过ATT PDU进行交互。

PDU格式

PDU类型

PDU类型方向触发响应
Command Client -> Server
Request Client -> Server Response
Response Server -> Client
Notification Server -> Client
Indication Server -> Client Confirmation
Confirmation Client -> Server

它们的区别如下:

客户端发送Request,服务器需要返回一个Response,表明服务器收到了。

服务器发送Indication,客户端需要返回一个Confirmation,表明客户端收到了。

以上两种方式,均是单线程操作,即下一个Request/Indication操作需要在上一个操作收到Response/Confirmation之后才能开始。

客户端发送Command,服务器无需任何返回。

服务器发送Notification,客户端无需任何返回。

因此Command和Notification是不可靠的通信。当通信环境不佳,客户端频繁发送Command,可能发生服务器接收不到或丢弃的情况,Notification也类似。

具体的PDU命令

具体的命令由 Attribute Opcode 指定

atttribute 格式

atttribute 格式如下:

GATT

GATT 位于 ATT 之上,GATT 使用 ATT 协议进行数据交互,GATT 定义一个个attribute实例,组成一个 profile,结构如下:

service definition

A service definition shall contain a service declaration and may contain include definitions and characteristic definitions. The service definition ends before the next service declaration or after the maximum Attribute Handle is reached. Service definitions appear on the server in an order based on Attribute Handle.

service delaration、include definitions、characteristic definitions 都是 attribute

service delaration

inlude definition

characterstic definition

A characteristic definition shall contain a characteristic declaration, a Characteristic Value declaration and may contain characteristic descriptor declarations.

Characteristic declaration

 Characteristic Value declaration

 Characteristic descriptor declarations

Characteristic Extended Properties

Characteristic User Description

Client Characteristic Configuration

 

posted @ 2024-03-28 12:01  流水灯  阅读(54)  评论(0编辑  收藏  举报