fix: preserve current runtime debug state
This commit is contained in:
+32
-6
@@ -8,9 +8,10 @@
|
||||
|
||||
#include "app_runtime.h"
|
||||
#include "config.h"
|
||||
#include "debug_log.h"
|
||||
#include "route_msg.h"
|
||||
|
||||
static void tcp_client_worker(struct netconn *conn, uint8_t link_index)
|
||||
static err_t tcp_client_worker(struct netconn *conn, uint8_t link_index)
|
||||
{
|
||||
struct netbuf *buf;
|
||||
const device_config_t *cfg = config_get();
|
||||
@@ -38,17 +39,18 @@ static void tcp_client_worker(struct netconn *conn, uint8_t link_index)
|
||||
} while (netbuf_next(buf) >= 0);
|
||||
netbuf_delete(buf);
|
||||
} else if (err != ERR_TIMEOUT) {
|
||||
break;
|
||||
return err;
|
||||
}
|
||||
|
||||
while (xQueueReceive(xLinkTxQueues[link_index], &tx_msg, 0) == pdPASS) {
|
||||
err = netconn_write(conn, tx_msg->data, tx_msg->len, NETCONN_COPY);
|
||||
route_msg_free(tx_msg);
|
||||
if (err != ERR_OK) {
|
||||
return;
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void tcp_client_task(uint8_t link_index)
|
||||
@@ -57,6 +59,10 @@ static void tcp_client_task(uint8_t link_index)
|
||||
struct netconn *conn;
|
||||
ip_addr_t remote_ip;
|
||||
uint32_t delay_ms;
|
||||
err_t err;
|
||||
uint8_t first_connect_deferred;
|
||||
|
||||
first_connect_deferred = (link_index == CONFIG_LINK_C1) ? 1u : 0u;
|
||||
|
||||
for (;;) {
|
||||
while (g_netif_ready == pdFALSE) {
|
||||
@@ -64,12 +70,26 @@ static void tcp_client_task(uint8_t link_index)
|
||||
}
|
||||
|
||||
cfg = config_get();
|
||||
debug_log_printf("[CLI] idx=%u hwm=%lu en=%u lport=%u rport=%u\r\n",
|
||||
(unsigned int)link_index,
|
||||
(unsigned long)uxTaskGetStackHighWaterMark(NULL),
|
||||
(unsigned int)cfg->links[link_index].enabled,
|
||||
(unsigned int)cfg->links[link_index].local_port,
|
||||
(unsigned int)cfg->links[link_index].remote_port);
|
||||
if (cfg->links[link_index].enabled == 0u) {
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
continue;
|
||||
}
|
||||
|
||||
delay_ms = (cfg->reconnect_interval_ms == 0u) ? 3000u : cfg->reconnect_interval_ms;
|
||||
|
||||
if (first_connect_deferred != 0u) {
|
||||
first_connect_deferred = 0u;
|
||||
debug_log_write("[CLI] C1 first-connect defer\r\n");
|
||||
vTaskDelay(pdMS_TO_TICKS(delay_ms));
|
||||
continue;
|
||||
}
|
||||
|
||||
conn = netconn_new(NETCONN_TCP);
|
||||
if (conn == NULL) {
|
||||
vTaskDelay(pdMS_TO_TICKS(delay_ms));
|
||||
@@ -77,7 +97,12 @@ static void tcp_client_task(uint8_t link_index)
|
||||
}
|
||||
|
||||
if (cfg->links[link_index].local_port != 0u) {
|
||||
(void)netconn_bind(conn, IP_ADDR_ANY, cfg->links[link_index].local_port);
|
||||
err = netconn_bind(conn, IP_ADDR_ANY, cfg->links[link_index].local_port);
|
||||
if (err != ERR_OK) {
|
||||
netconn_delete(conn);
|
||||
vTaskDelay(pdMS_TO_TICKS(delay_ms));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
IP_ADDR4(&remote_ip,
|
||||
@@ -86,8 +111,9 @@ static void tcp_client_task(uint8_t link_index)
|
||||
cfg->links[link_index].remote_ip[2],
|
||||
cfg->links[link_index].remote_ip[3]);
|
||||
|
||||
if (netconn_connect(conn, &remote_ip, cfg->links[link_index].remote_port) == ERR_OK) {
|
||||
tcp_client_worker(conn, link_index);
|
||||
err = netconn_connect(conn, &remote_ip, cfg->links[link_index].remote_port);
|
||||
if (err == ERR_OK) {
|
||||
(void)tcp_client_worker(conn, link_index);
|
||||
}
|
||||
|
||||
netconn_close(conn);
|
||||
|
||||
Reference in New Issue
Block a user