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:
@@ -16,6 +16,11 @@ enum proto_transport_link_state {
|
||||
PROTO_TRANSPORT_LINK_READY,
|
||||
};
|
||||
|
||||
#define PROTO_FRAME_MAGIC 0xAA55U
|
||||
#define PROTO_FRAME_HEADER_SIZE 3U
|
||||
#define PROTO_MAX_PAYLOAD_LEN 64U
|
||||
#define PROTO_MAX_FRAME_LEN (PROTO_FRAME_HEADER_SIZE + PROTO_MAX_PAYLOAD_LEN)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -28,7 +28,8 @@ static inline int submit_proto_rx_event(enum proto_transport transport,
|
||||
struct proto_rx_event *event;
|
||||
|
||||
if ((transport >= PROTO_TRANSPORT_COUNT) ||
|
||||
((data == NULL) && (len > 0U))) {
|
||||
((data == NULL) && (len > 0U)) ||
|
||||
(len > PROTO_MAX_FRAME_LEN)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,8 @@ static inline int submit_proto_tx_event(enum proto_transport transport,
|
||||
struct proto_tx_event *event;
|
||||
|
||||
if ((transport >= PROTO_TRANSPORT_COUNT) ||
|
||||
((data == NULL) && (len > 0U))) {
|
||||
((data == NULL) && (len > 0U)) ||
|
||||
(len > PROTO_MAX_FRAME_LEN)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user