feat: 新增接收dispatch反向路由
CI / host (pull_request) Successful in 2s
CI / cortex-m (pull_request) Successful in 5s

This commit is contained in:
2026-07-30 10:49:44 +08:00
parent fa1f547e81
commit 1c3e48d59f
10 changed files with 373 additions and 664 deletions
+34 -1
View File
@@ -17,7 +17,8 @@
typedef struct {
int send_type;
dr_send_handler_t handlers[DR_MAX_HANDLERS_PER_PORT];
int recv_type;
dr_send_handler_t handlers[DR_MAX_HANDLERS_PER_PORT];
int count;
uint8_t in_use;
} port_entry_t;
@@ -51,6 +52,14 @@ static const char *recv_descs[] = {
#undef DR_RECV
};
/* ---- 接收回调函数指针表(dispatch 查表用) ---- */
static void (*const recv_table[DR_RECV_CAP_COUNT])(uint32_t, const void*, size_t) = {
#define DR_RECV(id, desc) dr_on_recv_##id,
DR_RECV_CAPABILITIES
#undef DR_RECV
};
/* ---- 弱符号接收回调 ---- */
#define DR_RECV(id, desc) \
@@ -102,6 +111,7 @@ dr_port_t dr_port_create(void)
if (!ports[i].in_use) {
ports[i].in_use = 1;
ports[i].send_type = -1;
ports[i].recv_type = -1;
ports[i].count = 0;
return (dr_port_t)i;
}
@@ -130,6 +140,29 @@ int dr_port_get_send_type(dr_port_t port)
return ports[port].send_type;
}
void dr_port_set_recv_type(dr_port_t port, int cap_id)
{
if (!initialized) return;
if (port < 0 || port >= DR_MAX_PORTS || !ports[port].in_use) return;
ports[port].recv_type = cap_id;
}
int dr_port_get_recv_type(dr_port_t port)
{
if (!initialized) return -1;
if (port < 0 || port >= DR_MAX_PORTS || !ports[port].in_use) return -1;
return ports[port].recv_type;
}
void dr_port_dispatch(dr_port_t port, const void *data, size_t len)
{
if (!initialized) return;
if (port < 0 || port >= DR_MAX_PORTS || !ports[port].in_use) return;
int rid = ports[port].recv_type;
if (rid < 0 || rid >= DR_RECV_CAP_COUNT) return;
recv_table[rid]((uint32_t)port, data, len);
}
int dr_port_add_handler(dr_port_t port, dr_send_handler_t handler)
{
if (!initialized) return -1;