From: 孙春阳 Date: Thu, 18 Sep 2025 04:01:14 +0000 (+0800) Subject: 雷鸟,修复模组自动休眠唤不醒问题 X-Git-Tag: leiniao_debug_1.0.0_20250922_020716~59 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=6b0ec58a11c5be044205d5a3f8e0ca37a4b10b75;p=mirrors%2FFD230.git 雷鸟,修复模组自动休眠唤不醒问题 --- diff --git a/code/sdk/zhihui/ppp/example/ppp_at_cmd.c b/code/sdk/zhihui/ppp/example/ppp_at_cmd.c index f34636a41..e71376e51 100644 --- a/code/sdk/zhihui/ppp/example/ppp_at_cmd.c +++ b/code/sdk/zhihui/ppp/example/ppp_at_cmd.c @@ -44,7 +44,7 @@ static int ConvertCmdToParam(uint8_t *para, uint32_t paraLen, *argc = 0; for (uint32_t i = 0; i < paraLen; i++) { - if ((para[i] == ' ' || para[i] == '\n') && pos != 0) { + if ((para[i] == ' ' || para[i] == ',' || para[i] == '\n') && pos != 0) { argv[*argc][pos] = '\0'; *argc += 1; pos = 0; diff --git a/code/sdk/zhihui/ppp/example/ppp_tcp_test.c b/code/sdk/zhihui/ppp/example/ppp_tcp_test.c index 3620095c0..d214d94da 100644 --- a/code/sdk/zhihui/ppp/example/ppp_tcp_test.c +++ b/code/sdk/zhihui/ppp/example/ppp_tcp_test.c @@ -469,12 +469,22 @@ static ppp_error_t tcp_test_connect_socket(int *sock_fd, const char *host, uint1 PPP_DEBUG_WARN("Failed to set socket timeout"); } #else - // 在lwIP环境下设置超时 (使用简化方式) - int timeout_ms = TCP_TEST_CONNECT_TIMEOUT * 1000; - if (TCP_SETSOCKOPT(fd, TCP_SOL_SOCKET, TCP_SO_RCVTIMEO, &timeout_ms, sizeof(timeout_ms)) < 0 || - TCP_SETSOCKOPT(fd, TCP_SOL_SOCKET, TCP_SO_SNDTIMEO, &timeout_ms, sizeof(timeout_ms)) < 0) { - PPP_DEBUG_WARN("Failed to set socket timeout in lwIP"); + // 在lwIP环境下设置超时 - 使用正确的数据类型和检查 + #ifdef LWIP_SO_RCVTIMEO + struct timeval timeout; + timeout.tv_sec = TCP_TEST_CONNECT_TIMEOUT; + timeout.tv_usec = 0; + + if (TCP_SETSOCKOPT(fd, TCP_SOL_SOCKET, TCP_SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0) { + PPP_DEBUG_DEBUG("lwIP SO_RCVTIMEO not supported or failed"); } + if (TCP_SETSOCKOPT(fd, TCP_SOL_SOCKET, TCP_SO_SNDTIMEO, &timeout, sizeof(timeout)) < 0) { + PPP_DEBUG_DEBUG("lwIP SO_SNDTIMEO not supported or failed"); + } + #else + // lwIP可能不支持超时选项,使用非阻塞模式代替 + PPP_DEBUG_INFO("lwIP socket timeout not supported, using default behavior"); + #endif #endif struct sockaddr_in server_addr; diff --git a/code/sdk/zhihui/ppp/src/ppp_api.c b/code/sdk/zhihui/ppp/src/ppp_api.c index a5ed481b6..245be7acf 100644 --- a/code/sdk/zhihui/ppp/src/ppp_api.c +++ b/code/sdk/zhihui/ppp/src/ppp_api.c @@ -61,7 +61,7 @@ errcode_t ppp_api_power_init(void) .ring_pin = S_MGPIO21, //CTS cat1 wakeup mcu .ring_pin_en_value = 2, //2 双边沿中断 , 1 上升沿中断 , 0 下降沿中断 .wakemodem_pin = S_MGPIO22, //RTS mcu wakeup cat1 - .wakemodem_pin_en_value = 1 //1 唤醒cat1 , 0 休眠cat1 + .wakemodem_pin_en_value = 0 //0 唤醒cat1 , 1 休眠cat1 }; // 注册4G电源控制引脚配置 diff --git a/code/sdk/zhihui/ppp/src/ppp_lwip.c b/code/sdk/zhihui/ppp/src/ppp_lwip.c index 74c6536f8..75fd6cea2 100644 --- a/code/sdk/zhihui/ppp/src/ppp_lwip.c +++ b/code/sdk/zhihui/ppp/src/ppp_lwip.c @@ -307,9 +307,22 @@ ppp_error_t ppp_lwip_input(const uint8_t *data, uint32_t length) #ifndef LWIP_PPP_SUPPORT return PPP_ERR_INVALID_PARAM; #else + /* 参数和状态验证 */ if (!g_lwip_ctx.initialized || !data || length == 0) { return PPP_ERR_INVALID_PARAM; } + + // /* 添加合理性检查 - PPP帧长度限制 */ + // if (length > 1500) { // PPP最大帧长度 + // PPP_DEBUG_ERROR("PPP frame too large: %u bytes", length); + // return PPP_ERR_INVALID_PARAM; + // } + + /* 检查PPP控制块是否有效 */ + if (!g_lwip_ctx.ppp_pcb) { + PPP_DEBUG_ERROR("PPP control block is NULL"); + return PPP_ERR_INVALID_STATE; + } PPP_DEBUG_PRINT("=== PPP Input Data ===\n"); PPP_DEBUG_PRINT("Length: %d bytes\n", length); diff --git a/code/sdk/zhihui/ppp/src/ppp_lwip_thread.c b/code/sdk/zhihui/ppp/src/ppp_lwip_thread.c index c48f72f95..854fb3fa1 100644 --- a/code/sdk/zhihui/ppp/src/ppp_lwip_thread.c +++ b/code/sdk/zhihui/ppp/src/ppp_lwip_thread.c @@ -75,7 +75,7 @@ static void ppp_lwip_receive_thread(void *arg) PPP_DEBUG_INFO("PPP RX: Got %u bytes (total: %u packets, %u bytes)", bytes_read, total_packets, total_bytes); - /* 将接收到的数据添加到流缓冲区 */ + /* 将接收到的数据添加到流缓冲区 - 加强边界检查 */ if (stream_pos + bytes_read < PPP_RX_BUFFER_SIZE * 2) { memcpy(stream_buffer + stream_pos, rx_buffer, bytes_read); stream_pos += bytes_read; @@ -84,20 +84,34 @@ static void ppp_lwip_receive_thread(void *arg) stream_pos = 0; frame_start = 0; in_frame = false; + continue; // 跳过本次处理,避免缓冲区溢出 } - /* 处理PPP帧 - 查找0x7E标志 */ - for (uint32_t i = frame_start; i < stream_pos; i++) { + /* 处理PPP帧 - 查找0x7E标志并添加边界检查 */ + for (uint32_t i = frame_start; i < stream_pos && i < PPP_RX_BUFFER_SIZE * 2; i++) { if (stream_buffer[i] == 0x7E) { if (in_frame && i > frame_start) { /* 找到帧结束,处理完整的PPP帧 */ uint32_t frame_len = i - frame_start + 1; - PPP_DEBUG_DEBUG("PPP complete frame found: %u bytes", frame_len); - - /* 将完整帧传递给lwIP - 让lwIP自己验证帧的有效性 */ - ppp_lwip_input(stream_buffer + frame_start, frame_len); - complete_frames++; + /* 添加帧长度合理性检查 */ + if (frame_len > 0 && frame_len <= 1500) { // PPP最大帧长度 + PPP_DEBUG_DEBUG("PPP complete frame found: %u bytes", frame_len); + + /* 确保指针和长度有效 */ + if (frame_start + frame_len <= PPP_RX_BUFFER_SIZE * 2 && + frame_start < PPP_RX_BUFFER_SIZE * 2) { + /* 将完整帧传递给lwIP - 让lwIP自己验证帧的有效性 */ + ppp_lwip_input(stream_buffer + frame_start, frame_len); + complete_frames++; + } else { + PPP_DEBUG_WARN("PPP frame pointer out of bounds: start=%u, len=%u", + frame_start, frame_len); + } + } else { + PPP_DEBUG_WARN("Invalid PPP frame length: %u (frame_start=%u, i=%u)", + frame_len, frame_start, i); + } } /* 开始新帧 */ diff --git a/code/sdk/zhihui/ppp/src/ppp_power_ctl.c b/code/sdk/zhihui/ppp/src/ppp_power_ctl.c index 3364e0b75..ff81172a4 100644 --- a/code/sdk/zhihui/ppp/src/ppp_power_ctl.c +++ b/code/sdk/zhihui/ppp/src/ppp_power_ctl.c @@ -58,7 +58,7 @@ static ppp_ctl_pin_4g_t g_ppp_cat1_ctl_pins = { S_MGPIO21,//ring_pin 2, S_MGPIO22,//wakemodem_pin - 1, + 0, #else PIN_NONE, //bat_pin 1, @@ -393,10 +393,14 @@ void ppp_ring_isr_callback(pin_t pin, uintptr_t param) gpio_level_t val = uapi_gpio_get_val(pin); if (val == GPIO_LEVEL_HIGH) { PPP_DEBUG_PRINT("PPP: Cat1 ring interrupt on pin %d high \n", pin); + #ifdef PPP_LOW_POWER_MODE ppp_api_wakeup_cat1(true); + #endif } else { PPP_DEBUG_PRINT("PPP: Cat1 ring interrupt on pin %d low\n", pin); + #ifdef PPP_LOW_POWER_MODE ppp_api_wakeup_cat1(false); + #endif } uapi_gpio_clear_interrupt(pin); } diff --git a/code/sdk/zhihui/ppp/src/ppp_serial.c b/code/sdk/zhihui/ppp/src/ppp_serial.c index decb80fbc..6c3cc91b0 100644 --- a/code/sdk/zhihui/ppp/src/ppp_serial.c +++ b/code/sdk/zhihui/ppp/src/ppp_serial.c @@ -357,7 +357,9 @@ ppp_error_t ppp_serial_write(const uint8_t *data, uint32_t length) } PPP_DEBUG_INFO("=== PPP Serial Write Start ==="); + #ifdef PPP_LOW_POWER_MODE ppp_api_wakeup_cat1(true); + #endif osal_msleep(1); PPP_DEBUG_INFO("Write request: %u bytes in mode %d", length, g_serial_ctx.current_mode); PPP_DEBUG_INFO("UART Bus: %u", g_serial_ctx.uart_bus); @@ -430,7 +432,9 @@ ppp_error_t ppp_serial_write(const uint8_t *data, uint32_t length) result == PPP_ERR_OK ? "SUCCESS" : "FAILED", result); PPP_DEBUG_INFO("Statistics: tx_bytes=%u, tx_errors=%u", g_serial_ctx.tx_bytes, g_serial_ctx.tx_errors); PPP_DEBUG_INFO("=== PPP Serial Write End ==="); + #ifdef PPP_LOW_POWER_MODE ppp_api_wakeup_cat1(false); + #endif return result; }