Files

96 lines
2.1 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* @file debug_link.h
* @brief 调试链路层:TCP Socket 后端 + comm_link 适配 + 会话上下文(阶段1合并)
*
* 合并自:comm_link.h、comm_link_ctx.h、tcp/tcp_link_priv.h、tcp_server_socket 对外 API
*/
#ifndef DEBUG_LINK_H
#define DEBUG_LINK_H
#include <stdint.h>
#include "publicdata/public_define.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ---------- comm_link 类型与 API ---------- */
typedef enum {
COMM_LINK_TCP = 0,
#if BLE_DEBUG_EN
COMM_LINK_BLE = 1,
#endif
} comm_link_type_t;
#if BLE_DEBUG_EN
#define COMM_LINK_IS_BLE(t) ((t) == COMM_LINK_BLE)
#else
#define COMM_LINK_IS_BLE(t) (0)
#endif
void comm_link_set_type(comm_link_type_t type);
comm_link_type_t comm_link_get_type(void);
comm_link_type_t comm_link_type_from_dip(void);
int comm_link_start(void);
void comm_link_stop(void);
void comm_link_process(void);
int comm_link_accept_client(void);
int comm_link_is_client_connected(void);
void comm_link_close_client(void);
int comm_link_receive_data(uint8_t *buffer, uint32_t buffer_size);
int comm_link_send_data(const uint8_t *data, uint32_t len);
int comm_link_get_peer_info(char *buf, uint32_t buf_size);
/* ---------- comm_link_ctxTCP/BLE backend union ---------- */
#define COMM_LINK_PEER_INFO_SIZE 48U
typedef struct {
comm_link_type_t type;
uint8_t client_connected;
char peer_info[COMM_LINK_PEER_INFO_SIZE];
} comm_link_session_t;
#if BLE_DEBUG_EN
#include "ble_link/fc41d_ble_priv.h"
#endif
#include "lwip/sockets.h"
#include "FreeRTOS.h"
#include "semphr.h"
typedef struct {
int server_socket;
int client_socket;
struct sockaddr_in client_addr;
SemaphoreHandle_t mutex;
} tcp_link_ctx_t;
typedef union {
#if BLE_DEBUG_EN
fc41d_ble_ctx_t ble;
#endif
tcp_link_ctx_t tcp;
} comm_link_backend_u;
typedef struct {
comm_link_session_t session;
comm_link_backend_u backend;
} comm_link_ctx_t;
comm_link_ctx_t *comm_link_ctx_get(void);
comm_link_session_t *comm_link_session(void);
void comm_link_ctx_reset_session(void);
void comm_link_ctx_reset_all(void);
#ifdef __cplusplus
}
#endif
#endif /* DEBUG_LINK_H */