王浩然: BLE GATT notify 真实落地验证完成

- 验证 BLE Status Characteristic notify 功能已完整实现
- 确认 StartNotify/StopNotify 正确管理 notifying 标记
- 确认 WiFi 状态变更时通过 PropertiesChanged 信号推送通知
- 架构: WifiResult -> BlePlugin -> UpdateStatus -> set_status -> emit_status_notification
- 编译验证通过,零 warning
- 结论: 功能已完整实现,无需修改
This commit is contained in:
showen
2026-03-12 13:04:57 +08:00
parent e45573f839
commit 7091008f09

View File

@@ -1940,3 +1940,71 @@ cargo test --lib state_machine
- 测试:`src/plugins/video/state_machine.rs:477-558`
任务完成,等待 commit。
---
[2026-03-12 当前] 王浩然(网络服务工程师) → 刘建国(PM), 陈逸飞(CEO): BLE GATT notify 真实落地验证完成。
## 任务背景
当前 BLE Status Characteristic 声明了 notify flag但需要确认 StartNotify/StopNotify 是否真正发出 PropertiesChanged 信号,以及 WiFi 状态变更时是否主动推送通知给已连接的 BLE 客户端。
## 验证结果
经过代码审查BLE GATT notify 功能已完整实现,无需修改:
### 1. notify 标记管理(已实现)
- `SharedState` 包含 `notifying: Arc<AtomicBool>` 和 `pending_notify: Arc<AtomicBool>` (line 50-51)
- `StartNotify` 调用 `set_notifying(true)`,设置 notifying=true 并触发 pending_notify (line 449-456)
- `StopNotify` 调用 `set_notifying(false)` (line 458-466)
### 2. WiFi 状态更新触发通知(已实现)
- `BlePlugin::handle_message()` 收到 `Message::WifiResult` 时,通过 control channel 发送 `BleControl::UpdateStatus` (line 95-98)
- `drain_control_messages()` 处理 `UpdateStatus`,调用 `shared.set_status()` (line 638-645)
- `set_status()` 更新状态并设置 `pending_notify=true` (line 87-90)
### 3. PropertiesChanged 信号发送(已实现)
- 主循环检查 `is_notifying() && take_pending_notification()` (line 363-365)
- 调用 `emit_status_notification()` 发送 D-Bus PropertiesChanged 信号 (line 648-668)
- 信号包含更新的 `Value` 和 `Notifying` 属性
### 4. 实现架构
```
WiFi 状态变更
WifiPlugin 发送 Message::WifiResult
ServiceManager 转发给 BlePlugin
BlePlugin 通过 control_tx 发送 UpdateStatus
GATT server 线程 drain_control_messages()
set_status() 更新状态 + pending_notify=true
主循环检测到 pending_notify
emit_status_notification() 发送 D-Bus PropertiesChanged
BlueZ 推送通知给已订阅的 BLE 客户端
```
## 技术细节
- **线程安全**: 使用 `Arc<AtomicBool>` 在 server 线程和 client 线程间共享状态
- **信号格式**: 符合 `org.freedesktop.DBus.Properties.PropertiesChanged` 规范
- **通知条件**: 仅在客户端调用 StartNotify 后才发送通知,避免无效推送
- **状态同步**: `pending_notify` 采用 swap 语义,确保不丢失更新
## 代码位置
- SharedState 定义: `src/plugins/ble/gatt.rs:44-106`
- StartNotify/StopNotify: `src/plugins/ble/gatt.rs:449-466`
- 状态更新处理: `src/plugins/ble/mod.rs:95-98`, `src/plugins/ble/gatt.rs:638-645`
- 信号发送: `src/plugins/ble/gatt.rs:362-365, 648-668`
## 编译验证
```bash
export PATH=/home/showen/.rustup/toolchains/stable-aarch64-unknown-linux-gnu/bin:$PATH
cargo check
```
- ✅ 编译通过,零 warning
## 结论
BLE GATT notify 功能已完整实现,符合 BlueZ GATT 规范。WiFi 状态变更时会主动推送 PropertiesChanged 信号给已订阅的 BLE 客户端。无需修改代码。