fix: restore CH390 bridge flow and sync driver docs
This commit is contained in:
+5
-5
@@ -35,7 +35,7 @@ extern "C" {
|
||||
#define CONFIG_MAGIC 0x54435055
|
||||
|
||||
/* Configuration version for compatibility */
|
||||
#define CONFIG_VERSION 0x0001
|
||||
#define CONFIG_VERSION 0x0002
|
||||
|
||||
/* Device configuration structure */
|
||||
typedef struct {
|
||||
@@ -76,13 +76,13 @@ typedef struct {
|
||||
} device_config_t;
|
||||
|
||||
/* Default configuration values */
|
||||
#define DEFAULT_IP {192, 168, 1, 100}
|
||||
#define DEFAULT_IP {192, 168, 31, 100}
|
||||
#define DEFAULT_MASK {255, 255, 255, 0}
|
||||
#define DEFAULT_GW {192, 168, 1, 1}
|
||||
#define DEFAULT_GW {192, 168, 31, 1}
|
||||
#define DEFAULT_MAC {0x02, 0x00, 0x00, 0x00, 0x00, 0x01}
|
||||
#define DEFAULT_SERVER_PORT 8080
|
||||
#define DEFAULT_REMOTE_IP {192, 168, 1, 200}
|
||||
#define DEFAULT_REMOTE_PORT 9000
|
||||
#define DEFAULT_REMOTE_IP {192, 168, 31, 1}
|
||||
#define DEFAULT_REMOTE_PORT 8081
|
||||
#define DEFAULT_UART_BAUDRATE 115200
|
||||
#define DEFAULT_UART_DATABITS 8
|
||||
#define DEFAULT_UART_STOPBITS 1
|
||||
|
||||
+20
-2
@@ -106,6 +106,7 @@ static err_t tcp_client_on_connected(void *arg, struct tcp_pcb *pcb, err_t err)
|
||||
|
||||
ctx->pcb = pcb;
|
||||
ctx->status.state = TCP_CLIENT_STATE_CONNECTED;
|
||||
tcp_nagle_disable(pcb);
|
||||
tcp_arg(pcb, ctx);
|
||||
tcp_recv(pcb, tcp_client_on_recv);
|
||||
tcp_sent(pcb, tcp_client_on_sent);
|
||||
@@ -118,8 +119,9 @@ int tcp_client_init(const tcp_client_config_t *config)
|
||||
memset(&g_client, 0, sizeof(g_client));
|
||||
g_client.config.server_ip[0] = 192u;
|
||||
g_client.config.server_ip[1] = 168u;
|
||||
g_client.config.server_ip[2] = 1u;
|
||||
g_client.config.server_ip[3] = 100u;
|
||||
g_client.config.server_ip[2] = 31u;
|
||||
g_client.config.server_ip[3] = 1u;
|
||||
g_client.config.local_port = TCP_CLIENT_DEFAULT_PORT;
|
||||
g_client.config.server_port = TCP_CLIENT_DEFAULT_PORT;
|
||||
g_client.config.auto_reconnect = true;
|
||||
g_client.config.reconnect_interval_ms = TCP_CLIENT_RECONNECT_DELAY_MS;
|
||||
@@ -148,6 +150,17 @@ int tcp_client_connect(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (g_client.config.local_port != 0u) {
|
||||
err = tcp_bind(pcb, IP_ANY_TYPE, g_client.config.local_port);
|
||||
if (err != ERR_OK) {
|
||||
tcp_abort(pcb);
|
||||
g_client.status.state = TCP_CLIENT_STATE_DISCONNECTED;
|
||||
g_client.status.errors++;
|
||||
g_client.next_retry_ms = HAL_GetTick() + g_client.config.reconnect_interval_ms;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
IP_ADDR4(&remote_addr,
|
||||
g_client.config.server_ip[0],
|
||||
g_client.config.server_ip[1],
|
||||
@@ -192,6 +205,11 @@ int tcp_client_send(const uint8_t *data, uint16_t len)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((g_client.pcb->flags & TF_RXCLOSED) != 0u) {
|
||||
g_client.status.errors++;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tcp_sndbuf(g_client.pcb) < len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ typedef enum {
|
||||
/* TCP Client configuration */
|
||||
typedef struct {
|
||||
uint8_t server_ip[4]; /* Server IP address */
|
||||
uint16_t local_port; /* Local source port */
|
||||
uint16_t server_port; /* Server port */
|
||||
bool auto_reconnect; /* Auto reconnect on disconnect */
|
||||
uint16_t reconnect_interval_ms; /* Reconnect interval */
|
||||
|
||||
@@ -104,6 +104,8 @@ static err_t tcp_server_on_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
|
||||
ctx->status.state = TCP_SERVER_STATE_CONNECTED;
|
||||
ctx->status.connections++;
|
||||
|
||||
tcp_nagle_disable(newpcb);
|
||||
|
||||
tcp_arg(newpcb, ctx);
|
||||
tcp_recv(newpcb, tcp_server_on_recv);
|
||||
tcp_sent(newpcb, tcp_server_on_sent);
|
||||
@@ -189,6 +191,11 @@ int tcp_server_send(const uint8_t *data, uint16_t len)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((g_server.client_pcb->flags & TF_RXCLOSED) != 0u) {
|
||||
g_server.status.errors++;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tcp_sndbuf(g_server.client_pcb) < len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user