diff --git a/.vscode/settings.json b/.vscode/settings.json index 4597c38..fcfc0fd 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -69,6 +69,7 @@ "stdio.h": "c", "time.h": "c", "ch32v30x.h": "c", - "lwutil.h": "c" + "lwutil.h": "c", + "netdev.h": "c" } } diff --git a/bsp/src/at_device_ml307.c b/bsp/src/at_device_ml307.c index 5861007..bef4256 100644 --- a/bsp/src/at_device_ml307.c +++ b/bsp/src/at_device_ml307.c @@ -2,7 +2,7 @@ * @Author: mbw * @Date: 2024-11-30 15:46:21 * @LastEditors: mbw && 1600520629@qq.com - * @LastEditTime: 2025-02-21 14:49:11 + * @LastEditTime: 2025-02-21 18:33:03 * @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\at_device_ml307.c * @Description: * @@ -884,7 +884,6 @@ static void ml307_init_thread_entry(void *parameter) #define CGATT_RETRY 10 #define ML307_AT_DEFAULT_TIMEOUT 5000 int i; - rt_uint8_t retry_num = INIT_RETRY; rt_err_t result = RT_EOK; at_response_t resp = RT_NULL; struct at_device *device = (struct at_device *)parameter; @@ -900,7 +899,7 @@ static void ml307_init_thread_entry(void *parameter) LOG_D("start init %s device.", device->name); ml307_power_off(device); - while (retry_num--) + while (1) { /* power on the ml307 device */ rt_thread_mdelay(1000); @@ -966,7 +965,6 @@ static void ml307_init_thread_entry(void *parameter) result = -RT_ERROR; goto __exit; } - { #define ML307_NETDEV_HWADDR_LEN 8 #define ML307_IMEI_LEN 15 @@ -1153,7 +1151,7 @@ static void ml307_init_thread_entry(void *parameter) if (result != RT_EOK) { /* power off the ml307 device */ - // ml307_power_off(device); + ml307_power_off(device); rt_thread_mdelay(1000); LOG_I("%s device initialize retry...", device->name); diff --git a/bsp/src/bsp_ml307.c b/bsp/src/bsp_ml307.c index f9e7760..03ab2cb 100644 --- a/bsp/src/bsp_ml307.c +++ b/bsp/src/bsp_ml307.c @@ -2,7 +2,7 @@ * @Author: mbw * @Date: 2024-11-30 15:46:21 * @LastEditors: mbw && 1600520629@qq.com - * @LastEditTime: 2025-02-21 14:47:59 + * @LastEditTime: 2025-02-22 15:59:21 * @FilePath: \ble_bjq_ch303rct6_ml307\bsp\src\bsp_ml307.c * @Description: * @@ -26,7 +26,7 @@ #if IOT_MODULE_SWITCH == 1 #define ML307_THREAD_STACK_SIZE (4096 + 2048) #define ML307_RECV_THREAD_STACK_SIZE (4096 + 2048) -#define ML307_LIFE_THREAD_STACK_SIZE (1024) +#define ML307_LIFE_THREAD_STACK_SIZE (4096) #define ML307_THREAD_PRIORITY 25 #define ML307_THREAD_TICKS 50 #define ML307_RECV_THREAD_PRIORITY 24 @@ -1802,61 +1802,48 @@ static void Ml307_Life_Thread_Entry(void *parameter) result = -RT_ERROR; goto __exit; } - LOG_D("AT+MIPCFG=\"encoding\",0,1,1"); + /*disable sleep mode */ + if (at_obj_exec_cmd(device->client, resp, "AT+MLPMCFG=\"sleepmode\",0,1") != RT_EOK) + { + result = -RT_ERROR; + goto __exit; + } /*设置包模式*/ if (at_obj_exec_cmd(device->client, resp, "AT+MIPCFG=\"encoding\",0,1,1") != RT_EOK) { result = -RT_ERROR; 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+MIPCFG=\"autofree\",0,0") != RT_EOK) { - 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+MIPTKA=0,1,120,60,1") != RT_EOK) { - 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; } + /* Define PDP Context */ + rt_uint8_t i = 0, + for (i = 0; i < 5; i++) + { + if (at_obj_exec_cmd(client, resp, "AT+CGDCONT=1,\"IPV4V6\",\"cmnet\"") == RT_EOK) + { + LOG_D("%s device Define PDP Context Success.", device->name); + break; + } + rt_thread_mdelay(1000); + } + if (i == 5) + { + LOG_E("%s device Define PDP Context 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");