Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
AT
UART
AT组件如何解析数据里面包含(\r\n)数据?
发布于 2020-08-27 13:46:49 浏览:1662
订阅该版
AT组件如何解析数据里面包含(\\r\\n)数据?  如果数据包含\\r\\n则会在urc匹配的时候,被截断。这种问题如何规避啊?设计的时候,不可能没有考虑数据中有\\r\\n的问题吧?
查看更多
geniusgogo
认证专家
2020-08-27
这家伙很懒,什么也没写!
接收数据用:at_client_obj_recv
5
个回答
默认排序
按发布时间排序
红枫
认证专家
2020-08-27
这家伙很懒,什么也没写!
可以参考bc26中的数据接收处理
ching
2020-09-02
这家伙很懒,什么也没写!
```c static int at_recv_readline(at_client_t client) { rt_size_t read_len = 0; char ch = 0, last_ch = 0; rt_bool_t is_full = RT_FALSE; rt_memset(client->recv_line_buf, 0x00, client->recv_bufsz); client->recv_line_len = 0; while (1) { at_client_getchar(client, &ch, RT_WAITING_FOREVER); if (read_len < client->recv_bufsz) { client->recv_line_buf[read_len++] = ch; client->recv_line_len = read_len; } else { is_full = RT_TRUE; } /* is newline or URC data */ if ((ch == '\n' && last_ch == '\r') || (client->end_sign != 0 && ch == client->end_sign) || get_urc_obj(client)) { if (is_full) { LOG_E("read line failed. The line data length is out of buffer size(%d)!", client->recv_bufsz); rt_memset(client->recv_line_buf, 0x00, client->recv_bufsz); client->recv_line_len = 0; return -RT_EFULL; } break; } last_ch = ch; } #ifdef AT_PRINT_RAW_CMD at_print_raw_cmd("recvline", client->recv_line_buf, read_len); #endif return read_len; } static void client_parser(at_client_t client) { const struct at_urc *urc; while(1) { if (at_recv_readline(client) > 0) { if ((urc = get_urc_obj(client)) != RT_NULL) { /* current receive is request, try to execute related operations */ if (urc->func != RT_NULL) { urc->func(client, client->recv_line_buf, client->recv_line_len); } } else if (client->resp != RT_NULL) { at_response_t resp = client->resp; /* current receive is response */ client->recv_line_buf[client->recv_line_len - 1] = '\0'; if (resp->buf_len + client->recv_line_len < resp->buf_size) { /* copy response lines, separated by '\0' */ rt_memcpy(resp->buf + resp->buf_len, client->recv_line_buf, client->recv_line_len); /* update the current response information */ resp->buf_len += client->recv_line_len; resp->line_counts++; } else { client->resp_status = AT_RESP_BUFF_FULL; LOG_E("Read response buffer failed. The Response buffer size is out of buffer size(%d)!", resp->buf_size); } /* check response result */ if (rt_memcmp(client->recv_line_buf, AT_RESP_END_OK, rt_strlen(AT_RESP_END_OK)) == 0 && resp->line_num == 0) { /* get the end data by response result, return response state END_OK. */ client->resp_status = AT_RESP_OK; } else if (rt_strstr(client->recv_line_buf, AT_RESP_END_ERROR) || (rt_memcmp(client->recv_line_buf, AT_RESP_END_FAIL, rt_strlen(AT_RESP_END_FAIL)) == 0)) { client->resp_status = AT_RESP_ERROR; } else if (resp->line_counts == resp->line_num && resp->line_num) { /* get the end data by response line, return response state END_OK.*/ client->resp_status = AT_RESP_OK; } else { continue; } client->resp = RT_NULL; rt_sem_release(client->resp_notice); } else { // log_d("unrecognized line: %.*s", client->recv_line_len, client->recv_line_buf); } } } } ```
撰写答案
登录
注册新账号
关注者
0
被浏览
1.7k
关于作者
EUXS_4401
这家伙很懒,什么也没写!
提问
4
回答
2
被采纳
0
关注TA
发私信
相关问题
1
rt thread 2.0.2 usart 接收缓存问题
2
关于STM32串口通信的问题
3
STM32F1+RTT串口接收终端数据丢失问题
4
UART TX丢数据?
5
RTT打开串口的时候如何自定义波特率呢?
6
STM32F4的USART数据接收问题
7
串口1234使用问题
8
串口接收回调函数
9
LPC18xx UART问题讨论
10
x1000串口配置的失败问题
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
机器人操作系统 (ROS2) 和 RT-Thread 通信
4
五分钟玩转RT-Thread新社区
5
国产MCU移植系列教程汇总,欢迎查看!
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
ulog组件多端绑定的demo案例
2
记录rt-thread消息队列的调试方法
3
AT32的ADC使用
4
aht10 终端:The aht10 is under an abnormal status
5
github高阶加速,速度可达带宽峰值,测试到146Mbit/s
热门标签
RT-Thread Studio
串口
LWIP
Env
AT
SPI
Bootloader
FinSH
ART-Pi
CAN总线
Hardfault
USB
文件系统
RT-Thread
DMA
SCons
线程
MQTT
RT-Thread Nano
STM32
RTC
rt-smart
ESP8266
flash
ota在线升级
WIZnet_W5500
FAL
I2C
packages_软件包
UART
cubemx
freemodbus
潘多拉开发板_Pandora
定时器
BSP
PWM
ADC
socket
中断
rt_mq_消息队列_msg_queue
keil_MDK
SDIO
Debug
AB32VG1
MicroPython
C++_cpp
编译报错
msh
ulog
QEMU
本月问答贡献
出出啊
1500
个答案
338
次被采纳
小小李sunny
1390
个答案
276
次被采纳
张世争
715
个答案
157
次被采纳
crystal266
522
个答案
153
次被采纳
whj467467222
1216
个答案
146
次被采纳
本月文章贡献
出出啊
1
篇文章
12
次点赞
小小李sunny
1
篇文章
1
次点赞
张世争
2
篇文章
2
次点赞
crystal266
2
篇文章
5
次点赞
whj467467222
2
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部