feat(proto): 添加设备通信协议v1修订版及统一帧格式

- 新增docs/device_communication_protocol_v1.md文档,定义V1修订版协议
- CDC和BLE GATT均改为直接传输业务消息,去掉外层协议封装
- BLE改为使用NUS(Nordic UART Service)替代原有GATT服务
- 统一键盘位图为29字节格式,FunctionKeyEvent改为上报全键盘位图
- 顶层消息增加msg_id和reply_to字段用于请求响应匹配
- Ack和Error合并为统一Response消息类型
- CDC和NUS均增加统一外层帧格式:magic(2) + len(1) + protobuf
- 添加Proto frame常量定义及长度验证逻辑
- 更新proto文件定义,包含DeviceMessage统一信封和ResponseCode枚举

- 重构hid_flowctrl_module.c中的上下文访问方式,统一使用ctx前缀
This commit is contained in:
2026-04-24 10:54:14 +08:00
parent 48968e7880
commit 3971d7c4b2
10 changed files with 703 additions and 321 deletions

View File

@@ -1,5 +1,13 @@
syntax = "proto3";
enum ResponseCode {
RESPONSE_CODE_OK = 0;
RESPONSE_CODE_UNKNOWN_TYPE = 1;
RESPONSE_CODE_INVALID_LENGTH = 2;
RESPONSE_CODE_INVALID_PARAM = 3;
RESPONSE_CODE_NOT_READY = 4;
}
message HelloReq {
uint32 protocol_version = 1;
}
@@ -39,24 +47,14 @@ message ThemeRgb {
uint32 blue = 3;
}
message Ack {
uint32 acked_type = 1;
message Response {
ResponseCode error_code = 1;
}
enum ErrorCode {
ERROR_CODE_NONE = 0;
ERROR_CODE_UNKNOWN_TYPE = 1;
ERROR_CODE_INVALID_LENGTH = 2;
ERROR_CODE_INVALID_PARAM = 3;
ERROR_CODE_NOT_READY = 4;
}
message DeviceMessage {
uint32 msg_id = 10;
uint32 reply_to = 11;
message Error {
uint32 error_type = 1;
ErrorCode error_code = 2;
}
message CdcPacketBody {
oneof body {
HelloReq hello_req = 1;
HelloRsp hello_rsp = 2;
@@ -65,7 +63,6 @@ message CdcPacketBody {
LedState led_state = 5;
TimeSync time_sync = 6;
ThemeRgb theme_rgb = 7;
Ack ack = 8;
Error error = 9;
Response response = 8;
}
}