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:
56
src/events/proto_transport_state_event.c
Normal file
56
src/events/proto_transport_state_event.c
Normal file
@@ -0,0 +1,56 @@
|
||||
#include "proto_transport_state_event.h"
|
||||
|
||||
static const char *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 const char *state_name(enum proto_transport_link_state state)
|
||||
{
|
||||
switch (state) {
|
||||
case PROTO_TRANSPORT_LINK_DOWN:
|
||||
return "down";
|
||||
case PROTO_TRANSPORT_LINK_READY:
|
||||
return "ready";
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
static void log_proto_transport_state_event(const struct app_event_header *aeh)
|
||||
{
|
||||
const struct proto_transport_state_event *event =
|
||||
cast_proto_transport_state_event(aeh);
|
||||
|
||||
APP_EVENT_MANAGER_LOG(aeh, "transport:%s state:%s",
|
||||
transport_name(event->transport),
|
||||
state_name(event->state));
|
||||
}
|
||||
|
||||
static void profile_proto_transport_state_event(struct log_event_buf *buf,
|
||||
const struct app_event_header *aeh)
|
||||
{
|
||||
const struct proto_transport_state_event *event =
|
||||
cast_proto_transport_state_event(aeh);
|
||||
|
||||
nrf_profiler_log_encode_uint8(buf, event->transport);
|
||||
nrf_profiler_log_encode_uint8(buf, event->state);
|
||||
}
|
||||
|
||||
APP_EVENT_INFO_DEFINE(proto_transport_state_event,
|
||||
ENCODE(NRF_PROFILER_ARG_U8, NRF_PROFILER_ARG_U8),
|
||||
ENCODE("transport", "state"),
|
||||
profile_proto_transport_state_event);
|
||||
|
||||
APP_EVENT_TYPE_DEFINE(proto_transport_state_event,
|
||||
log_proto_transport_state_event,
|
||||
&proto_transport_state_event_info,
|
||||
APP_EVENT_FLAGS_CREATE(
|
||||
APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE));
|
||||
82
src/events/usb_control_event.c
Normal file
82
src/events/usb_control_event.c
Normal file
@@ -0,0 +1,82 @@
|
||||
#include "usb_control_event.h"
|
||||
|
||||
static const char *control_event_name(enum usb_control_event_type type)
|
||||
{
|
||||
switch (type) {
|
||||
case USB_CONTROL_EVENT_CDC_LINE_STATE:
|
||||
return "cdc_line_state";
|
||||
case USB_CONTROL_EVENT_CDC_LINE_CODING:
|
||||
return "cdc_line_coding";
|
||||
default:
|
||||
return "?";
|
||||
}
|
||||
}
|
||||
|
||||
static void log_usb_control_event(const struct app_event_header *aeh)
|
||||
{
|
||||
const struct usb_control_event *event = cast_usb_control_event(aeh);
|
||||
|
||||
switch (event->type) {
|
||||
case USB_CONTROL_EVENT_CDC_LINE_STATE:
|
||||
APP_EVENT_MANAGER_LOG(aeh, "type:%s dtr:%u",
|
||||
control_event_name(event->type),
|
||||
event->data.cdc_line_state.dtr);
|
||||
break;
|
||||
|
||||
case USB_CONTROL_EVENT_CDC_LINE_CODING:
|
||||
APP_EVENT_MANAGER_LOG(aeh,
|
||||
"type:%s baud:%u data:%u stop:%u parity:%u flow:%u",
|
||||
control_event_name(event->type),
|
||||
event->data.cdc_line_coding.baudrate,
|
||||
event->data.cdc_line_coding.data_bits,
|
||||
event->data.cdc_line_coding.stop_bits,
|
||||
event->data.cdc_line_coding.parity,
|
||||
event->data.cdc_line_coding.flow_ctrl);
|
||||
break;
|
||||
|
||||
default:
|
||||
APP_EVENT_MANAGER_LOG(aeh, "type:%s",
|
||||
control_event_name(event->type));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void profile_usb_control_event(struct log_event_buf *buf,
|
||||
const struct app_event_header *aeh)
|
||||
{
|
||||
const struct usb_control_event *event = cast_usb_control_event(aeh);
|
||||
|
||||
nrf_profiler_log_encode_uint8(buf, event->type);
|
||||
switch (event->type) {
|
||||
case USB_CONTROL_EVENT_CDC_LINE_STATE:
|
||||
nrf_profiler_log_encode_uint8(buf, event->data.cdc_line_state.dtr);
|
||||
break;
|
||||
|
||||
case USB_CONTROL_EVENT_CDC_LINE_CODING:
|
||||
nrf_profiler_log_encode_uint32(buf, event->data.cdc_line_coding.baudrate);
|
||||
nrf_profiler_log_encode_uint8(buf, event->data.cdc_line_coding.data_bits);
|
||||
nrf_profiler_log_encode_uint8(buf, event->data.cdc_line_coding.stop_bits);
|
||||
nrf_profiler_log_encode_uint8(buf, event->data.cdc_line_coding.parity);
|
||||
nrf_profiler_log_encode_uint8(buf, event->data.cdc_line_coding.flow_ctrl);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
APP_EVENT_INFO_DEFINE(usb_control_event,
|
||||
ENCODE(NRF_PROFILER_ARG_U8,
|
||||
NRF_PROFILER_ARG_U32,
|
||||
NRF_PROFILER_ARG_U8,
|
||||
NRF_PROFILER_ARG_U8,
|
||||
NRF_PROFILER_ARG_U8,
|
||||
NRF_PROFILER_ARG_U8),
|
||||
ENCODE("type", "baud_or_zero", "arg1", "arg2", "arg3", "arg4"),
|
||||
profile_usb_control_event);
|
||||
|
||||
APP_EVENT_TYPE_DEFINE(usb_control_event,
|
||||
log_usb_control_event,
|
||||
&usb_control_event_info,
|
||||
APP_EVENT_FLAGS_CREATE(
|
||||
APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE));
|
||||
Reference in New Issue
Block a user