添加 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状态来决定是否提交 模式切换事件,使代码更简洁且易于理解。
48 lines
1.2 KiB
C
48 lines
1.2 KiB
C
#include <inttypes.h>
|
|
|
|
#include "mode_switch_event.h"
|
|
|
|
static const char *mode_name(enum mode_switch_mode mode)
|
|
{
|
|
switch (mode) {
|
|
case MODE_SWITCH_INVALID:
|
|
return "INVALID";
|
|
case MODE_SWITCH_USB:
|
|
return "USB";
|
|
case MODE_SWITCH_24G:
|
|
return "2.4G";
|
|
case MODE_SWITCH_BLE:
|
|
return "BLE";
|
|
default:
|
|
return "?";
|
|
}
|
|
}
|
|
|
|
static void log_mode_switch_event(const struct app_event_header *aeh)
|
|
{
|
|
const struct mode_switch_event *event = cast_mode_switch_event(aeh);
|
|
|
|
APP_EVENT_MANAGER_LOG(aeh, "mode:%s voltage:%" PRIu16 "mV",
|
|
mode_name(event->mode), event->voltage_mv);
|
|
}
|
|
|
|
static void profile_mode_switch_event(struct log_event_buf *buf,
|
|
const struct app_event_header *aeh)
|
|
{
|
|
const struct mode_switch_event *event = cast_mode_switch_event(aeh);
|
|
|
|
nrf_profiler_log_encode_uint8(buf, event->mode);
|
|
nrf_profiler_log_encode_uint16(buf, event->voltage_mv);
|
|
}
|
|
|
|
APP_EVENT_INFO_DEFINE(mode_switch_event,
|
|
ENCODE(NRF_PROFILER_ARG_U8, NRF_PROFILER_ARG_U16),
|
|
ENCODE("mode", "voltage_mv"),
|
|
profile_mode_switch_event);
|
|
|
|
APP_EVENT_TYPE_DEFINE(mode_switch_event,
|
|
log_mode_switch_event,
|
|
&mode_switch_event_info,
|
|
APP_EVENT_FLAGS_CREATE(
|
|
APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE));
|