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:
@@ -11,6 +11,11 @@ enum proto_transport {
|
||||
PROTO_TRANSPORT_COUNT,
|
||||
};
|
||||
|
||||
enum proto_transport_link_state {
|
||||
PROTO_TRANSPORT_LINK_DOWN = 0,
|
||||
PROTO_TRANSPORT_LINK_READY,
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
36
inc/events/proto_transport_state_event.h
Normal file
36
inc/events/proto_transport_state_event.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef BLINKY_PROTO_TRANSPORT_STATE_EVENT_H_
|
||||
#define BLINKY_PROTO_TRANSPORT_STATE_EVENT_H_
|
||||
|
||||
#include <app_event_manager.h>
|
||||
#include <app_event_manager_profiler_tracer.h>
|
||||
|
||||
#include "proto_common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct proto_transport_state_event {
|
||||
struct app_event_header header;
|
||||
enum proto_transport transport;
|
||||
enum proto_transport_link_state state;
|
||||
};
|
||||
|
||||
APP_EVENT_TYPE_DECLARE(proto_transport_state_event);
|
||||
|
||||
static inline void submit_proto_transport_state_event(
|
||||
enum proto_transport transport, enum proto_transport_link_state state)
|
||||
{
|
||||
struct proto_transport_state_event *event =
|
||||
new_proto_transport_state_event();
|
||||
|
||||
event->transport = transport;
|
||||
event->state = state;
|
||||
APP_EVENT_SUBMIT(event);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* BLINKY_PROTO_TRANSPORT_STATE_EVENT_H_ */
|
||||
71
inc/events/usb_control_event.h
Normal file
71
inc/events/usb_control_event.h
Normal file
@@ -0,0 +1,71 @@
|
||||
#ifndef BLINKY_USB_CONTROL_EVENT_H_
|
||||
#define BLINKY_USB_CONTROL_EVENT_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <app_event_manager.h>
|
||||
#include <app_event_manager_profiler_tracer.h>
|
||||
#include <zephyr/device.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum usb_control_event_type {
|
||||
USB_CONTROL_EVENT_CDC_LINE_STATE = 0,
|
||||
USB_CONTROL_EVENT_CDC_LINE_CODING,
|
||||
};
|
||||
|
||||
struct usb_control_event {
|
||||
struct app_event_header header;
|
||||
enum usb_control_event_type type;
|
||||
const struct device *dev;
|
||||
union {
|
||||
struct {
|
||||
bool dtr;
|
||||
} cdc_line_state;
|
||||
struct {
|
||||
uint32_t baudrate;
|
||||
uint8_t data_bits;
|
||||
uint8_t stop_bits;
|
||||
uint8_t parity;
|
||||
uint8_t flow_ctrl;
|
||||
} cdc_line_coding;
|
||||
} data;
|
||||
};
|
||||
|
||||
APP_EVENT_TYPE_DECLARE(usb_control_event);
|
||||
|
||||
static inline void submit_usb_control_cdc_line_state_event(
|
||||
const struct device *dev, bool dtr)
|
||||
{
|
||||
struct usb_control_event *event = new_usb_control_event();
|
||||
|
||||
event->type = USB_CONTROL_EVENT_CDC_LINE_STATE;
|
||||
event->dev = dev;
|
||||
event->data.cdc_line_state.dtr = dtr;
|
||||
APP_EVENT_SUBMIT(event);
|
||||
}
|
||||
|
||||
static inline void submit_usb_control_cdc_line_coding_event(
|
||||
const struct device *dev, uint32_t baudrate, uint8_t data_bits,
|
||||
uint8_t stop_bits, uint8_t parity, uint8_t flow_ctrl)
|
||||
{
|
||||
struct usb_control_event *event = new_usb_control_event();
|
||||
|
||||
event->type = USB_CONTROL_EVENT_CDC_LINE_CODING;
|
||||
event->dev = dev;
|
||||
event->data.cdc_line_coding.baudrate = baudrate;
|
||||
event->data.cdc_line_coding.data_bits = data_bits;
|
||||
event->data.cdc_line_coding.stop_bits = stop_bits;
|
||||
event->data.cdc_line_coding.parity = parity;
|
||||
event->data.cdc_line_coding.flow_ctrl = flow_ctrl;
|
||||
APP_EVENT_SUBMIT(event);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* BLINKY_USB_CONTROL_EVENT_H_ */
|
||||
Reference in New Issue
Block a user