feat: save stable CH390 bridge baseline
This commit is contained in:
+15
-82
@@ -1,43 +1,33 @@
|
||||
/**
|
||||
* @file tcp_server.h
|
||||
* @brief TCP Server module for transparent transmission with UART2
|
||||
* @brief Indexed lwIP RAW TCP server manager.
|
||||
*/
|
||||
|
||||
#ifndef __TCP_SERVER_H__
|
||||
#define __TCP_SERVER_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Default TCP Server port */
|
||||
#define TCP_SERVER_DEFAULT_PORT 8080
|
||||
#define TCP_SERVER_INSTANCE_COUNT 2u
|
||||
#define TCP_SERVER_RX_BUFFER_SIZE 512u
|
||||
|
||||
/* Maximum number of simultaneous connections */
|
||||
#define TCP_SERVER_MAX_CONNECTIONS 1
|
||||
|
||||
/* Buffer sizes */
|
||||
#define TCP_SERVER_RX_BUFFER_SIZE 512
|
||||
#define TCP_SERVER_TX_BUFFER_SIZE 512
|
||||
|
||||
/* TCP Server state */
|
||||
typedef enum {
|
||||
TCP_SERVER_STATE_IDLE,
|
||||
TCP_SERVER_STATE_IDLE = 0,
|
||||
TCP_SERVER_STATE_LISTENING,
|
||||
TCP_SERVER_STATE_CONNECTED,
|
||||
TCP_SERVER_STATE_ERROR
|
||||
} tcp_server_state_t;
|
||||
|
||||
/* TCP Server configuration */
|
||||
typedef struct {
|
||||
uint16_t port;
|
||||
bool auto_reconnect;
|
||||
} tcp_server_config_t;
|
||||
bool enabled;
|
||||
} tcp_server_instance_config_t;
|
||||
|
||||
/* TCP Server status */
|
||||
typedef struct {
|
||||
tcp_server_state_t state;
|
||||
uint32_t rx_bytes;
|
||||
@@ -46,71 +36,14 @@ typedef struct {
|
||||
uint32_t errors;
|
||||
} tcp_server_status_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize TCP Server module
|
||||
* @param config Server configuration
|
||||
* @return 0 on success, negative on error
|
||||
*/
|
||||
int tcp_server_init(const tcp_server_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Start TCP Server (begin listening)
|
||||
* @return 0 on success, negative on error
|
||||
*/
|
||||
int tcp_server_start(void);
|
||||
|
||||
/**
|
||||
* @brief Stop TCP Server
|
||||
* @return 0 on success, negative on error
|
||||
*/
|
||||
int tcp_server_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Send data to connected client
|
||||
* @param data Data buffer
|
||||
* @param len Data length
|
||||
* @return Number of bytes sent, negative on error
|
||||
*/
|
||||
int tcp_server_send(const uint8_t *data, uint16_t len);
|
||||
|
||||
/**
|
||||
* @brief Receive data from connected client
|
||||
* @param data Data buffer
|
||||
* @param max_len Maximum length to receive
|
||||
* @param timeout_ms Timeout in milliseconds (0 = non-blocking)
|
||||
* @return Number of bytes received, 0 if no data, negative on error
|
||||
*/
|
||||
int tcp_server_recv(uint8_t *data, uint16_t max_len, uint32_t timeout_ms);
|
||||
|
||||
/**
|
||||
* @brief Check if client is connected
|
||||
* @return true if connected
|
||||
*/
|
||||
bool tcp_server_is_connected(void);
|
||||
|
||||
/**
|
||||
* @brief Get TCP Server status
|
||||
* @param status Pointer to status structure
|
||||
*/
|
||||
void tcp_server_get_status(tcp_server_status_t *status);
|
||||
|
||||
/**
|
||||
* @brief Get TCP Server StreamBuffer handle for UART integration
|
||||
* @return StreamBuffer handle for receiving data from TCP
|
||||
*/
|
||||
void *tcp_server_get_rx_stream(void);
|
||||
|
||||
/**
|
||||
* @brief Get TCP Server TX StreamBuffer handle for UART integration
|
||||
* @return StreamBuffer handle for sending data to TCP
|
||||
*/
|
||||
void *tcp_server_get_tx_stream(void);
|
||||
|
||||
/**
|
||||
* @brief TCP Server task function (for FreeRTOS)
|
||||
* @param argument Task argument (unused)
|
||||
*/
|
||||
void tcp_server_task(void *argument);
|
||||
int tcp_server_init_all(void);
|
||||
int tcp_server_config(uint8_t instance, const tcp_server_instance_config_t *config);
|
||||
int tcp_server_start(uint8_t instance);
|
||||
int tcp_server_stop(uint8_t instance);
|
||||
int tcp_server_send(uint8_t instance, const uint8_t *data, uint16_t len);
|
||||
int tcp_server_recv(uint8_t instance, uint8_t *data, uint16_t max_len);
|
||||
bool tcp_server_is_connected(uint8_t instance);
|
||||
void tcp_server_get_status(uint8_t instance, tcp_server_status_t *status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user