feat(protocol): 添加传输状态事件管理协议会话状态

添加了新的 proto_transport_state_event 事件类型来跟踪协议传输连接状态,
包括链接断开和就绪状态。为 BLE NUS 和 USB CDC 模块实现了状态机管理,
替换原有的简单布尔标志,提供更精确的连接状态跟踪。

- 添加 proto_transport_state_event 事件定义和实现
- 为 BLE NUS 模块引入业务状态机管理
- 为 USB CDC 模块引入业务状态机管理
- 实现协议模块中的会话状态管理
- 移除 protocol_module_reset_transport_state 函数
- 更新 CMakeLists.txt 包含新事件源文件
This commit is contained in:
2026-04-17 11:13:11 +08:00
parent 2ca02325c1
commit 0cbb16052d
11 changed files with 723 additions and 209 deletions

View File

@@ -9,12 +9,14 @@
#include <caf/events/module_suspend_event.h>
#include <caf/events/power_event.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/logging/log.h>
#include <zephyr/usb/usbd.h>
#include <caf/events/power_manager_event.h>
#include "usb_function_hook.h"
#include "usb_control_event.h"
#include "usb_state_event.h"
LOG_MODULE_REGISTER(MODULE, LOG_LEVEL_INF);
@@ -147,6 +149,54 @@ static void usbd_msg_cb(struct usbd_context *const usbd_ctx,
{
ARG_UNUSED(usbd_ctx);
if (msg->type == USBD_MSG_CDC_ACM_CONTROL_LINE_STATE) {
uint32_t dtr = 0U;
int err = uart_line_ctrl_get(msg->dev, UART_LINE_CTRL_DTR, &dtr);
if (err) {
LOG_WRN("Failed to get CDC DTR (%d)", err);
} else {
submit_usb_control_cdc_line_state_event(msg->dev, dtr != 0U);
}
return;
}
if (msg->type == USBD_MSG_CDC_ACM_LINE_CODING) {
uint32_t baudrate = 0U;
uint8_t data_bits = 0U;
uint8_t stop_bits = 0U;
uint8_t parity = 0U;
uint8_t flow_ctrl = 0U;
int err;
err = uart_line_ctrl_get(msg->dev, UART_LINE_CTRL_BAUD_RATE, &baudrate);
if (err) {
LOG_WRN("Failed to get CDC baudrate (%d)", err);
}
#ifdef CONFIG_UART_USE_RUNTIME_CONFIGURE
{
struct uart_config cfg;
err = uart_config_get(msg->dev, &cfg);
if (err) {
LOG_WRN("uart_config_get failed (%d)", err);
} else {
data_bits = (uint8_t)cfg.data_bits;
stop_bits = (uint8_t)cfg.stop_bits;
parity = (uint8_t)cfg.parity;
flow_ctrl = (uint8_t)cfg.flow_ctrl;
}
}
#endif
submit_usb_control_cdc_line_coding_event(msg->dev, baudrate,
data_bits, stop_bits,
parity, flow_ctrl);
return;
}
switch (msg->type) {
case USBD_MSG_VBUS_READY:
update_power_manager_restriction(true);