Browse Source

[at] optimize at_vprintfln

为什么提交这份PR (why to submit this PR)
现在的at指令发送接口,底层会自动添加"\r\n",某些场景需要发送空指令。如ESP32的蓝牙发送数据指令,收到">"后
发数据,等待接收OK。

详细讨论可见:
https://club.rt-thread.org/ask/question/185810c0aed98558.html

你的解决方案是什么 (what is your solution)
判断at指令长度,长度为0,则直接返回
JasonCang 1 year ago
parent
commit
d0c6d6f4a4
1 changed files with 9 additions and 0 deletions
  1. 9 0
      components/net/at/src/at_utils.c

+ 9 - 0
components/net/at/src/at_utils.c

@@ -6,6 +6,7 @@
  * Change Logs:
  * Date           Author       Notes
  * 2018-04-14     chenyong     first version
+ * 2023-06-09     CX           optimize at_vprintfln interface
  */
 
 #include <at.h>
@@ -91,8 +92,16 @@ rt_size_t at_vprintfln(rt_device_t device, const char *format, va_list args)
     rt_size_t len;
 
     last_cmd_len = vsnprintf(send_buf, sizeof(send_buf) - 2, format, args);
+
+    if(last_cmd_len == 0)
+    {
+        return 0;
+    }
+
     if(last_cmd_len > sizeof(send_buf) - 2)
+    {
         last_cmd_len = sizeof(send_buf) - 2;
+    }
     rt_memcpy(send_buf + last_cmd_len, "\r\n", 2);
 
     len = last_cmd_len + 2;