feat: DevicePlugin Task1 — Message enum扩展(DeviceCommand/Response/Event + 7个辅助类型)
This commit is contained in:
@@ -2129,3 +2129,51 @@ ShowenV2 当前版本已达到 **生产就绪** 标准:
|
|||||||
- **P2**: 建议增加 BLE/WiFi 硬件测试,验证实际设备连接
|
- **P2**: 建议增加 BLE/WiFi 硬件测试,验证实际设备连接
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
[2026-03-13 当前] 张明远(内核工程师) → 刘建国(PM), 陈逸飞(CEO): DevicePlugin 阶段一 Task 1 已完成。
|
||||||
|
|
||||||
|
## 任务完成情况
|
||||||
|
|
||||||
|
已完成 DevicePlugin 阶段一 Task 1:Message enum 扩展。
|
||||||
|
|
||||||
|
### 修改内容
|
||||||
|
|
||||||
|
1. **在 src/core/message.rs 中添加了以下类型**:
|
||||||
|
- `PixelFormat` enum:RGBA8888, RGB888, RGB565
|
||||||
|
- `SensorType` enum:Temperature, Humidity, Light, Proximity
|
||||||
|
- `TouchAction` enum:Down, Move, Up
|
||||||
|
- `DeviceCapability` enum:Display, Touch, Buttons, Audio, Battery, Backlight, Sensors, Framebuffer, GPIO
|
||||||
|
- `DeviceCommand` enum:12个命令变体(GetDisplayInfo, SetBrightness, SetBacklight, WriteFramebuffer, SetSleepInhibit, GetBatteryLevel, SetVolume, PlayAudio, GetTouchEvents, GetButtonState, GetSensorData, CustomCommand)
|
||||||
|
- `DeviceResponse` enum:6个响应变体(DisplayInfo, SensorData, BatteryLevel, Ok, Error, Custom)
|
||||||
|
- `DeviceEvent` enum:6个事件变体(TouchEvent, ButtonEvent, BatteryLow, DisplayConnected, DisplayDisconnected, SensorAlert)
|
||||||
|
|
||||||
|
2. **在 Message enum 中添加了三个新变体**:
|
||||||
|
- `DeviceCommand(DeviceCommand)`
|
||||||
|
- `DeviceResponse(DeviceResponse)`
|
||||||
|
- `DeviceEvent(DeviceEvent)`
|
||||||
|
|
||||||
|
3. **修复了 src/core/tests.rs**:
|
||||||
|
- 在 `message_label()` 函数中添加了对三个新消息变体的处理,修复了 match 穷尽性检查错误
|
||||||
|
|
||||||
|
### 验证结果
|
||||||
|
|
||||||
|
- ✅ `cargo check --workspace --all-targets` 通过,零 warning
|
||||||
|
- ✅ `cargo test --workspace` 全部通过(66个测试)
|
||||||
|
- ✅ 所有新类型正确派生 Debug, Clone, Serialize, Deserialize
|
||||||
|
- ✅ DeviceCommand 包含 12 个变体(超过要求的 5 个)
|
||||||
|
- ✅ DeviceResponse 包含 6 个变体(超过要求的 3 个)
|
||||||
|
- ✅ DeviceEvent 包含 6 个变体
|
||||||
|
- ✅ 所有类型都有清晰的中文文档注释
|
||||||
|
|
||||||
|
### 技术要点
|
||||||
|
|
||||||
|
- 所有设备相关类型都支持跨 FFI 边界序列化(Serialize + Deserialize)
|
||||||
|
- 枚举设计遵循设计文档第4节的规范
|
||||||
|
- 为未来扩展预留了 CustomCommand 和 Custom 响应类型
|
||||||
|
- 完整覆盖了显示、输入、音频、电源、传感器等设备能力
|
||||||
|
|
||||||
|
### 下一步
|
||||||
|
|
||||||
|
Task 1 已完成,可以进入 Task 2(DevicePlugin 骨架与 Backend trait),建议由架构师王思远负责。
|
||||||
|
|
||||||
|
---
|
||||||
|
|||||||
@@ -46,3 +46,16 @@
|
|||||||
- 熟悉 ServiceManager 全部生命周期代码
|
- 熟悉 ServiceManager 全部生命周期代码
|
||||||
- 熟悉 VersionManager rollback 流程
|
- 熟悉 VersionManager rollback 流程
|
||||||
- 熟悉动态插件错误策略框架
|
- 熟悉动态插件错误策略框架
|
||||||
|
- 熟悉 Message enum 扩展和跨 FFI 边界的序列化要求
|
||||||
|
|
||||||
|
## 个人经验 (2026-03-13)
|
||||||
|
- 修复了 P0 #3 AutoRollback:ServiceManager 需要持有 VersionManager 引用才能执行回退
|
||||||
|
- PluginState 增加 pending_rollback 标记供下次启动时处理
|
||||||
|
- 并发修改 repo 时要注意文件锁竞争(cargo build 会 block)
|
||||||
|
- set_version_manager 方法需要 cfg(not(test)) 保护
|
||||||
|
- 完成 DevicePlugin 阶段一 Task 1:Message enum 扩展
|
||||||
|
- 添加了 DeviceCommand/DeviceResponse/DeviceEvent 三个核心 enum
|
||||||
|
- 添加了 PixelFormat/SensorType/TouchAction/DeviceCapability 辅助类型
|
||||||
|
- 所有类型正确派生 Debug, Clone, Serialize, Deserialize(跨 FFI 要求)
|
||||||
|
- 修复了 tests.rs 中的 match 穷尽性检查(新增三个 message 变体)
|
||||||
|
- cargo check 零 warning,cargo test 全部通过(66 个测试)
|
||||||
|
|||||||
@@ -56,6 +56,11 @@ pub enum Message {
|
|||||||
Shutdown,
|
Shutdown,
|
||||||
PluginReady(String),
|
PluginReady(String),
|
||||||
|
|
||||||
|
// ── 设备管理 ──
|
||||||
|
DeviceCommand(DeviceCommand),
|
||||||
|
DeviceResponse(DeviceResponse),
|
||||||
|
DeviceEvent(DeviceEvent),
|
||||||
|
|
||||||
// ── 扩展(未来插件用) ──
|
// ── 扩展(未来插件用) ──
|
||||||
Custom {
|
Custom {
|
||||||
kind: String,
|
kind: String,
|
||||||
@@ -91,3 +96,133 @@ pub enum WifiCommand {
|
|||||||
ApStart { ssid: String, password: String },
|
ApStart { ssid: String, password: String },
|
||||||
ApStop,
|
ApStop,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── 设备管理 ──
|
||||||
|
|
||||||
|
/// 像素格式
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub enum PixelFormat {
|
||||||
|
/// RGBA 8888 格式(每像素 4 字节)
|
||||||
|
RGBA8888,
|
||||||
|
/// RGB 888 格式(每像素 3 字节)
|
||||||
|
RGB888,
|
||||||
|
/// RGB 565 格式(每像素 2 字节)
|
||||||
|
RGB565,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 传感器类型
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub enum SensorType {
|
||||||
|
/// 温度传感器
|
||||||
|
Temperature,
|
||||||
|
/// 湿度传感器
|
||||||
|
Humidity,
|
||||||
|
/// 光线传感器
|
||||||
|
Light,
|
||||||
|
/// 接近传感器
|
||||||
|
Proximity,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 触摸动作
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub enum TouchAction {
|
||||||
|
/// 按下
|
||||||
|
Down,
|
||||||
|
/// 移动
|
||||||
|
Move,
|
||||||
|
/// 抬起
|
||||||
|
Up,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 设备能力
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub enum DeviceCapability {
|
||||||
|
/// 显示屏
|
||||||
|
Display,
|
||||||
|
/// 触摸屏
|
||||||
|
Touch,
|
||||||
|
/// 按钮
|
||||||
|
Buttons,
|
||||||
|
/// 音频
|
||||||
|
Audio,
|
||||||
|
/// 电池
|
||||||
|
Battery,
|
||||||
|
/// 背光
|
||||||
|
Backlight,
|
||||||
|
/// 传感器
|
||||||
|
Sensors,
|
||||||
|
/// 帧缓冲
|
||||||
|
Framebuffer,
|
||||||
|
/// GPIO
|
||||||
|
GPIO,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 设备命令(业务插件 → DevicePlugin)
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub enum DeviceCommand {
|
||||||
|
/// 获取显示信息
|
||||||
|
GetDisplayInfo,
|
||||||
|
/// 设置亮度(0-100)
|
||||||
|
SetBrightness(u8),
|
||||||
|
/// 设置背光开关
|
||||||
|
SetBacklight(bool),
|
||||||
|
/// 写入帧缓冲
|
||||||
|
WriteFramebuffer { data: Vec<u8>, format: PixelFormat },
|
||||||
|
/// 设置防息屏
|
||||||
|
SetSleepInhibit(bool),
|
||||||
|
/// 获取电池电量
|
||||||
|
GetBatteryLevel,
|
||||||
|
/// 设置音量(0-100)
|
||||||
|
SetVolume(u8),
|
||||||
|
/// 播放音频
|
||||||
|
PlayAudio { path: String },
|
||||||
|
/// 获取触摸事件
|
||||||
|
GetTouchEvents,
|
||||||
|
/// 获取按钮状态
|
||||||
|
GetButtonState,
|
||||||
|
/// 获取传感器数据
|
||||||
|
GetSensorData(SensorType),
|
||||||
|
/// 自定义命令
|
||||||
|
CustomCommand {
|
||||||
|
subsystem: String,
|
||||||
|
payload: serde_json::Value,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 设备响应(DevicePlugin → 请求者)
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub enum DeviceResponse {
|
||||||
|
/// 显示信息
|
||||||
|
DisplayInfo {
|
||||||
|
width: u32,
|
||||||
|
height: u32,
|
||||||
|
format: PixelFormat,
|
||||||
|
},
|
||||||
|
/// 传感器数据
|
||||||
|
SensorData { sensor: SensorType, value: f64 },
|
||||||
|
/// 电池电量(0-100)
|
||||||
|
BatteryLevel(u8),
|
||||||
|
/// 操作成功
|
||||||
|
Ok,
|
||||||
|
/// 操作失败
|
||||||
|
Error(String),
|
||||||
|
/// 自定义响应
|
||||||
|
Custom(serde_json::Value),
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 设备事件(DevicePlugin → 广播)
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub enum DeviceEvent {
|
||||||
|
/// 触摸事件
|
||||||
|
TouchEvent { x: i32, y: i32, action: TouchAction },
|
||||||
|
/// 按钮事件
|
||||||
|
ButtonEvent { button: u8, pressed: bool },
|
||||||
|
/// 电池电量低
|
||||||
|
BatteryLow(u8),
|
||||||
|
/// 显示器已连接
|
||||||
|
DisplayConnected,
|
||||||
|
/// 显示器已断开
|
||||||
|
DisplayDisconnected,
|
||||||
|
/// 传感器警报
|
||||||
|
SensorAlert { sensor: SensorType, value: f64 },
|
||||||
|
}
|
||||||
|
|||||||
@@ -77,6 +77,9 @@ fn message_label(message: &Message) -> String {
|
|||||||
Message::ScreenLockRequest(value) => format!("screen_lock:{value}"),
|
Message::ScreenLockRequest(value) => format!("screen_lock:{value}"),
|
||||||
Message::CursorVisibility(value) => format!("cursor_visibility:{value}"),
|
Message::CursorVisibility(value) => format!("cursor_visibility:{value}"),
|
||||||
Message::WifiCommand(_) => "wifi_command".to_string(),
|
Message::WifiCommand(_) => "wifi_command".to_string(),
|
||||||
|
Message::DeviceCommand(_) => "device_command".to_string(),
|
||||||
|
Message::DeviceResponse(_) => "device_response".to_string(),
|
||||||
|
Message::DeviceEvent(_) => "device_event".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user