优化整定,DHCP有问题待优化

This commit is contained in:
冯佳
2026-03-09 15:34:18 +08:00
parent 20597d22e5
commit 925df72fa0
30 changed files with 2556 additions and 2002 deletions

View File

@ -14,6 +14,10 @@
#include "transaction.h"
#include "state_manager.h"
#include "error_handler.h"
#include "sht40.h"
#include "lwip/netif.h"
#include "lwip/dhcp.h"
#include "drv_eth.h"
/**
* @brief 处理网络错误
@ -31,7 +35,33 @@ static int handle_network_error(error_code_t error, void *user_data)
/* 尝试恢复网络连接 */
osal_log_i("Attempting to recover network connection...");
/* 这里可以添加具体的网络恢复逻辑,比如重新连接、重启网络接口等 */
/* 具体的网络恢复逻辑 */
if (user_data != NULL)
{
struct netif *netif = (struct netif *)user_data;
/* 检查网络连接状态 */
ethernet_link_check_state(netif);
/* 如果网络连接已断开尝试重新启动DHCP */
if (!netif_is_link_up(netif))
{
osal_log_i("Network link down, waiting for link up...");
int wait_count = 0;
while (!netif_is_link_up(netif) && wait_count < 10)
{
osal_thread_mdelay(1000);
ethernet_link_check_state(netif);
wait_count++;
}
}
/* 重新启动DHCP */
osal_log_i("Restarting DHCP...");
dhcp_stop(netif);
osal_thread_mdelay(100);
dhcp_start(netif);
}
return 0;
}
@ -52,9 +82,23 @@ static int handle_sensor_error(error_code_t error, void *user_data)
/* 尝试恢复传感器 */
osal_log_i("Attempting to recover sensor...");
/* 这里可以添加具体的传感器恢复逻辑,比如重新初始化传感器等 */
/* 具体的传感器恢复逻辑 */
int retry_count = 0;
while (retry_count < 3)
{
osal_log_i("Attempt %d: Reinitializing SHT40 sensor...", retry_count + 1);
if (sht40_init() == 0)
{
osal_log_i("SHT40 sensor recovered successfully");
state_manager_set_sensor_state(SENSOR_STATE_READY);
return 0;
}
osal_thread_mdelay(1000);
retry_count++;
}
return 0;
osal_log_e("Failed to recover SHT40 sensor after %d attempts", retry_count);
return -1;
}
/**
@ -73,7 +117,8 @@ static int handle_tcp_error(error_code_t error, void *user_data)
/* 尝试恢复TCP连接 */
osal_log_i("Attempting to recover TCP connection...");
/* 这里可以添加具体的TCP恢复逻辑,比如重新建立连接等 */
/* 具体的TCP恢复逻辑 */
/* 这里可以添加重新建立TCP连接的代码 */
return 0;
}