- 将ble_serial_module替换为ble_nus_module以使用标准的BLE NUS服务 - 移除不再使用的cdc_wrapper_module和相关事件处理 - 更新协议传输层抽象,支持USB CDC和BLE NUS两种传输方式 - 创建统一的proto_rx_event和proto_tx_event替代专用的串行通信事件 - 添加proto_common.h定义传输类型枚举 - 修改protocol_module接口以支持多传输方式 - 在prj.conf中启用CONFIG_BT_ZEPHYR_NUS配置选项
43 lines
1.1 KiB
C
43 lines
1.1 KiB
C
#include "proto_rx_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 void log_proto_rx_event(const struct app_event_header *aeh)
|
|
{
|
|
const struct proto_rx_event *event = cast_proto_rx_event(aeh);
|
|
|
|
APP_EVENT_MANAGER_LOG(aeh, "transport:%s len:%zu",
|
|
transport_name(event->transport),
|
|
event->dyndata.size);
|
|
}
|
|
|
|
static void profile_proto_rx_event(struct log_event_buf *buf,
|
|
const struct app_event_header *aeh)
|
|
{
|
|
const struct proto_rx_event *event = cast_proto_rx_event(aeh);
|
|
|
|
nrf_profiler_log_encode_uint8(buf, event->transport);
|
|
nrf_profiler_log_encode_uint16(buf, (uint16_t)event->dyndata.size);
|
|
}
|
|
|
|
APP_EVENT_INFO_DEFINE(proto_rx_event,
|
|
ENCODE(NRF_PROFILER_ARG_U8, NRF_PROFILER_ARG_U16),
|
|
ENCODE("transport", "len"),
|
|
profile_proto_rx_event);
|
|
|
|
APP_EVENT_TYPE_DEFINE(proto_rx_event,
|
|
log_proto_rx_event,
|
|
&proto_rx_event_info,
|
|
APP_EVENT_FLAGS_CREATE(
|
|
APP_EVENT_TYPE_FLAGS_INIT_LOG_ENABLE));
|