将TCP重连优化,心跳改为3分钟

This commit is contained in:
小马_666 2025-02-14 16:32:42 +08:00
parent db30b6f7b3
commit 9d2cdf6e26
3 changed files with 13 additions and 10 deletions

View File

@ -5,7 +5,7 @@
"type": "mrs-debugger",
"request": "launch",
"name": "JT-DT-YD4N02A_RTT_MRS-4G",
"cwd": "d:\\SXDT\\Project\\CH32\\JT-DT-YD4N02A_RTT_MRS-NT26K",
"cwd": "c:\\Users\\张喆1223\\Desktop\\NT26K\\JT-DT-YD4N02A_4G_RTT_MRS",
"openOCDCfg": {
"useLocalOpenOCD": true,
"executable": "c:/MounRiver/MounRiver_Studio2/resources/app/resources/win32/components/WCH/OpenOCD/OpenOCD/bin/openocd.exe",
@ -39,8 +39,8 @@
"additionalCommands": []
},
"loadedFiles": {
"executableFile": "d:\\SXDT\\Project\\CH32\\JT-DT-YD4N02A_RTT_MRS-NT26K\\obj\\JT-DT-YD4N02A_RTT_MRS-4G.elf",
"symbolFile": "d:\\SXDT\\Project\\CH32\\JT-DT-YD4N02A_RTT_MRS-NT26K\\obj\\JT-DT-YD4N02A_RTT_MRS-4G.elf",
"executableFile": "c:\\Users\\张喆1223\\Desktop\\NT26K\\JT-DT-YD4N02A_4G_RTT_MRS\\obj\\JT-DT-YD4N02A_RTT_MRS-4G.elf",
"symbolFile": "c:\\Users\\张喆1223\\Desktop\\NT26K\\JT-DT-YD4N02A_4G_RTT_MRS\\obj\\JT-DT-YD4N02A_RTT_MRS-4G.elf",
"executableFileOffset": 0,
"symbolFileOffset": 0
},

View File

@ -111,7 +111,7 @@ static rt_err_t nt26k_power_off(struct at_device *device)
static rt_err_t nt26k_Close_Rf(struct at_device *device)
{
at_response_t resp = at_create_resp(64, 0, rt_tick_from_millisecond(60000));
at_response_t resp = at_create_resp(64, 0, rt_tick_from_millisecond(10000));
if (resp == RT_NULL)
{
LOG_D("no memory for resp create.");
@ -888,7 +888,7 @@ static void nt26k_init_thread_entry(void *parameter)
goto __exit;
}
/*设置保活信息*/
if (at_obj_exec_cmd(device->client, resp, "AT+QICFG=\"tcp/keepalive\",1,1000,100,10") != RT_EOK)
if (at_obj_exec_cmd(device->client, resp, "AT+QICFG=\"tcp/keepalive\",1,180,75,9") != RT_EOK)
{
result = -RT_ERROR;
goto __exit;

View File

@ -1462,7 +1462,7 @@ static void Nt26k_Life_Thread_Entry(void *parameter)
rt_err_t result = RT_ETIMEOUT;
rt_uint32_t delay_n = 0;
at_response_t resp = RT_NULL;
rt_uint32_t retry_delay = 1000;
rt_uint32_t retry_delay = 4000;
LOG_D("nt26k_life_thread entry\n");
while (1)
@ -1482,8 +1482,10 @@ static void Nt26k_Life_Thread_Entry(void *parameter)
result = -RT_ETIMEOUT;
goto __exit;
}
device->class->device_ops->control(device, AT_DEVICE_RF_CLOSE, RT_NULL);
device->class->device_ops->control(device, AT_DEVICE_CTRL_NET_DISCONN, RT_NULL);
rt_thread_mdelay(RT_TICK_PER_SECOND);//这里如果有TCP连接先关掉TCP,没有返回错误无所谓
device->class->device_ops->control(device, AT_DEVICE_RF_CLOSE, RT_NULL);
rt_thread_mdelay(RT_TICK_PER_SECOND);
if (device->class->device_ops->control(device, AT_DEVICE_CTRL_WAKEUP, RT_NULL) == RT_EOK)
{
if (device->class->device_ops->control(device, AT_DEVICE_CTRL_POWER_ON, RT_NULL) == RT_EOK)
@ -1522,7 +1524,8 @@ static void Nt26k_Life_Thread_Entry(void *parameter)
}
/*设置保活信息*/
LOG_D("AT+QICFG=\"tcp/keepalive\",1,1000,100,10");
if (at_obj_exec_cmd(device->client, resp, "AT+QICFG=\"tcp/keepalive\",1,1000,100,10") != RT_EOK)
// if (at_obj_exec_cmd(device->client, resp, "AT+QICFG=\"tcp/keepalive\",1,1000,100,10") != RT_EOK)
if (at_obj_exec_cmd(device->client, resp, "AT+QICFG=\"tcp/keepalive\",1,180,75,9") != RT_EOK)
{
LOG_E("AT+QICFG=\"tcp/keepalive\" error\n");
result = -RT_ETIMEOUT;
@ -1640,9 +1643,9 @@ static void Nt26k_Life_Thread_Entry(void *parameter)
nt26k_disconnect_retry_flag = 1;
LOG_D("联网错误,等待%dms后重连", retry_delay);
rt_thread_mdelay(retry_delay);
retry_delay = MIN(retry_delay * 2, 60000); // 最大延迟60秒
retry_delay = MIN(retry_delay * 2, 1800000); // 最大延迟30min
delay_n++;
if (delay_n >= 360) // 连续重连大于1小时都不行则重启设备
if (delay_n >= 21) // 连续重连大于1小时都不行则重启设备
{
Flash_Set_WorkDuration(work_duration);
rt_thread_mdelay(100);