3. 消息类型

通信过程采用 Request - Response, Indication 这种组合。

消息类型

方向

Write Characteristic

Indication Characteristic

Request

手机 -> 设备

Y

Response

手机 <- 设备

Y

Indication

手机 <- 设备

Y

如果手机未能收到测量结果,也可以通过Read获取最后一次的结果。

3.1. 向设备发送命令

!pragma teoz true
participant 手机 as P #cyan
box 设备 #LightBlue
box BLE
participant Write as W #khaki
participant Indication as I  #lightgreen
end box
participant MCU as M #deepskyblue
end box

autonumber
...
note over P,I: BLE已连接
P ->(10) W : Request( timeout, ...)
W -> M :
M -> I :
P (10)<- I : Response( error )

3.2. 设备返回测量结果

!pragma teoz true
participant 手机 as P #cyan
box 设备 #LightBlue
box BLE
participant Write as W #khaki
participant Indication as I  #lightgreen
end box
participant MCU as M #deepskyblue
end box

autonumber
...
note over P,I: BLE已连接
...
M -> I :
P (10)<- I : Indication( result )