当前位置:网站首页>Bluetooth development (11) -- ble interacts happily
Bluetooth development (11) -- ble interacts happily
2022-06-11 00:09:00 【yuanyun_ elber】
The previous chapter mobile phones and flip4 A connection has been established , The next packet format is data channel pdu 了 .
Data channel pdu The format is as follows :

We said before , Unlike classic Bluetooth ,LE only one header, and BR There are two Baotou ——packet header and payload header, Actually... Here LLID Be similar to BR Of payload header Medium LLID, there NESN and SN Be similar to BR Of packet header Medium SEQN, Of course, it's not exactly the same , Both the sender and the receiver of the former maintain one sequence number The latter is obviously maintained by only one party .
Similar to classic Bluetooth ,data channel pdu Also according to header Medium LLID Divide into control pdu and data pdu Two kinds of .
After the connection is established ,master and slave Will pass LLCP(link layer control protocl), adopt control pdu Control the connection .
control pdu The format is as follows :

among opcode Indicates the type of control package .
Let's see , After this connection , The two sides through LLCP The protocol interacts with some information .

Then you can go through data pdu To interact with the upper level information .

The first is a att exchange mtu Of , This is a mobile notification flip4 Its maximum reception MTU size Of . Notice the red line , First LLID It indicates that this package is a data pdu, then l2cap Layer of cid Seems to be fixed Of 0x4, Said is att package ,att payload Of opcode It means it's a exchange mtu request, Mobile phone mtu yes 185. bluetooth 4.0 The previous standard ,mtu Only 23 byte , This mtu Used to do OTA The application of firmware upgrade is really slow ,4.2 after mtu To expand to 255 byte .
After the exchange MTU after , Mobile phones need to know flip4 This server Supported services 、 characteristic 、 Feature description and other information , It is similar to the classic Bluetooth sdp link .
First you need to get service, obtain service There are two ways , First, access to all services , One is based on uuid Access to services , The method selected here is the former , The process goes like this :

First sent att_read_by_group_type_req Of start handle It must be 1,end handle yes 0xffff,attribute type yes primary service(2800), then server The terminal will start from handle 1 Search service , stay att_read_by_group_type_rsp Found in the reply service, Because I can't reply all at once , So this process needs to be executed circularly , The next time the mobile terminal sends att_read_by_group_type_req Packet start handle Than att_read_by_group_type_rsp Of end handle Add 1.
Let's see flip4 Your first reply :

This reply contains two primary service, Let's put it on record , Three times in total service After searching , a sheet service The list will be displayed :
Handle | Attribute Type | Attribute Value |
1 | 2800(primary service, Bluetooth association regulations assigned numbers) | 1801(GATT service, Bluetooth association regulations assigned numbers) |
5 | 2800 | 1800(GAP service, Bluetooth association regulations assigned numbers) |
10 | 2800 | 65786365-6C70-6F69-6E74-2E636F6D0000 |
16 | 2800 | Fe8f |
We know profile yes service Set , Find all service after , You also need to find each service Subset , Include include、characteristic wait , The commands used are ATT_READ_BY_TYPE_REQ.
If you find characteristic, And find characteristic descriptor wait , The command used is ATT_FIND_INFOMATION_REQ.
include It means that we should service Include others service, This process is called relationship discovery, We don't have this process here .
Characteristic It's more important , because service yes characteristic Set .
This process is called characteristic discovery:

Look what we found characteristic, By format , Found characteristic, Is itself a attribute,
Yes 2 Bytes of attribute handel, Here is 2,attribute type yes 2803(characteristic, This is in att_read_by_type_req It contains , Not looking for anything else ),attribute value Include 1 Bytes of property( Determines the read and write permissions, etc ),2 Bytes of value handle(0003), and 2 Bytes bluetooth UUID(2a05),assigned numbers Express service changed.

I usually find characteristic After that, I followed closely characteristic descriptor:

Last , We have formed a service Summary of :
Handle | Attribute Type | Attribute Value |
1 | 2800(primary service, Bluetooth association regulations assigned numbers) | 1801(GATT service, Bluetooth association regulations assigned numbers) |
2 | 2803(characteristic) | {20,0003,service changed} |
5 | 2800(primary service) | 1800(GAP service, Bluetooth association regulations assigned numbers) |
10 | 2800(primary service) | 65786365-6C70-6F69-6E74-2E636F6D0000 |
11 | 2803(characteristic) | {12(read,notify), 000c, 65786365-6C70-6F69-6E74-2E636F6D0001} |
14 | 2803(characteristic) | {08(write), 000f, 65786365-6C70-6F69-6E74-2E636F6D0002} |
16 | 2800(primary service) | Fe8f |
It can be seen from this table that ,10 Number service It is the core of our reading and writing services service, among , Yes 0x000c Number handle Can be used to read data ,0x000f Number handle Can be used to write data , As you can see below app Just use these two handle Number and flip4 Interact :
This is what I received notify Data packets :

This is a write Data packets of :

Specific data format , It's the top app Need to be concerned about , It's not about the protocol .
边栏推荐
- MultipartFile重命名上传
- Serial port missing in Ni Max in LabVIEW
- 763. 划分字母区间
- Error 1046 when LabVIEW uses MathScript node or matlab script
- Typecho blog site wide deployment of Tencent cloud CDN tutorial - Xingze V Club
- [pyGame games] interesting puzzle game: how many hamsters can you play? (source code attached)
- [auto reply Script] happy new year. I typed every word myself, not forwarded it~
- Lambda 学习记录
- 【Turtle表白合集】“海底月是天上月,眼前人是心上人。”余生多喜乐,长平安~(附3款源码)
- vtk.js中vtp下载
猜你喜欢

LabVIEW prohibits other multi-core processing applications from executing on all cores

Easyrecovery15 simple and convenient data recovery tool

【AI出牌器】第一次见这么“刺激”的斗地主,胜率高的关键因素竟是......
![[pyGame] when the](/img/7e/d2cd2eb2fff2c1fb2b41f579d4f70e.png)
[pyGame] when the "coolest snake in history" arrives, fun will play it (no money for fun)

IGBT and third generation semiconductor SiC double pulse test scheme

LabVIEW phase locked loop (PLL)

How to check the variable waveform when debugging the program? Look here

【自动回复or提醒小助手】妈妈再也不用担心我漏掉消息了(10行代码系列)

It is said that the verification code is a barrier in the crawler. I can break through it with only five lines of code.

LabVIEW open other exe programs
随机推荐
Flowable process deployment
LabVIEW and VDM extract color and generate gray image
Typecho website speed optimization - Xingze V Club
[new version] new pseudo personal homepage v2.0- starze V Club
Chapter 2 application layer 2.4 DNS
[pyGame collection] please check the game guide through childhood: are there any games you have played? (attach five source codes for self access)
How to check the variable waveform when debugging the program? Look here
IGBT与三代半导体SiC双脉冲测试方案
Insert sort
Why is the website snapshot hijacked and tampered with
File转为MultipartFile的方法
【Go语言学习】——并发编程
phpstudy的安装
Wireshake introduction learning notes
【Pygame小游戏】来了来了它来了——这款五子棋小游戏超A的,分享给你的小伙伴儿一起pk吧~
Pseudo static setting of Typecho - starze V Club
Compared with the "South-to-North Water Transfer", what will the "east to west" of the fire bring to cloud computing?
Quick sort
Several common current transformer sampling circuits
Go语言Channel理解使用