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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
2017-03-28 C语音之static关键字用途
2017-03-28 裸机算法之按键检测