修复ppp收发统计
author孙春阳 <snickersun@163.com>
Sun, 21 Sep 2025 16:10:56 +0000 (00:10 +0800)
committer孙春阳 <snickersun@163.com>
Sun, 21 Sep 2025 16:10:56 +0000 (00:10 +0800)
code/sdk/zhihui/ppp/src/ppp_api.c
code/sdk/zhihui/ppp/src/ppp_lwip_thread.c

index d16ff14..2006607 100644 (file)
@@ -1178,6 +1178,12 @@ static errcode_t ppp_parse_network_status_response(const char *response, uint8_t
  */
 errcode_t ppp_api_update_imei(void)
 {
+    // 检查是否在AT模式
+    if (ppp_serial_get_mode() != PPP_SERIAL_MODE_AT) {
+        PPP_DEBUG_WARN("Cannot update IMEI: not in AT mode (current mode: %d)", ppp_serial_get_mode());
+        return ERRCODE_FAIL;
+    }
+    
     char *response = (char *)malloc(512);  // 动态分配内存
     if (response == NULL) {
         PPP_DEBUG_ERROR("Failed to allocate memory for AT response");
@@ -1216,6 +1222,12 @@ errcode_t ppp_api_update_imei(void)
  */
 errcode_t ppp_api_update_signal(void)
 {
+    // 检查是否在AT模式
+    if (ppp_serial_get_mode() != PPP_SERIAL_MODE_AT) {
+        PPP_DEBUG_WARN("Cannot update signal: not in AT mode (current mode: %d)", ppp_serial_get_mode());
+        return ERRCODE_FAIL;
+    }
+    
     char *response = (char *)malloc(512);  // 动态分配内存
     if (response == NULL) {
         PPP_DEBUG_ERROR("Failed to allocate memory for AT response");
@@ -1254,6 +1266,12 @@ errcode_t ppp_api_update_signal(void)
  */
 errcode_t ppp_api_update_operator(void)
 {
+    // 检查是否在AT模式
+    if (ppp_serial_get_mode() != PPP_SERIAL_MODE_AT) {
+        PPP_DEBUG_WARN("Cannot update operator: not in AT mode (current mode: %d)", ppp_serial_get_mode());
+        return ERRCODE_FAIL;
+    }
+    
     char *response = (char *)malloc(512);  // 动态分配内存
     if (response == NULL) {
         PPP_DEBUG_ERROR("Failed to allocate memory for AT response");
@@ -1292,6 +1310,12 @@ errcode_t ppp_api_update_operator(void)
  */
 errcode_t ppp_api_update_iccid(void)
 {
+    // 检查是否在AT模式
+    if (ppp_serial_get_mode() != PPP_SERIAL_MODE_AT) {
+        PPP_DEBUG_WARN("Cannot update ICCID: not in AT mode (current mode: %d)", ppp_serial_get_mode());
+        return ERRCODE_FAIL;
+    }
+    
     char *response = (char *)malloc(512);  // 动态分配内存
     if (response == NULL) {
         PPP_DEBUG_ERROR("Failed to allocate memory for AT response");
@@ -1330,6 +1354,12 @@ errcode_t ppp_api_update_iccid(void)
  */
 errcode_t ppp_api_update_version(void)
 {
+    // 检查是否在AT模式
+    if (ppp_serial_get_mode() != PPP_SERIAL_MODE_AT) {
+        PPP_DEBUG_WARN("Cannot update version: not in AT mode (current mode: %d)", ppp_serial_get_mode());
+        return ERRCODE_FAIL;
+    }
+    
     char *response = (char *)malloc(512);  // 动态分配内存
     if (response == NULL) {
         PPP_DEBUG_ERROR("Failed to allocate memory for AT response");
@@ -1368,6 +1398,12 @@ errcode_t ppp_api_update_version(void)
  */
 errcode_t ppp_api_update_network_status(void)
 {
+    // 检查是否在AT模式
+    if (ppp_serial_get_mode() != PPP_SERIAL_MODE_AT) {
+        PPP_DEBUG_WARN("Cannot update network status: not in AT mode (current mode: %d)", ppp_serial_get_mode());
+        return ERRCODE_FAIL;
+    }
+    
     char *response = (char *)malloc(512);  // 动态分配内存
     if (response == NULL) {
         PPP_DEBUG_ERROR("Failed to allocate memory for AT response");
@@ -1424,6 +1460,12 @@ errcode_t ppp_api_update_network_status(void)
  */
 errcode_t ppp_api_update_sim_status(void)
 {
+    // 检查是否在AT模式
+    if (ppp_serial_get_mode() != PPP_SERIAL_MODE_AT) {
+        PPP_DEBUG_WARN("Cannot update SIM status: not in AT mode (current mode: %d)", ppp_serial_get_mode());
+        return ERRCODE_FAIL;
+    }
+    
     char *response = (char *)malloc(512);  // 动态分配内存
     if (response == NULL) {
         PPP_DEBUG_ERROR("Failed to allocate memory for AT response");
@@ -2289,6 +2331,12 @@ errcode_t ppp_get_network_signal_info(void)
         return ERRCODE_FAIL;
     }
     
+    // 检查是否在AT模式
+    if (ppp_serial_get_mode() != PPP_SERIAL_MODE_AT) {
+        PPP_DEBUG_WARN("Cannot get network signal info: not in AT mode (current mode: %d)", ppp_serial_get_mode());
+        return ERRCODE_FAIL;
+    }
+    
     PPP_DEBUG_INFO("Getting network signal information...");
     
     ppp_network_signal_info_t signal_info;
index 57bcf18..7ee2a77 100644 (file)
@@ -333,9 +333,14 @@ static void ppp_lwip_process_thread(void *arg)
             processed_frames++;
             processed_bytes += frame->length;
             
-            // 更新处理统计
+            // 更新处理统计(统计实际传递给lwIP的字节数,但排除我们添加的0x7E)
             g_ppp_discard_stats.total_frames_processed++;
-            g_ppp_discard_stats.total_bytes_processed += frame->length;
+            // 减去我们添加的额外0x7E标志(每帧最多添加1个)
+            uint32_t original_bytes = frame->length;
+            if (frame->length > 0 && frame->data[frame->length-1] == 0x7E) {
+                original_bytes--; // 减去结束时添加的0x7E
+            }
+            g_ppp_discard_stats.total_bytes_processed += original_bytes;
             
             // 释放帧内存
             free(frame->data);