21
This commit is contained in:
parent
2fa3bbf647
commit
9230e7985d
@ -331,7 +331,7 @@ qdx_socket_t qdx_port_tcp_connect(const char *ip, uint16_t port)
|
|||||||
|
|
||||||
if (err != WCHNET_ERR_SUCCESS) {
|
if (err != WCHNET_ERR_SUCCESS) {
|
||||||
DBG_PORT("SocketConnect fail %02X\r\n", err);
|
DBG_PORT("SocketConnect fail %02X\r\n", err);
|
||||||
WCHNET_SocketClose(wchnet_id, 0);
|
WCHNET_SocketClose(wchnet_id, TCP_CLOSE_RST);
|
||||||
free_sock_ctx(ctx);
|
free_sock_ctx(ctx);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -346,14 +346,14 @@ qdx_socket_t qdx_port_tcp_connect(const char *ip, uint16_t port)
|
|||||||
DBG_PORT("connect_sem TIMEOUT after %d ms -> %d.%d.%d.%d:%d\r\n",
|
DBG_PORT("connect_sem TIMEOUT after %d ms -> %d.%d.%d.%d:%d\r\n",
|
||||||
(int)elapsed, dest_ip[0], dest_ip[1], dest_ip[2], dest_ip[3], port);
|
(int)elapsed, dest_ip[0], dest_ip[1], dest_ip[2], dest_ip[3], port);
|
||||||
DBG_PORT(" ctx->connected=%d wchnet_id=%d\r\n", ctx->connected, wchnet_id);
|
DBG_PORT(" ctx->connected=%d wchnet_id=%d\r\n", ctx->connected, wchnet_id);
|
||||||
WCHNET_SocketClose(wchnet_id, 0);
|
WCHNET_SocketClose(wchnet_id, TCP_CLOSE_RST);
|
||||||
free_sock_ctx(ctx);
|
free_sock_ctx(ctx);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
DBG_PORT("connect_sem got after %d ms, connected=%d\r\n", (int)elapsed, ctx->connected);
|
DBG_PORT("connect_sem got after %d ms, connected=%d\r\n", (int)elapsed, ctx->connected);
|
||||||
|
|
||||||
if (!ctx->connected) {
|
if (!ctx->connected) {
|
||||||
WCHNET_SocketClose(wchnet_id, 0);
|
WCHNET_SocketClose(wchnet_id, TCP_CLOSE_RST);
|
||||||
free_sock_ctx(ctx);
|
free_sock_ctx(ctx);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -373,16 +373,39 @@ int32_t qdx_port_tcp_send(qdx_socket_t sock, const uint8_t *data, uint32_t len)
|
|||||||
if (!ctx || !ctx->connected)
|
if (!ctx || !ctx->connected)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
uint32_t send_len = len;
|
uint32_t total_sent = 0;
|
||||||
|
const uint8_t *ptr = data;
|
||||||
|
uint32_t remaining = len;
|
||||||
|
uint8_t retries = 0;
|
||||||
|
|
||||||
xSemaphoreTake(g_wchnet_mutex, portMAX_DELAY);
|
while (remaining > 0) {
|
||||||
uint8_t err = WCHNET_SocketSend(ctx->wchnet_sock_id, (uint8_t *)data, &send_len);
|
uint32_t send_len = remaining;
|
||||||
xSemaphoreGive(g_wchnet_mutex);
|
|
||||||
|
|
||||||
if (err != WCHNET_ERR_SUCCESS)
|
xSemaphoreTake(g_wchnet_mutex, portMAX_DELAY);
|
||||||
return -1;
|
uint8_t err = WCHNET_SocketSend(ctx->wchnet_sock_id, (uint8_t *)ptr, &send_len);
|
||||||
|
xSemaphoreGive(g_wchnet_mutex);
|
||||||
|
|
||||||
return (int32_t)send_len;
|
if (err != WCHNET_ERR_SUCCESS && send_len == 0) {
|
||||||
|
/* WCHNET send buffer full — yield so wchnet task can flush */
|
||||||
|
if (++retries > 50) {
|
||||||
|
DBG_PORT("send fail after retries, err=0x%02X\r\n", err);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(2));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
retries = 0;
|
||||||
|
ptr += send_len;
|
||||||
|
remaining -= send_len;
|
||||||
|
total_sent += send_len;
|
||||||
|
|
||||||
|
if (remaining > 0) {
|
||||||
|
/* Partial send — yield to let wchnet task drain the buffer */
|
||||||
|
vTaskDelay(pdMS_TO_TICKS(2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int32_t)total_sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qdx_port_tcp_recv(qdx_socket_t sock, uint8_t *buf, uint32_t max_len)
|
int32_t qdx_port_tcp_recv(qdx_socket_t sock, uint8_t *buf, uint32_t max_len)
|
||||||
@ -422,7 +445,10 @@ void qdx_port_tcp_close(qdx_socket_t sock)
|
|||||||
|
|
||||||
if (ctx->in_use) {
|
if (ctx->in_use) {
|
||||||
xSemaphoreTake(g_wchnet_mutex, portMAX_DELAY);
|
xSemaphoreTake(g_wchnet_mutex, portMAX_DELAY);
|
||||||
WCHNET_SocketClose(ctx->wchnet_sock_id, 0);
|
/* Use TCP_CLOSE_RST to immediately release the WCHNET socket slot.
|
||||||
|
* TCP_CLOSE_NORMAL (0) causes TIME_WAIT which holds the slot for
|
||||||
|
* an extended period, preventing reconnection with only 2 sockets. */
|
||||||
|
WCHNET_SocketClose(ctx->wchnet_sock_id, TCP_CLOSE_RST);
|
||||||
xSemaphoreGive(g_wchnet_mutex);
|
xSemaphoreGive(g_wchnet_mutex);
|
||||||
}
|
}
|
||||||
ring_init(&ctx->rx_ring);
|
ring_init(&ctx->rx_ring);
|
||||||
|
|||||||
@ -489,14 +489,21 @@ static void task_business_entry(void *pvParameters)
|
|||||||
else if (Preprocess_CheckInternalTrigger2D(&raw_img) == 1)
|
else if (Preprocess_CheckInternalTrigger2D(&raw_img) == 1)
|
||||||
{
|
{
|
||||||
/* Trigger hit! Start burst: this frame is frame #0 */
|
/* Trigger hit! Start burst: this frame is frame #0 */
|
||||||
|
DBG_APP("TRIGGER frm=%d\r\n", (int)raw_img.FrameNumber);
|
||||||
PreprocessResult_t meta;
|
PreprocessResult_t meta;
|
||||||
TcpTxBuffer_t *tx_buf = use_buffer_A ? &g_TxNetBuffer_A : &g_TxNetBuffer_B;
|
TcpTxBuffer_t *tx_buf = use_buffer_A ? &g_TxNetBuffer_A : &g_TxNetBuffer_B;
|
||||||
use_buffer_A = !use_buffer_A;
|
use_buffer_A = !use_buffer_A;
|
||||||
tx_buf->ValidPayloadLen = 0;
|
tx_buf->ValidPayloadLen = 0;
|
||||||
|
|
||||||
if (Preprocess_Execute(&raw_img, tx_buf, &meta) == 0)
|
int8_t pp_ret = Preprocess_Execute(&raw_img, tx_buf, &meta);
|
||||||
|
if (pp_ret == 0)
|
||||||
{
|
{
|
||||||
TcpLogic_BuildAndSendTemperatureFrame(tx_buf, &meta, 0x01, 1);
|
int8_t tx_ret = TcpLogic_BuildAndSendTemperatureFrame(tx_buf, &meta, 0x01, 1);
|
||||||
|
DBG_APP("SEND frm=%d %dx%d ret=%d\r\n",
|
||||||
|
(int)meta.FrameNumber, (int)meta.ValidWidth,
|
||||||
|
(int)meta.ValidHeight, (int)tx_ret);
|
||||||
|
} else {
|
||||||
|
DBG_APP("PP fail ret=%d\r\n", (int)pp_ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Determine burst count from config */
|
/* Determine burst count from config */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user