feat(mode_switch): 添加无效模式枚举值并更新事件处理
添加 MODE_SWITCH_INVALID 枚举值到 mode_switch_mode 中, 用于表示无效的模式状态。同时更新相关的事件处理逻辑, 确保在模式切换时能够正确处理无效模式的情况。 refactor(mode_policy): 简化模块上下文结构并优化模式策略 将模块上下文中的 ble_adv_suspended 和 usb_enabled 标志位 替换为 active_mode 枚举值,简化了数据结构。重新设计了 模式策略应用逻辑,使其更清晰易懂,并改进了BLE和USB设备 的启用/暂停控制流程。 refactor(usb_device): 重构USB设备生命周期管理 移除了 USB_STACK_DISABLED 状态,简化了USB栈的状态管理。 改进了USB设备的启动和停止逻辑,更好地与模块生命周期 集成。现在USB状态事件仅在模块初始化后提交,避免了 不必要的事件发布。 feat(logging): 增加详细的状态转换日志记录 为BLE NUS模块添加了业务状态转换的日志记录功能, 增加了详细的错误和警告日志,包括生命周期状态、 业务状态和连接信息,便于调试和问题排查。 refactor(mode_switch): 优化模式检测和报告机制 修改了模式切换采样的判断逻辑,移除了force_report和 mode_valid标志位,改用last_mode状态来决定是否提交 模式切换事件,使代码更简洁且易于理解。
This commit is contained in:
@@ -75,6 +75,50 @@ static struct protocol_module_ctx ctx = {
|
||||
|
||||
#define session_state ctx.session_state
|
||||
|
||||
static const char *lifecycle_name(enum module_lifecycle state)
|
||||
{
|
||||
switch (state) {
|
||||
case LC_UNINIT:
|
||||
return "UNINIT";
|
||||
case LC_RUNNING:
|
||||
return "RUNNING";
|
||||
case LC_STOPPED:
|
||||
return "STOPPED";
|
||||
case LC_SUSPENDED:
|
||||
return "SUSPENDED";
|
||||
case LC_ERROR:
|
||||
return "ERROR";
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
static const char *proto_session_name(enum proto_session_state state)
|
||||
{
|
||||
switch (state) {
|
||||
case PROTO_SESSION_DOWN:
|
||||
return "DOWN";
|
||||
case PROTO_SESSION_WAIT_HELLO:
|
||||
return "WAIT_HELLO";
|
||||
case PROTO_SESSION_ACTIVE:
|
||||
return "ACTIVE";
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
static const char *proto_transport_name(enum proto_transport transport)
|
||||
{
|
||||
switch (transport) {
|
||||
case PROTO_TRANSPORT_USB_CDC:
|
||||
return "usb_cdc";
|
||||
case PROTO_TRANSPORT_BLE_NUS:
|
||||
return "ble_nus";
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
static int decode_body(const uint8_t *payload, size_t payload_len,
|
||||
CdcPacketBody *body)
|
||||
{
|
||||
@@ -230,6 +274,9 @@ int protocol_module_process_message(enum proto_transport transport,
|
||||
}
|
||||
|
||||
if (!module_lifecycle_is_running(&ctx.lc)) {
|
||||
LOG_WRN("Reject proto msg transport:%s len:%u lc:%s",
|
||||
proto_transport_name(transport), (uint32_t)req_payload_len,
|
||||
lifecycle_name(ctx.lc.state));
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
@@ -241,6 +288,10 @@ int protocol_module_process_message(enum proto_transport transport,
|
||||
switch (body.which_body) {
|
||||
case CdcPacketBody_hello_req_tag:
|
||||
if (session_state[transport] == PROTO_SESSION_DOWN) {
|
||||
LOG_WRN("Reject HelloReq transport:%s session:%s lc:%s",
|
||||
proto_transport_name(transport),
|
||||
proto_session_name(session_state[transport]),
|
||||
lifecycle_name(ctx.lc.state));
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
@@ -354,7 +405,11 @@ static bool handle_proto_rx_event(const struct proto_rx_event *event)
|
||||
&rsp_payload_len);
|
||||
if (err) {
|
||||
if (err != -ENOTSUP) {
|
||||
LOG_WRN("Protocol processing failed (%d)", err);
|
||||
LOG_WRN("Protocol processing failed (%d) transport:%s session:%s lc:%s len:%u",
|
||||
err, proto_transport_name(event->transport),
|
||||
proto_session_name(session_state[event->transport]),
|
||||
lifecycle_name(ctx.lc.state),
|
||||
(uint32_t)event->dyndata.size);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user