diff --git a/applications/user_sys.h b/applications/user_sys.h index 44057e6..ccbf174 100644 --- a/applications/user_sys.h +++ b/applications/user_sys.h @@ -46,6 +46,10 @@ // rt_kprintf("Compiled at: %s\n", __TIMESTAMP__); \ // } while (0) +#ifndef MIN +#define MIN(a, b) ((a) < (b) ? (a) : (b)) +#endif + typedef enum { kPowerOnEvent, diff --git a/bsp/inc/bsp_h308.h b/bsp/inc/bsp_h308.h index 2a54906..7c0cc42 100644 --- a/bsp/inc/bsp_h308.h +++ b/bsp/inc/bsp_h308.h @@ -1,3 +1,13 @@ +/*** + * @Author: mbw + * @Date: 2025-01-24 08:40:39 + * @LastEditors: mbw && 1600520629@qq.com + * @LastEditTime: 2025-02-14 11:06:11 + * @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\inc\bsp_h308.h + * @Description: + * @ + * @Copyright (c) 2025 by ${git_name_email}, All Rights Reserved. + */ /*** * @Author: mbw * @Date: 2025-01-24 08:40:39 @@ -26,6 +36,9 @@ #define H308_PWR_ON rt_pin_write(H308_PWR_PIN, PIN_HIGH) #define H308_PWR_OFF rt_pin_write(H308_PWR_PIN, PIN_LOW) +// #define H308_PWR_ON rt_pin_write(H308_PWR_PIN, PIN_LOW) +// #define H308_PWR_OFF rt_pin_write(H308_PWR_PIN, PIN_HIGH) + #define H308_RST_ON rt_pin_write(H308_RST_PIN, PIN_LOW) #define H308_RST_OFF rt_pin_write(H308_RST_PIN, PIN_HIGH) diff --git a/bsp/src/at_device_nt26k.c b/bsp/src/at_device_nt26k.c index 91c2341..2f80eef 100644 --- a/bsp/src/at_device_nt26k.c +++ b/bsp/src/at_device_nt26k.c @@ -2,7 +2,7 @@ * @Author : stark1898y 1658608470@qq.com * @Date : 2024-09-04 13:33:49 * @LastEditors: mbw && 1600520629@qq.com - * @LastEditTime: 2025-02-13 08:55:43 + * @LastEditTime: 2025-02-14 11:10:57 * @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\src\at_device_nt26k.c * @Description : * @@ -356,6 +356,10 @@ static int at_device_nt26k_connect_tcp(struct at_device *device) { nt26k_disconnect_pdp_flag = 1; } + if (err_code == 407) + { + LOG_W("请检查服务器"); + } } } } diff --git a/bsp/src/bsp_button.c b/bsp/src/bsp_button.c index 57bea8d..20d63e1 100644 --- a/bsp/src/bsp_button.c +++ b/bsp/src/bsp_button.c @@ -57,12 +57,34 @@ static uint8_t relay_cnt = 1; static void _CommonBtnEvtCb(void *arg) { + // static rt_uint8_t cnt = 0; if (flex_button_event_read(&user_button[USER_BUTTON_0]) == FLEX_BTN_PRESS_CLICK) { if (SysControl.status == kAlarmEvent) { Send_Laser_Alarm_Event(KMuteEvent); } + // cnt++; + // if (cnt == 1) + // { + // LED_G_NORMAL; + // } + // else if (cnt == 2) + // { + // LED_Y_FAULT; + // } + // else if (cnt == 3) + // { + // LED_R_ALARM; + // } + // else + // { + // LED_STOP(r); + // LED_STOP(g); + // LED_STOP(y); + // cnt = 0; + + // } } else if (flex_button_event_read(&user_button[USER_BUTTON_0]) == FLEX_BTN_PRESS_LONG_HOLD) { diff --git a/bsp/src/bsp_led.c b/bsp/src/bsp_led.c index e76dd06..e69ba60 100644 --- a/bsp/src/bsp_led.c +++ b/bsp/src/bsp_led.c @@ -1,3 +1,13 @@ +/* + * @Author: mbw + * @Date: 2025-01-24 08:40:39 + * @LastEditors: mbw && 1600520629@qq.com + * @LastEditTime: 2025-02-14 11:36:24 + * @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\src\bsp_led.c + * @Description: + * + * Copyright (c) 2025 by ${git_name_email}, All Rights Reserved. + */ #include "bsp_led.h" #include "rtthread.h" #include "pin.h" diff --git a/bsp/src/bsp_nt26k.c b/bsp/src/bsp_nt26k.c index f45000e..4906bbb 100644 --- a/bsp/src/bsp_nt26k.c +++ b/bsp/src/bsp_nt26k.c @@ -2,7 +2,7 @@ * @Author: mbw * @Date: 2024-10-09 08:42:14 * @LastEditors: mbw && 1600520629@qq.com - * @LastEditTime: 2025-02-12 11:01:27 + * @LastEditTime: 2025-02-14 10:10:31 * @FilePath: \JT-DT-YD4N02A_RTT_MRS-NT26K\bsp\src\bsp_nt26k.c * @Description: * @@ -372,7 +372,6 @@ int Data_Resp(struct Nt26k_Ops *ops, rt_uint8_t data_num, rt_uint8_t cmd, rt_uin LOG_E("nt26k_conncet_tcp_flag error"); return -RT_ERROR; } - char data_buf[512] = {0}; rt_int32_t len = rt_snprintf(data_buf, sizeof(data_buf), "%02X%02X%30s%02X", device_type, event_type, data, res); @@ -1464,6 +1463,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; LOG_D("nt26k_life_thread entry\n"); while (1) @@ -1483,6 +1483,8 @@ 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); + rt_thread_mdelay(RT_TICK_PER_SECOND);//这里如果有TCP连接,先关掉TCP,没有返回错误无所谓 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) @@ -1496,7 +1498,6 @@ static void Nt26k_Life_Thread_Entry(void *parameter) result = -RT_ERROR; goto __exit; } - /* disable echo */ LOG_D("ATE0"); if (at_obj_exec_cmd(device->client, resp, "ATE0") != RT_EOK) @@ -1542,6 +1543,54 @@ static void Nt26k_Life_Thread_Entry(void *parameter) result = -RT_ETIMEOUT; goto __exit; } + rt_uint8_t cnt = 0; + /* check signal strength */ + for (cnt = 0; cnt < 10; cnt++) + { + if (at_obj_exec_cmd(device->client, resp, "AT+CSQ") == RT_EOK) + { + int signal_strength = 0, err_rate = 0; + + if (at_resp_parse_line_args_by_kw(resp, "+CSQ:", "+CSQ: %d,%d", &signal_strength, &err_rate) > 0) + { + if ((signal_strength != 99) && (signal_strength != 0)) + { + break; + } + } + } + rt_thread_mdelay(1000); + } + if (cnt == 10) + { + LOG_E("%s device signal strength check failed", device->name); + result = -RT_ERROR; + goto __exit; + } + /* check the GPRS network is registered */ + for (cnt = 0; cnt < 10; cnt++) + { + if (at_obj_exec_cmd(device->client, resp, "AT+CEREG?") == RT_EOK) // 60s内注册CS业务 + { + int link_stat = 0; + + if (at_resp_parse_line_args_by_kw(resp, "+CEREG:", "+CEREG: %*d,%d", &link_stat) > 0) + { + if ((link_stat == 1) || (link_stat == 5)) + { + LOG_D("%s device GPRS is registered", device->name); + break; + } + } + } + rt_thread_mdelay(1000); + } + if (cnt == 10) + { + LOG_E("%s device GPRS is register failed", device->name); + result = -RT_ERROR; + goto __exit; + } if (device->class->device_ops->control(device, AT_DEVICE_CTRL_NET_CONN, RT_NULL) == RT_EOK) { LOG_D("重连网络成功\n"); @@ -1549,15 +1598,12 @@ static void Nt26k_Life_Thread_Entry(void *parameter) delay_n = 0; nt26k_disconnect_retry_flag = 0; at_delete_resp(resp); + retry_delay = 1000; // 重置重连延迟时间 rt_thread_mdelay(100); Nt26k_Send_Event(kNt26kHeartbeatEvent); } else { - if (device->class->device_ops->control(device, AT_DEVICE_RF_CLOSE, RT_NULL) == RT_EOK) - { - LOG_D("关闭模组功能"); - } result = -RT_ETIMEOUT; goto __exit; } @@ -1593,8 +1639,9 @@ static void Nt26k_Life_Thread_Entry(void *parameter) at_delete_resp(resp); } nt26k_disconnect_retry_flag = 1; - LOG_D("联网错误,等待10s后重连"); - rt_thread_mdelay(10000);//上一版本未加延时 + LOG_D("联网错误,等待%dms后重连", retry_delay); + rt_thread_mdelay(retry_delay); + retry_delay = MIN(retry_delay * 2, 60000); // 最大延迟60秒 delay_n++; if (delay_n >= 360) // 连续重连大于1小时都不行,则重启设备 {